Downhill Simplex


John_S
08-29-2010, 02:15 AM
I am trying to determine the constants for this nolinear
equation. This is my equation:

y = a+b*(1-exp(-t/c));

I have the vectors for y & t;

I want to solve for the constants a, b,c using downhillsimplex(not other method) from neumerical recipie and I want to know how I should define my input and the function in amoeba.
Thank you in advance.

jaje
08-29-2010, 03:09 AM
You are minimizing with respect to which norm? If this is a least-squares fit, I see no reason to insist on using Nelder-Mead instead of Levenberg-Marquardt.

Jan M.

John_S
08-29-2010, 11:38 AM
Thanks for the reply.I have used the levenberg marquardt and result is good but when my data are very noisy the result from levenberg marquardt is not very promissing then now I am keen to use this function as is more global.I appreciate any advice to help me to put the correct input in amoeba.

lim83
08-31-2010, 08:08 PM
hi john_s,

how did you use the LM routine? can you post your code up here? i would like to use LM too, but i do not know how to implement it.

thanks.

John_S
09-01-2010, 04:31 PM
NR::mrqmin(Vec_I_DP &x, Vec_I_DP &y, Vec_I_DP &sig, Vec_IO_DP &a,
Vec_I_BOOL &ia, Mat_O_DP &covar, Mat_O_DP &alpha, DP &chisq,
void funcs(const DP, Vec_I_DP &, DP &, Vec_O_DP &), DP &alamda)
in my case: x and y were the known parameters in the equation(for examole 4 point(x,y). Sig was a vector of 1.a is your intial guess and funcs is a function which you should put the first derivities of your unknown variables.
did you find about simplex?

lim83
09-01-2010, 09:22 PM
actually i realised i cannot use the LM algorithm after all, because my function is rather complicated and its not easy getting the derivatives.

i am still trying to figure out how to use amoeba.c. i have an example, though, and you might find this useful. it is as follows:



/* Driver for routine amoeba */

#include <stdio.h>
#include <math.h>
#define NRANSI
#include "nr.h"
#include "nrutil.h"

#define MP 4
#define NP 3
#define FTOL 1.0e-6

float func(float x[])
{
return 0.6-bessj0(SQR(x[1]-0.5)+SQR(x[2]-0.6)+SQR(x[3]-0.7));
}

int main(void)
{
int i,nfunc,j,ndim=NP;
float *x,*y,**p;

x=vector(1,NP);
y=vector(1,MP);
p=matrix(1,MP,1,NP);
for (i=1;i<=MP;i++) {
for (j=1;j<=NP;j++)
x[j]=p[i][j]=(i == (j+1) ? 1.0 : 0.0);
y[i]=func(x);
}
amoeba(p,y,ndim,FTOL,func,&nfunc);
printf("\nNumber of function evaluations: %3d\n",nfunc);
printf("Vertices of final 3-d simplex and\n");
printf("function values at the vertices:\n\n");
printf("%3s %10s %12s %12s %14s\n\n",
"i","x[i]","y[i]","z[i]","function");
for (i=1;i<=MP;i++) {
printf("%3d ",i);
for (j=1;j<=NP;j++) printf("%12.6f ",p[i][j]);
printf("%12.6f\n",y[i]);
}
printf("\nTrue minimum is at (0.5,0.6,0.7)\n");
free_matrix(p,1,MP,1,NP);
free_vector(y,1,MP);
free_vector(x,1,NP);
return 0;
}
#undef NRANSI


edit: if you know how to modify this and feed in your own model/data, pls let me know. thx

John_S
09-06-2010, 06:00 PM
Hi,
I think I figure out how to use downhill simplex. I set the funk to minimise the sum like:
sum+= (Yfrom my experimental[0-3inmycase] - Y from equation(with unknown values))* (Yfrom my experimental[L] - Y from equation(with unknown values))
p should be sets of your initial guesses for example if you have 3 parameters to fit you should have 4 set of guesses in the matrix p(4by3).the rest is similar to the example.