mpfit and linear equality constraints [message #79065] |
Mon, 30 January 2012 08:32  |
Mats Löfdahl
Messages: 263 Registered: January 2012
|
Senior Member |
|
|
I want to do non-linear model fitting with linear equality constraints and I just want to check that I've understood the mpfit "tied" keyword functionality correctly. Am I correct in believing it does not use the theory for linear equality constraints at all, it just removes the tied parameters from the problem and calculates them afterwards from the non-tied parameters?
By "theory for linear equality constraints" I'm referring the procedure where you calculate an orthogonal decomposition of the constraints matrix, extract the basis vectors for the null space, etc. And then use this to reduce the dimension of the problem by the same number of parameters but instead of removing parameters from the problem, you'd be solving for combinations of the parameters that are tied to one another. (Not meant as a full description, just a reminder for those who have encountered it before.)
I can't find any of that going on in mpfit.pro but I thought I'd ask just to make sure.
If I'm right, I'd be interested in pointers to IDL code implementing this kind of processing. Particularly if it does it and still uses mpfit for the actual fitting once the constraints part is out of the way.
|
|
|
Re: mpfit and linear equality constraints [message #79135 is a reply to message #79065] |
Tue, 31 January 2012 12:40  |
Mats Löfdahl
Messages: 263 Registered: January 2012
|
Senior Member |
|
|
Den tisdagen den 31:e januari 2012 kl. 17:33:09 UTC+1 skrev Craig Markwardt:
> No computer can solve an equation exactly, it's a matter of
> tolerances.
OK, point taken...
>> I guess one could force the approximation of the constraints to be arbitrarily good by setting the tolerances for those equations as very small. But above you say that I should rescale the constraints equations so their residuals are comparable to the data constraints, so this does not seem to be what you mean.
>
> I would say that you should proceed iteratively. First put a looser
> tolerance on your constraint equations. Then when the equation is
> close to solved, tighten the tolerances. The solution should converge
> very quickly.
Oh, so that was what you meant. OK, it's a different approach from what I've used before but I can see that it would be doable. I think I'll give it a try. Thank you very much!
/Mats
|
|
|
Re: mpfit and linear equality constraints [message #79139 is a reply to message #79065] |
Tue, 31 January 2012 08:33  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
On Jan 31, 5:03 am, Mats Löfdahl <mats.lofd...@gmail.com> wrote:
> Den måndagen den 30:e januari 2012 kl. 22:56:44 UTC+1 skrev Craig Markwardt:
> Thanks! I read your slides and I think I get some of it. That is, it seems to me that I would be able to do it with a reasonable effort.
>
> But does it really do what I'm trying to accomplish? I want those constraints to be fulfilled exactly. If I were to add my constraints equations naively, for sure they would only be solved in the same approximate sense as the rest of the equations. If there is something in the method you describe that forces them to be solved exactly, I don't quite see it.
No computer can solve an equation exactly, it's a matter of
tolerances.
> I guess one could force the approximation of the constraints to be arbitrarily good by setting the tolerances for those equations as very small. But above you say that I should rescale the constraints equations so their residuals are comparable to the data constraints, so this does not seem to be what you mean.
I would say that you should proceed iteratively. First put a looser
tolerance on your constraint equations. Then when the equation is
close to solved, tighten the tolerances. The solution should converge
very quickly.
The reason to not set very tight tolerances at the beginning is that a
few very large residuals will confuse any solver. If some of the
residuals are ~1 and others are ~1e7, then most any matrix solver will
become unreliable.
Craig
|
|
|
Re: mpfit and linear equality constraints [message #79147 is a reply to message #79065] |
Tue, 31 January 2012 02:03  |
Mats Löfdahl
Messages: 263 Registered: January 2012
|
Senior Member |
|
|
Den måndagen den 30:e januari 2012 kl. 22:56:44 UTC+1 skrev Craig Markwardt:
> Greetings--
>
> On Jan 30, 11:32 am, mats.l...@gmail.com wrote:
>> I want to do non-linear model fitting with linear equality constraints and I just want to check that I've understood the mpfit "tied" keyword functionality correctly. Am I correct in believing it does not use the theory for linear equality constraints at all, it just removes the tied parameters from the problem and calculates them afterwards from the non-tied parameters?
>
> You are correct that MPFIT does the former, not the latter.
I'm getting confused by my own negations so I'll stick with the notion that I'm correct... :o)
>> By "theory for linear equality constraints" I'm referring the procedure ...
> ...
>> If I'm right, I'd be interested in pointers to IDL code implementing this kind of processing. Particularly if it does it and still uses mpfit for the actual fitting once the constraints part is out of the way.
>
> I think you can accomplish some of what you want to do if you impose
> constraints as additional equations in the problem. I outlined how
> one can do this in my 2009 talk at IDL Visualize. [*] You need to
> think of your N data points as N equations (to be solved in a least
> squared sense). Adding more constraints is just adding more equations
> to the list.
>
> Basically, if you have N data points and M constraints, your user
> function needs to compute N+M residual values.
> The first N residuals are just the standard (data-model) residuals.
> The following M residuals are the result of computing your constraint
> equations. MPFIT doesn't care which is which.
>
> The M constraints should be expressed as f(p) = 0, (where p =
> parameters). For example if your constraint is P[0] EQ 4*P[1], it
> needs to be re-expressed as P[0] - 4*P[1] EQ 0. MPFIT just solves
> systems of equations where {f_i(p) = 0}, so if you can express your
> constraints in the same form it will do the trick. You may need to re-
> scale the constraint equations so that their residuals are comparable
> to the N data constraints.
>
> MPFIT solves the equation by orthogonal decomposition, so adding
> constraint equations to the problem should achieve what you want to
> do.
Thanks! I read your slides and I think I get some of it. That is, it seems to me that I would be able to do it with a reasonable effort.
But does it really do what I'm trying to accomplish? I want those constraints to be fulfilled exactly. If I were to add my constraints equations naively, for sure they would only be solved in the same approximate sense as the rest of the equations. If there is something in the method you describe that forces them to be solved exactly, I don't quite see it.
I guess one could force the approximation of the constraints to be arbitrarily good by setting the tolerances for those equations as very small. But above you say that I should rescale the constraints equations so their residuals are comparable to the data constraints, so this does not seem to be what you mean.
/Mats
|
|
|
Re: mpfit and linear equality constraints [message #79152 is a reply to message #79065] |
Mon, 30 January 2012 13:56  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
Greetings--
On Jan 30, 11:32 am, mats.lofd...@gmail.com wrote:
> I want to do non-linear model fitting with linear equality constraints and I just want to check that I've understood the mpfit "tied" keyword functionality correctly. Am I correct in believing it does not use the theory for linear equality constraints at all, it just removes the tied parameters from the problem and calculates them afterwards from the non-tied parameters?
You are correct that MPFIT does the former, not the latter.
> By "theory for linear equality constraints" I'm referring the procedure ...
...
> If I'm right, I'd be interested in pointers to IDL code implementing this kind of processing. Particularly if it does it and still uses mpfit for the actual fitting once the constraints part is out of the way.
I think you can accomplish some of what you want to do if you impose
constraints as additional equations in the problem. I outlined how
one can do this in my 2009 talk at IDL Visualize. [*] You need to
think of your N data points as N equations (to be solved in a least
squared sense). Adding more constraints is just adding more equations
to the list.
Basically, if you have N data points and M constraints, your user
function needs to compute N+M residual values.
The first N residuals are just the standard (data-model) residuals.
The following M residuals are the result of computing your constraint
equations. MPFIT doesn't care which is which.
The M constraints should be expressed as f(p) = 0, (where p =
parameters). For example if your constraint is P[0] EQ 4*P[1], it
needs to be re-expressed as P[0] - 4*P[1] EQ 0. MPFIT just solves
systems of equations where {f_i(p) = 0}, so if you can express your
constraints in the same form it will do the trick. You may need to re-
scale the constraint equations so that their residuals are comparable
to the N data constraints.
MPFIT solves the equation by orthogonal decomposition, so adding
constraint equations to the problem should achieve what you want to
do.
Best wishes,
Craig
[*] "Equation Solving with MPFIT," 2009 "IDL Visualize" workshop
http://www.physics.wisc.edu/~craigm/idl/fitting.html
|
|
|