Re: faster minimization needed - maybe mpfit? [message #79735 is a reply to message #79653] |
Mon, 26 March 2012 15:36   |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
On Monday, March 26, 2012 3:59:41 PM UTC-4, chris wrote:
> On 26 Mrz., 21:04, Craig Markwardt <craig.markwa...@gmail.com> wrote:
>> On Monday, March 26, 2012 9:15:30 AM UTC-4, chris wrote:
>>> Hi folks,
>>> the following expression runs successfully with AMOEBA but requires
>>> for large matrices (columns < 512, rows up to 30000), for small
>>> tolerances (e.g. ftol=1e-06) and a high number of iterations
>>> (nmax>=10000) to converge years:
>>
>>> expr = total(abs(convol(im-rebin(p[*],size(im,/dim),/samp),
>>> [-1.,0.,1.])))
>>
>>> where p is the parameter vector (one row) to be found and im is the
>>> matrix.
>>
>>> Is there a way to do it faster? Maybe with mpfit (I don't get an idea
>>> how...)
>>
>> If you can express your problem as minimize{TOTAL(RESID^2)}, then you can use MPFIT, where RESID is signed. In your case you can do this, but there's a few little tricks.
>>
>> Your problem looks like minimize{TOTAL(ABS(XXX))}.
>>
>> You might want to define RESID=SQRT(ABS(XXX)), and then in principle it looks like an MPFIT problem. Unfortunately you need to preserve the sign of XXX. So this is what you do:
>> RESID = SIGN(XXX)*SQRT(ABS(XXX))
>> where SIGN(XXX) is the sign of XXX (-1 or +1 depending on XXX).
>>
>> Happy equation solving...
>> Craig
>
> Hi Craig,
> thank you. Nevertheless, I don't think that I understood what you
> suggests. So, i tried this:
>
> function test2,p,x=x,err=err
> temp=convol(x,rebin(p[*],size(x,/dim)))
> return,signum(temp)*sqrt(abs(temp))
> end
>
> But what I got is this:
>
> ENVI> st={x:im}&help,mpfit('test2',functargs=st,maxiter=100)
> <Expression> DOUBLE = NaN
>
> What's wrong?
Problem #1. You need to provide starting values, for P, just like for AMOEBA.
Problem #2. You changed the function. Your residual in your original post was of the form convol(im-rebin(p)). Why did you change it?
Issue #3. Error checking. Use the STATUS and ERRMSG keywords to retrieve more error information about what went wrong.
By the way, are you sure you want to solve a least absolute deviation problem? Or would you be satisfied with a least squares solution? Least squares is so much easier, for example you can use MPFITFUN().
Craig
|
|
|