SciPy 0.6.0 API Documentation Generated by Endo, 2007-10-17
Python wrappers for Orthogonal Distance Regression (ODRPACK).
Classes
=======
Data -- stores the data and weights to fit against
RealData -- stores data with standard deviations and covariance matrices
Model -- stores the model and its related information
Output -- stores all of the output from an ODR run
ODR -- collects all data and runs the fitting routine
Exceptions
==========
odr_error -- error sometimes raised inside odr() and can be raised in the
fitting functions to tell ODRPACK to halt the procedure
odr_stop -- error to raise in fitting functions to tell ODRPACK that the data or
parameters given are invalid
Use
===
Basic use:
1) Define the function you want to fit against:
def f(B, x):
return B[0]*x + B[1]
B is a vector of the parameters.
x is an array of the current x values. (Same format as the x passed to Data or
RealData. Return an array in the same format as y passed to Data or
RealData.)
2) Create a Model.
linear = Model(f)
3) Create a Data or RealData instance.
mydata = Data(x, y, wd=1./power(sx,2), we=1./power(sy,2))
or
mydata = RealData(x, y, sx=sx, sy=sy)
4) Instantiate ODR with your data, model and initial parameter estimate.
myodr = ODR(mydata, linear, beta0=[1., 2.])
5) Run the fit.
myoutput = myodr.run()
6) Examine output.
myoutput.pprint()
Read the docstrings and the accompanying tests for more advanced usage.
Notes
=====
* Array formats -- FORTRAN stores its arrays in memory column first, i.e. an
array element A(i, j, k) will be next to A(i+1, j, k). In C and, consequently,
NumPy, arrays are stored row first: A[i, j, k] is next to A[i, j, k+1]. For
efficiency and convenience, the input and output arrays of the fitting
function (and its Jacobians) are passed to FORTRAN without transposition.
Therefore, where the ODRPACK documentation says that the X array is of shape
(N, M), it will be passed to the Python function as an array of shape (M, N).
If M==1, the one-dimensional case, then nothing matters; if M>1, then your
Python functions will be dealing with arrays that are indexed in reverse of
the ODRPACK documentation. No real biggie, but watch out for your indexing of
the Jacobians: the i,j'th elements (@f_i/@x_j) evaluated at the n'th
observation will be returned as jacd[j, i, n]. Except for the Jacobians, it
really is easier to deal with x[0] and x[1] than x[:,0] and x[:,1]. Of course,
you can always use the transpose() function from scipy explicitly.
* Examples -- See the accompanying file test/test.py for examples of how to set
up fits of your own. Some are taken from the User's Guide; some are from
other sources.
* Models -- Some common models are instantiated in the accompanying module
models.py . Contributions are welcome.
Credits
=======
* Thanks to Arnold Moene and Gerard Vermeulen for fixing some killer bugs.
Robert Kern
robert.kern@gmail.com
odr = __odrpack.odr
odr_error = __odrpack.odr_error
odr_stop = __odrpack.odr_stop
Interprets the return code of the odr routine.
| Local name | Refers to |
|---|---|
| numpy | numpy |
| __odrpack | scipy.odr.__odrpack |