Hi,
I have an array of Xs and corresponding one of Ys. How can I get the least square fit? Because when I look at the class it uses histograms and distributions, etc… Cheers :) Uko -- You received this message because you are subscribed to the Google Groups "SciSmalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
You should have a look to the book if not done:
https://github.com/SquareBracketAssociates/NumericalMethods/releases/tag/snapshot-2016-01-17 If you find how it works, please document ;-) On Wed, Feb 17, 2016 at 4:21 PM, Yuriy Tymchuk <[hidden email]> wrote: > Hi, > > I have an array of Xs and corresponding one of Ys. How can I get the least square fit? Because when I look at the class it uses histograms and distributions, etc… > > Cheers :) > Uko > > -- > You received this message because you are subscribed to the Google Groups "SciSmalltalk" group. > To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. > For more options, visit https://groups.google.com/d/optout. -- Serge Stinckwich UCBN & UMI UMMISCO 209 (IRD/UPMC) Every DSL ends up being Smalltalk http://www.doesnotunderstand.org/ -- You received this message because you are subscribed to the Google Groups "SciSmalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by Uko
Hi Yuriy,
-- do you mean something like this: x:=#(1 2 4 8 9). y:=#(3 4 5 6 7). lr:=DhbLinearRegression new. points:=(1 to:x size) collect:[:i|( (x at:i)@(y at:i))]. points do:[:i|lr add:i]. p:=lr asEstimatedPolynomial . "-->(371/127) + (55/127) X" b := RTGrapher new. ds := RTDataSet new. ds noDot. ds points: (0 to: 10 by:2). ds x: #yourself. ds y: [:i|p value:i]. ds connectColor: (Color red). b add: ds. ds := RTDataSet new. ds points: points. ds x: #x. ds y: #y. b add: ds. b build. b view openWithMenu . ?? werner On Wednesday, February 17, 2016 at 4:21:38 PM UTC+1, Yuriy Tymchuk wrote: Hi, You received this message because you are subscribed to the Google Groups "SciSmalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
additionaly there is DhbPolynomialLeastSquareFit. or do mean a nonlinear least square fit? in this case a little example would be helpful. wernerOn Thu, Feb 18, 2016 at 1:01 AM, werner kassens <[hidden email]> wrote:
You received this message because you are subscribed to the Google Groups "SciSmalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by werner kassens-2
Nice script, Werner.
I modify it a little bit in order to use real data (speeds and distance of seventeen galaxies) and do an approximation of the Hubble constant. This is something I'm doing with 1st Year student at the University in Python. Maybe we should a library of scripts that shows some nice example of SciSmalltalk ? ======================================================================================== x := #(0.028 0.076 0.108 0.136 0.153 0.226 0.283 0.359 0.363 0.408 0.438 0.472 0.476 0.476 0.493 0.556 0.639). y := #(2.7 4.2 10.5 14.1 10.5 13.2 19.8 28.2 20.7 29.4 31.8 44.4 32.1 37.2 33 34.5 46.5). lr := DhbLinearRegression new. points := (1 to: x size) collect: [:i|( (x at: i)@(y at: i))]. points do: [:i|lr add:i]. p := lr asEstimatedPolynomial. b := RTGrapher new. lb := RTLegendBuilder new. lb view: b view. lb addText: ('H=', lr slope asString). lb build. ds := RTDataSet new. ds noDot. ds points: (0 to: 0.8 by: 0.1). ds x: #yourself. ds y: [:i|p value: i]. ds connectColor: (Color red). b add: ds. ds := RTDataSet new. ds points: points. ds x: #x. ds y: #y. b add: ds. b. ================================================= On Thu, Feb 18, 2016 at 1:01 AM, werner kassens <[hidden email]> wrote: > Hi Yuriy, > do you mean something like this: > x:=#(1 2 4 8 9). > y:=#(3 4 5 6 7). > lr:=DhbLinearRegression new. > points:=(1 to:x size) collect:[:i|( (x at:i)@(y at:i))]. > points do:[:i|lr add:i]. > p:=lr asEstimatedPolynomial . "-->(371/127) + (55/127) X" > > b := RTGrapher new. > ds := RTDataSet new. > ds noDot. > ds points: (0 to: 10 by:2). > ds x: #yourself. > ds y: [:i|p value:i]. > ds connectColor: (Color red). > b add: ds. > ds := RTDataSet new. > ds points: points. > ds x: #x. > ds y: #y. > b add: ds. > b build. > b view openWithMenu . > ?? > werner > > > On Wednesday, February 17, 2016 at 4:21:38 PM UTC+1, Yuriy Tymchuk wrote: >> >> Hi, >> >> I have an array of Xs and corresponding one of Ys. How can I get the least >> square fit? Because when I look at the class it uses histograms and >> distributions, etc… >> >> Cheers :) >> Uko > > -- > You received this message because you are subscribed to the Google Groups > "SciSmalltalk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [hidden email]. > For more options, visit https://groups.google.com/d/optout. -- Serge Stinckwich UCBN & UMI UMMISCO 209 (IRD/UPMC) Every DSL ends up being Smalltalk http://www.doesnotunderstand.org/ -- You received this message because you are subscribed to the Google Groups "SciSmalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by werner kassens-2
Hi,
this was super useful. One thing that I’ve noticed, is that if all the values are the same, a zero divide exception happens when correlationCoefficient is calculated. Does if have to be like that, or there is a way to treat this case? Cheers. Uko
You received this message because you are subscribed to the Google Groups "SciSmalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by SergeStinckwich
On Sunday, February 21, 2016 at 4:57:18 PM UTC+1, Serge Stinckwich wrote:
-- Maybe we should a library of scripts that shows some nice example of Hi Serge, yes, you made a nice example out of that script indeed. at the moment i dont have any further scripts to share though. and im working on some other things these days. werner You received this message because you are subscribed to the Google Groups "SciSmalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by Uko
Hi Uko,
-- i assume you mean if the y-values are all the same? (if the x-values are all the same a solution would not be possible.) of course you can catch the ZeroDivideError and then set correlationCoefficient to nil. this way you can get eg the 'lr asEstimatedPolynomial' part and such things as slope & intercept. but i personally would be hesitant to change this in the publicly downloadable version without some further thinking, the ZeroDivideError makes sense from the pov of the book and i am not sure whether the error parts in DhbLinearRegression return the correct values if one does this. werner On Sunday, February 21, 2016 at 10:48:55 PM UTC+1, Yuriy Tymchuk wrote:
You received this message because you are subscribed to the Google Groups "SciSmalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
...and a bug report would of course make sense wernerOn Mon, Feb 22, 2016 at 1:08 PM, werner kassens <[hidden email]> wrote:
You received this message because you are subscribed to the Google Groups "SciSmalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout. |
Free forum by Nabble | Edit this page |