[SciPy-User] adding linear fitting routine

Matt Newville newville at cars.uchicago.edu
Fri Dec 6 10:28:23 EST 2013


On Fri, Dec 6, 2013 at 1:21 AM, David J Pine <djpine at gmail.com> wrote:
>
>
> On Thu, Dec 5, 2013 at 3:49 PM, Matt Newville <newville at cars.uchicago.edu>
> wrote:
>>
>> On Thu, Dec 5, 2013 at 8:13 AM, Alan G Isaac <alan.isaac at gmail.com> wrote:
>> > On 12/5/2013 5:43 AM, Skipper Seabold wrote:
>> >> Maybe this is an opportunity to start introducing the Bunch pattern
>> >> into scipy.
>> >
>> > Pursuing this train of thought one step further,
>> > I like results objects that can do lazy evaluation
>> > of expensive results.
>> >
>> > Alan Isaac
>> >
>>
>> Yes, I think this would be very helpful.   Returning a "Result" that
>> was an otherwise empty class instance that could possibly have methods
>> to calculate derived values would be a nice approach.   A nice
>> possibility is that curve_fit() could simply extend the Results class
>> returned from minimize(), so that the minimize() values were available
>> if needed.
>>
>> I don't like the 'full_output' options that change the number or
>> quantity of output values. Consistency in return values between
>> different functions with related purpose would very, very helpful, but
>> consistency in return values for a single function seems like it
>> should be a requirement.   Of course, breaking existing APIs is also
>> bad, but I would suggest not adding any more 'full_output' options.
>>
>> That said, in the case of linfit(), returning just two values
>> (best_values, covariance) seems completely acceptable to me.
>>
>> --Matt Newville
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
> The Bunch class idea is new to me.  I looked it up
> (http://stackoverflow.com/questions/16262670/understanding-the-bunch-pattern-and-self-dict)
> and tried it out in linfit().  It works quite nicely, having the advantages
> of a dictionary but with a cleaner syntax.  If this way of doing the output
> were implemented, then linfit() would have two persistent outputs, fit (an
> array containing the slope and y-intercept) and cvm (the 2x2 covariance
> matrix of the fitting parameters), and the optional output info where
> info.rchisq would be the value of reduced chi-squared, info.resids would be
> the residuals, info.rval would be the r-value, etc.  It isn't the usual way
> of doing things, but it's clean and simple.  I rather like it.  What does
> everyone else think?
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>

+1.  I might suggest using longer names: 'covariance' instead of
'cvm', and perhaps 'slope' and 'intercept' instead of (or in addition
to) a 2-element array (again, order is probably obvious, but only
probably).  But having linfit() included would be great.

-- 
--Matt Newville



More information about the SciPy-User mailing list