Another MPFIT question [message #62830] |
Sat, 11 October 2008 14:35  |
MichaelT
Messages: 52 Registered: May 2006
|
Member |
|
|
Today I discovered MPFIT and I am so excited how well it works (many
thanks Craig!).
I ran into one problem, however, which I was not able to solve. Maybe,
there is a simple solution.
Among all the parameters I have four whose sum must not be larger than
a certain value:
0 < c1+c2+c3+c4 < 1.
All four parameters may vary between zero and one which I implemented
using .limits and .limited. But, how do I implement the additional
constraint? Any ideas? It may be too obvious for me to see...
Thanks, Michael
|
|
|
|
Re: Another MPFIT question [message #62911 is a reply to message #62830] |
Mon, 13 October 2008 03:06   |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
MichaelT <michael.theusner@googlemail.com> writes:
> Today I discovered MPFIT and I am so excited how well it works (many
> thanks Craig!).
>
> I ran into one problem, however, which I was not able to solve. Maybe,
> there is a simple solution.
> Among all the parameters I have four whose sum must not be larger than
> a certain value:
>
> 0 < c1+c2+c3+c4 < 1.
>
> All four parameters may vary between zero and one which I implemented
> using .limits and .limited. But, how do I implement the additional
> constraint? Any ideas? It may be too obvious for me to see...
The short answer is that MPFIT does not handle complex inequality
constraints, only simple box boundary constraints on each parameter.
Vince's suggestion of re-expressing with different parameters is a
good one, but as you discovered, all the constraints become difficult.
You may be able to cheat. You could append a special data point which
contributes "badness" whenever the parameters go outside of their
desired bounds. For example, if you have 100 data points, you would
append a 101st residual, computed something like this,
big = 100 ; Bigger than your biggest residual
cc = c1+c2+c3+c4 ; Total
cclimits = [0d, 1d] ; Limits on total
toler = 0.001d ; Tolerance on limits
yy = (1-tanh((cc-cclimits(0))/toler))/2 + (1+tanh((cc-cclimits(1))/toler))/2
resid[101] = big*yy
Since MPFIT simply tries to minimize residuals, the presence of one
more residual will be handled just fine. As long as the parameters
are within constraints, the 101st residual contributes nothing, but if
they begin to touch the constraint, resid[101] will start to grow, and
hopefully repel the fitter from going that direction. All untested of
course.
The TANH() functions make an inverse box-car shape, but with smooth
edges. The smoothness is key, otherwise the fitter will rightly fail
due to discontinuities.
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: cbmarkwardt+usenet@gmail.com
------------------------------------------------------------ --------------
|
|
|
|
|
|
Re: Another MPFIT question [message #63478 is a reply to message #63383] |
Sat, 08 November 2008 08:23  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
On Nov 6, 5:03 pm, jgrimm...@yahoo.com wrote:
> On 15 Oct 2008 07:22:32 -0400, Craig Markwardt
>
> <craigm...@REMOVEcow.physics.wisc.edu> wrote:
>
> Craig,
>
>> MichaelT <michael.theus...@googlemail.com> writes:
>>> Hi again, I just tried it and it works perfectly! Thanks again!
>
>> Huh. That actually blows my mind. I've never tried that before!
>
>> Craig
>
> You are mimicking the penalty function approach to
> constraints! (Unless, I am really missing something
> here ....).
Right, I understand that. The mind-blowing part was that it worked on
the first try :-)
|
|
|