Re: Another MPFIT question [message #62826] |
Sun, 12 October 2008 03:56 |
MichaelT
Messages: 52 Registered: May 2006
|
Member |
|
|
Ok, I just had this idea:
function myfunc, x, p
c0 = (p[0]+p[1]+p[2]+p[3]) > 1d
c1 = p[0] / c0
c2 = p[1] / c0
c3 = p[2] / c0
c4 = p[3] / c0
return, somefunctionof(c1,c2,c3,c4)
End
It does really limit c1+...+c4 to [0, 1] and the parameters are also
limited to [0, 1]. But, I'm not so sure whether or not it is really ok
to do it this way.
Michael
|
|
|
Re: Another MPFIT question [message #62827 is a reply to message #62826] |
Sun, 12 October 2008 03:42  |
MichaelT
Messages: 52 Registered: May 2006
|
Member |
|
|
Oh no... My changes do not change anything. Only c1 is now limited to
[0, 1], but, the others are not...
It seems Vince's idea does not help in this case, unfortunately.
I do not know what to do now. I have four parameters but five
conditions. Can anybody help?
I need to tell MPFIT the following limits:
c1,c2,c3,c4 = [0, 1]
AND
c1 + c2 + c3 + c4 = [0, 1]
Michael
|
|
|
Re: Another MPFIT question [message #62828 is a reply to message #62827] |
Sun, 12 October 2008 01:29  |
MichaelT
Messages: 52 Registered: May 2006
|
Member |
|
|
On Oct 12, 4:02 am, Vince Hradil <vincehra...@gmail.com> wrote:
> How's this
> re-parameterize our problem to -
> p[0]=c1, p[1]=c1+c2, p[2]=c1+c2+c3 and p[3]=c1+c2+c3+c4
> then limit all these to [0,1]
Many thanks Vince! That gave me the right idea!
I had to implement it a tiny little bit differently, though. It turned
out that in your suggested case c1...4 would not have been limited to
[0, 1] but [-1, 1].
So I had to do it like this:
p[0]=1-c1, p[1]=1-c1-c2, p[2]=1-c1-c2-c3 and p[3]=1-c1-c2-c3-c4
function myfunc, x, p
c1 = 1 - p[0]
c2 = p[0]-p[1]
c3 = p[1]-p[2]
c4 = p[2]-p[3]
return, somefunctionof(c1,c2,c3,c4)
end
Have a good Sunday!
Michael
|
|
|
Re: Another MPFIT question [message #62829 is a reply to message #62828] |
Sat, 11 October 2008 19:02  |
Vince Hradil
Messages: 574 Registered: December 1999
|
Senior Member |
|
|
On Oct 11, 4:35 pm, MichaelT <michael.theus...@googlemail.com> wrote:
> 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
How's this
re-parameterize our problem to -
p[0]=c1, p[1]=c1+c2, p[2]=c1+c2+c3 and p[3]=c1+c2+c3+c4
then limit all these to [0,1]
so in the function:
function myfunc, x, p
c1 = p[0]
c2 = p[1]-p[0]
c3 = p[2]-p[1]
c4 = p[3]-p[2]
return, somefunctionof(c1,c2,c3,c4)
end
|
|
|