Possible bug?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Possible bug?

mrodrig
Hello,

I am trying to make a data fitting using the leasqr function. In the
attachment you can find the data and the function that I am trying to adjust
and the adjustment parameters.

When plotting x vs y and the F function with the par parameters, initially
it seems reasonable.

When I make the adjustment I get the following result

error: weighted residuals are not real
error: called from
     __lm_svd__ at line 467 column 11
 
I searched and there are other users that something similar has happened to
them

Somebody could help me

Data_fitting.txt
<http://octave.1599824.n4.nabble.com/file/t372706/Data_fitting.txt>  



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug?

Doug Stewart-4


On Fri, Feb 9, 2018 at 7:06 AM, mrodrig <[hidden email]> wrote:
Hello,

I am trying to make a data fitting using the leasqr function. In the
attachment you can find the data and the function that I am trying to adjust
and the adjustment parameters.

When plotting x vs y and the F function with the par parameters, initially
it seems reasonable.

When I make the adjustment I get the following result

error: weighted residuals are not real
error: called from
     __lm_svd__ at line 467 column 11
 
I searched and there are other users that something similar has happened to
them

Somebody could help me

Data_fitting.txt
<http://octave.1599824.n4.nabble.com/file/t372706/Data_fitting.txt>



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------


I tried your code, and see the same error as you reported.

I don't know for sure what the problem is, but your equation is a way too long.
I would suggest starting with only 2 or 3 terms and git that much working, and then add more terms as is needed.
Usually one wants the shortest equation possible, unless you have some physics that says what the equation looks like.  

There is also some places in your equation that could be ambiguous, so add more brackets.

 

--
DAS



-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug?

Olaf Till-2
In reply to this post by mrodrig
On Fri, Feb 09, 2018 at 05:06:08AM -0700, mrodrig wrote:

> Hello,
>
> I am trying to make a data fitting using the leasqr function. In the
> attachment you can find the data and the function that I am trying to adjust
> and the adjustment parameters.
>
> When plotting x vs y and the F function with the par parameters, initially
> it seems reasonable.
>
> When I make the adjustment I get the following result
>
> error: weighted residuals are not real
Assuming you havn't specified non-real weights or 'y', this error
means that your fitted function ('F' ?) returns non-real residuals for
a set of parameters chosen by leasqr during the course of
optimization. If you can't change the function 'F' to fix this, it may
help to avoid certain parameter values by specifying constraints.

(I recommend using nonlin_curvefit instead of leasqr. The default
algorithm is the same.)

Olaf

--
public key id EAFE0591, e.g. on x-hkp://pool.sks-keyservers.net


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug?

mrodrig
Dear Olaf,

Thanks for your response.

The function F is the Physic Model that I am try to use, so I can´t change.

I try the following

[P, funcion, cvg] = nonlin_curvefit (F, pin, x, y);
with
pin=[359;58337;1.1;0.9;400;150000;1.1;0.9;460;170000;1.1;0.9; 525; 62456;
1.1;0.9]

and I have the same problem.

error: weighted residuals are not real

Looking in the debug mode, I found that

  f = F (p);
        r = wt .* f;
        r = r(:);
**        if (~isreal (r))
          error ("weighted residuals are not real");
        endif

but if I look in **

but
r =

  -7234.132 +    0.000i
  -6749.209 +    0.000i
  -6268.353 +    0.000i
  -5526.880 +    0.000i
  -4790.524 +    0.000i
  -3608.309 +    0.000i
  -2227.055 +    0.000i
.....
Could you help me?

Mauricio




--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug?

mrodrig
In reply to this post by Doug Stewart-4
Hello Doug,

Unfortunately I can not change the physical model. In fact, the plot of F
with the initial parameters seems to reasonably explain the problem.

I tried doing tests with simpler functions and it works. The function F is
the sum of four functions F1 + F2 + F3 + F4. I tried to make the adjustment
with one of the functions to other experimental data and it seems to be
fine. Perhaps the problem arises when incorporating many variables?

Any other suggestions?

Mauricio



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug?

Olaf Till-2
In reply to this post by mrodrig
On Thu, Feb 15, 2018 at 06:33:52AM -0700, mrodrig wrote:
> The function F is the Physic Model that I am try to use, so I can´t change.

But that is probably where the problem is... Why can't you change F?

> r =
>
>   -7234.132 +    0.000i
>   -6749.209 +    0.000i
>   -6268.353 +    0.000i
>   -5526.880 +    0.000i
>   -4790.524 +    0.000i
>   -3608.309 +    0.000i
>   -2227.055 +    0.000i
> .....
> Could you help me?
If you can't change F, and constraints don't help, probably not.

But if you know the imaginary parts are always negligible, you could
remove the imaginary parts of r, either with an additional line of
code in F (but you say you can't change F ??) or by calling F from
another function.

Olaf

--
public key id EAFE0591, e.g. on x-hkp://pool.sks-keyservers.net


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug?

mrodrig
Dear Olaf,

Thanks for your prompt response.

How can I include limits for the values I'm looking for using the
nonlin_curvefit?

In the example of the demo it appears

  ## linear constraints, A. ' * parametervector + B> = 0
   A = [1; -1]; B = 0; # p (1)> = p (2);
   settings = optimset ("inequc", {A, B});

In my case, the constrains would be of the type

maximum value and minimum value

for example pair (3) should be between 1.1 and 2?

Thanks
Mauricio



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------