Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to limit fit variables

2,823 views
Skip to first unread message

Mario Gossla

unread,
Feb 19, 2004, 7:30:01 AM2/19/04
to
Hi everybody,

I managed to simulate and even fit an implicite function *happy*. But
now my fit parameters are running away. Well, unfortunately the data
aren't behaving like in the textbook. :-(

For example:

fit [x=-1.5:1.5] f(x,y) 'mess.dat' using 1:2:3:(1) via Diodeideality

where Diodeideality should run within [1:2]

Is there a way to tell Gnuplot it's limits ?

Mario

Hans-Bernhard Broeker

unread,
Feb 19, 2004, 9:24:39 AM2/19/04
to
Mario Gossla <hal__remove_...@gmx.li> wrote:

> I managed to simulate and even fit an implicite function *happy*.

There is no such thing as an implicit function: there are implicit
curves, but they're not functions.

> But now my fit parameters are running away. Well, unfortunately the
> data aren't behaving like in the textbook. :-(

> For example:

> fit [x=-1.5:1.5] f(x,y) 'mess.dat' using 1:2:3:(1) via Diodeideality

> where Diodeideality should run within [1:2]

> Is there a way to tell Gnuplot it's limits ?

You'll have to transform the range manually. I.e. you won't
be using the actual parameter, but a variable whose value determines
the real physical parameter. For good measure, let's redefine
f such that the parameter is one of its arguments:

f(x,y,D) = # ... whatever ....
Dmap(p) = 1.0 + (2.0 - 1.0) * (tanh(p) + 1.0)/2.0

fit [-1.5:1.5] f(x,y,Dmap(p)) 'mess.dat' u 1:2:3:(1) via p

You'll have to translate the resulting 'p' and its error into value
and error of 'D' yourself.


--
Hans-Bernhard Broeker (bro...@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.

Mario Gossla

unread,
Feb 19, 2004, 10:01:41 AM2/19/04
to
Hans-Bernhard Broeker wrote:


> There is no such thing as an implicit function: there are implicit
> curves, but they're not functions.

Ok, but ... For example:

http://www.mapleapps.com/powertools/calcI/html/L11-implicitDifferentiation.html

http://www-math.math.rwth-aachen.de/MapleAnswers/135.html

> You'll have to transform the range manually. I.e. you won't
> be using the actual parameter, but a variable whose value determines
> the real physical parameter. For good measure, let's redefine
> f such that the parameter is one of its arguments:
>
> f(x,y,D) = # ... whatever ....
> Dmap(p) = 1.0 + (2.0 - 1.0) * (tanh(p) + 1.0)/2.0
>
> fit [-1.5:1.5] f(x,y,Dmap(p)) 'mess.dat' u 1:2:3:(1) via p
>
> You'll have to translate the resulting 'p' and its error into value
> and error of 'D' yourself.

Thanks, I guess that'll do the trick.

Mario

Mario Gossla

unread,
Feb 20, 2004, 5:41:17 AM2/20/04
to
Hans-Bernhard Broeker wrote:

> You'll have to transform the range manually. I.e. you won't
> be using the actual parameter, but a variable whose value determines
> the real physical parameter. For good measure, let's redefine
> f such that the parameter is one of its arguments:

I did a remapping now, and the fit is ok. Limiting works, and the fits
are converging. But now I have another prob. After the results were
given, I get now:

Singular matrix in Invert_RtR

And here the script stops. What does that mean? Seems like an overflow
in matrix.c? Below is a part of gnuplots outputs.

Mario

<<<<begin of screen excerpt>>>>

Iteration 14
WSSR : 8.92225 delta(WSSR)/WSSR : -9.89047e-08
delta(WSSR) : -8.82453e-07 limit for stopping : 1e-06
lambda : 1.21465e-14

resultant parameter values

Imap = -2694.28
Rpmap = -91784.7
Nmap = 34710.6
Rsmap = 687.333

After 14 iterations the fit converged.
final sum of squares of residuals : 8.92225
rel. change during last iteration : -9.89047e-08

degrees of freedom (ndf) : 37
rms of residuals (stdfit) = sqrt(WSSR/ndf) : 0.491062
variance of residuals (reduced chisquare) = WSSR/ndf : 0.241142

Singular matrix in Invert_RtR

<<<<end of screen excerpt>>>>

Hans-Bernhard Broeker

unread,
Feb 20, 2004, 7:44:56 AM2/20/04
to
Mario Gossla <hal__remove_...@gmx.li> wrote:

> I did a remapping now, and the fit is ok. Limiting works, and the fits
> are converging. But now I have another prob. After the results were
> given, I get now:

> Singular matrix in Invert_RtR

"Singular matrix" means that something's wrong with your model
function, at the particular set of parameter values found by the fit,
with your given data. Without seeing the data and the function
involved, it's hard to tell what exactly the problem is, but it'll
usually be something like WSSR being independent of one of the
parameters you tried to fit, or some similar numerical hickup.

This can also happen if your fit parameters have very different
magnitudes, or one of them came out being zero, but that doesn't seem
to be the case here.

Mario Gossla

unread,
Feb 20, 2004, 11:16:45 AM2/20/04
to
Hans-Bernhard Broeker wrote:

> "Singular matrix" means that something's wrong with your model
> function, at the particular set of parameter values found by the fit,
> with your given data. Without seeing the data and the function

Well the trouble occured only after limiting the fitting parameters via
tanh(p). I'll check the new function, again.

> involved, it's hard to tell what exactly the problem is, but it'll
> usually be something like WSSR being independent of one of the
> parameters you tried to fit, or some similar numerical hickup.

But isn't that a general problem of the work arround with the mapping
via tanh(p), when a parameter is running to the edge of the definition
range?

Mario

Hans-Bernhard Broeker

unread,
Feb 20, 2004, 11:38:51 AM2/20/04
to
Mario Gossla <hal__remove_...@gmx.li> wrote:
> Hans-Bernhard Broeker wrote:

> > involved, it's hard to tell what exactly the problem is, but it'll
> > usually be something like WSSR being independent of one of the
> > parameters you tried to fit, or some similar numerical hickup.

> But isn't that a general problem of the work arround with the mapping
> via tanh(p), when a parameter is running to the edge of the definition
> range?

Could be. But then, the real problem is not in the mapping via tanh()
itself, but rather that the actual model parameter ended up being
driven right to the end of its allowed range. You may have to redo
the fit with that parameter fixed at its endpoint value.

Formally, the singularity means that the error obtained for at least
one of the parameters being fitted came out as infinitely large --- it
happens in computing the inverted matrix that would give the errors
and correlations usually printed at the end of each fit.

Mario Gossla

unread,
Feb 20, 2004, 2:44:05 PM2/20/04
to
Hans-Bernhard Broeker wrote:
>>But isn't that a general problem of the work arround with the mapping
>>via tanh(p), when a parameter is running to the edge of the definition
>>range?
>
>
> Could be. But then, the real problem is not in the mapping via tanh()
> itself, but rather that the actual model parameter ended up being
> driven right to the end of its allowed range. You may have to redo
> the fit with that parameter fixed at its endpoint value.

Yes, this is exactly my problem. The data do not match the theory that's
why I wanted to restrict the range for the parameters. But you're right,
it's basicly a data <-> therory problem.

I fit now three parameters without limits and vary one by hand that
works pretty good, and the results make more sense anyway.

Thanks,

Mario

Hans-Bernhard Broeker

unread,
Feb 21, 2004, 4:00:50 PM2/21/04
to
Mario Gossla <hal__remove_...@gmx.li> wrote:

> Yes, this is exactly my problem. The data do not match the theory that's
> why I wanted to restrict the range for the parameters. But you're right,
> it's basicly a data <-> therory problem.

If the theory really doesn't match your data, there's nothing 'fit'
can do for you. You'll need a model that actually describes the data
before least-squares fitting can give you any kind of meaningful
answers.

Mario Gossla

unread,
Feb 23, 2004, 5:01:13 AM2/23/04
to
Hans-Bernhard Broeker wrote:
> If the theory really doesn't match your data, there's nothing 'fit'
> can do for you. You'll need a model that actually describes the data
> before least-squares fitting can give you any kind of meaningful
> answers.

Hey, I didn't say I want to fit elephants to the shape of a mouse. I'm
fitting diodes with one theory for diodes. And without setting limits to
the parameters the fit converges to, well, acceptable values. With
setting limits, the fit converges as well, but calculating the "fit
quality" fails in gnuplot.

Sometimes it's nice to release a parameter even if it is exactly at one
limit. Let's say I want to release a value p = [0:1] where 1 makes
physically sence and 0 as well. So the fit could run to exactly one or
to exactly zero. Is my theory wrong in this case? Does it not give
meaningful answers? On the other hand, sometimes a value might be
extremly large then the data might not show a difference, lets say, if
your P=1MOhms or P=1000MOhms. It's simply not in the data. Where is the
problem to limit the parameter so that it can run in a set limit? Yes I
know, I these cases I can set the parameter to the limied value myself.
That's what I'm doing right now.

I'm not complaining, nor arguing, I simply want to describe what's
happening.

Mario

Hans-Bernhard Broeker

unread,
Feb 23, 2004, 8:38:34 AM2/23/04
to
Mario Gossla <hal__remove_...@gmx.li> wrote:

> Sometimes it's nice to release a parameter even if it is exactly at one
> limit. Let's say I want to release a value p = [0:1] where 1 makes
> physically sence and 0 as well. So the fit could run to exactly one or
> to exactly zero. Is my theory wrong in this case? Does it not give
> meaningful answers?

Well, let's just say that in a case like this, tanh() or atan() aren't
quite the optimal choice of parameter transformation function. You'ld
need something like sin(x) instead, which actually reaches the
endpoint values, or if you want to reach only one of them, 1/(1+x*x).

Mario Gossla

unread,
Feb 23, 2004, 2:50:37 PM2/23/04
to
Hans-Bernhard Broeker wrote:
> Well, let's just say that in a case like this, tanh() or atan() aren't
> quite the optimal choice of parameter transformation function. You'ld
> need something like sin(x) instead, which actually reaches the
> endpoint values, or if you want to reach only one of them, 1/(1+x*x).

Yes, I was thinking about this as well. I'll probably try to knit some
mapping function in future. Right now I found out that releasing the
params completely it good enough for my current problem. Fire and
forgett will definitely not work even when limiting the released
parameters.

Anyway, I'm really impressed how powerful gnuplot, in fact, is. I didn't
realize this in the past.

Mario

Dr Engelbert Buxbaum

unread,
Feb 27, 2004, 12:21:56 AM2/27/04
to
Mario Gossla wrote:


> I did a remapping now, and the fit is ok. Limiting works, and the fits
> are converging. But now I have another prob. After the results were
> given, I get now:
>
> Singular matrix in Invert_RtR
>
> And here the script stops. What does that mean? Seems like an overflow
> in matrix.c? Below is a part of gnuplots outputs.

The Marquard-Levenberg routine used by Gnuplot (and many other programs)
is somewhat ill-behaved: It is quite sensitive toward the starting
values of the params, is limited to 3-4 params and sometimes stops
before it really has achieved the optimal results.

Nelder-Mead's Simplex algorithm (a good implementation can be found in
Caceci & Cacheris, Byte Magazine 1985) is much more flexible and
reliable. Unfortunately, error margins for the params are available only
by bootstrapping. I have used it to fit a 2-dimensional
Gauss-distribution (7 params) and substrate/activity curves with 4
catalytic and one inhibitory site (9 params), in each case M-L had
failed miserably. In one case I had only a system of differential
equations describing a complex reaction. Using Runge-Kutta I solved that
numerically, fitting the params to the measured concentration of a
reaction intermediate with Simplex!

On top of that, Simplex can easily be adapted to use other error
functions than least squares (minimum median error for data with a lot
of scatter, sum of relative residuals for data sets covering several
orders of magnitude...), and the fit function does not need to be
differentiatable.

If I had a wish free for the future development of Gnuplot, addition of
Simplex fitting would be it. Something like

set fitmode [Marquard,Simplex],

with Marquard the default so as not to break existing applications.
Alternative error functions may also be usefull, selected by a second
set command evaluated only if fitmode is Simplex.

0 new messages