scipy.odr how to get optional output attributes for class output

Created on 9 Jun 2016  ·  4Comments  ·  Source: scipy/scipy

Hi there,

I am running a code which uses scipy.odr to estimate 2 parameters. Everythings works well for the usual outputs, but in the class output I want to receive the optional attributes, particularly these ones:

res_var (float, optional) Residual variance.
sum_sqare (float, optional) Sum of squares error.
rel_error (float, optional) Relative error in function values computed within fcn_.

when I run the program I got the following error: 'Output' object has no attribute 'rel_err'

For what I read, I need to use the run odr (the low level function of ODR) with the option full_output=1

But in the package I cannot find the way how to use that function, always that I try I found myself with other silly errors that I am sure refers to the way I use it.

Sending you the hole code doesn't make sense becuase it is too bit, I attached a small part of my code as example, it runs and at the same time it reproduces my error, there is also a small comment where I show how I am trying to use the function odr.odr before I call the output attributes (off course is a wrong way of using it)

hope you can help me to find the correct procedure.

Thanks
odr_full_output_ex.py.zip

query scipy.odr

Most helpful comment

Your code crashes before already for me:

     46 odr_model = odr.Model(fcn = f_phi_cw_raytest)
     47 odr_opti = odr.ODR(odr_data,odr_model,
---> 48                    np.array([phi_0,cw_0]),maxit=10)
     49 odr_opti.set_job(fit_type = 0, deriv = 1, var_calc = 2)
     50 

/home/rgommers/Code/scipy/scipy/odr/odrpack.py in __init__(self, data, model, beta0, delta0, ifixb, ifixx, job, iprint, errfile, rptfile, ndigit, taufac, sstol, partol, maxit, stpb, stpd, sclb, scld, work, iwork)
    766         self.output = None
    767 
--> 768         self._check()
    769 
    770     def _check(self):

/home/rgommers/Code/scipy/scipy/odr/odrpack.py in _check(self)
    787 
    788         if x_s[-1] != y_s[-1]:
--> 789             raise OdrError("number of observations do not match")
    790 
    791         n = x_s[-1]

OdrError: number of observations do not match

And in run() the full_output keyword is hardcoded to 1, so the optional outputs should already be present.

Can you please fix your example and put it in actual code here (not as a zip file) so it can be copy-pasted into the terminal?

All 4 comments

Your code crashes before already for me:

     46 odr_model = odr.Model(fcn = f_phi_cw_raytest)
     47 odr_opti = odr.ODR(odr_data,odr_model,
---> 48                    np.array([phi_0,cw_0]),maxit=10)
     49 odr_opti.set_job(fit_type = 0, deriv = 1, var_calc = 2)
     50 

/home/rgommers/Code/scipy/scipy/odr/odrpack.py in __init__(self, data, model, beta0, delta0, ifixb, ifixx, job, iprint, errfile, rptfile, ndigit, taufac, sstol, partol, maxit, stpb, stpd, sclb, scld, work, iwork)
    766         self.output = None
    767 
--> 768         self._check()
    769 
    770     def _check(self):

/home/rgommers/Code/scipy/scipy/odr/odrpack.py in _check(self)
    787 
    788         if x_s[-1] != y_s[-1]:
--> 789             raise OdrError("number of observations do not match")
    790 
    791         n = x_s[-1]

OdrError: number of observations do not match

And in run() the full_output keyword is hardcoded to 1, so the optional outputs should already be present.

Can you please fix your example and put it in actual code here (not as a zip file) so it can be copy-pasted into the terminal?

I will have another look if you follow up, but I'm going to close this because it's not an issue. Note that StackOverflow or the scipy-user mailing list are more appropriate places to ask this kind of thing.

Dear Ralf,

I fix the problem thanks to your suggestion, as you said above, the ODR class gives me all the attributes I check it as you said in the source code. I missunderstood the instructions of the ODR package on the website as they say in the output class: "...The attributes listed as “optional” above are only present if _odr_ was run with full_output=1...:". Now I got everything to run it. I really appreciate your help and contribution.

When I got this problem, this was the only place I found. Can you give me this mail address for ODR users you said before? Now that I got all the attributes I found that my _sd_betas_ are always zero for two different experiments, I wanna know if that is normal for my experiment set up or if I need to activate anything in particular to get the real sd_betas.

Thanks.

Hi, I suppose the scipy mailing lists are the one you are referring to. They can be found here. In particular, scipy user list is discussions for various users while scipy dev is regarding the development of the package. Hope it helps.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bayesfactor picture bayesfactor  ·  4Comments

tomogwen picture tomogwen  ·  3Comments

gvr37leo picture gvr37leo  ·  3Comments

Diyago picture Diyago  ·  4Comments

NicolasHug picture NicolasHug  ·  4Comments