Skip to content
Snippets Groups Projects
Commit 7d70e12c authored by Tim Behrens's avatar Tim Behrens
Browse files

Fixed minsearch problem with non-varying parameters

parent d6a81240
No related branches found
No related tags found
No related merge requests found
...@@ -212,17 +212,18 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto ...@@ -212,17 +212,18 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto
} }
} }
//Number of parameters to estimate //Number of parameters to estimate
int n=x.Nrows()-n_nonvary, maxiter=200*n,iter=0; int n=x.Nrows()-n_nonvary, maxiter=200*n,iter=0;
int ntot=x.Nrows();
int func_evals=0; int func_evals=0;
// Some things we'll need. // Some things we'll need.
float rho=1,chi=2,psi=0.5,sigma=0.5; float rho=1,chi=2,psi=0.5,sigma=0.5;
float tolx=1e-6,tolf=1e-6; float tolx=1e-6,tolf=1e-6;
ColumnVector onesn(n); ColumnVector onesn(ntot);
onesn=1; onesn=1;
ColumnVector one2n(n),two2np1(n); ColumnVector one2n(ntot),two2np1(ntot);
for(int i=1;i<=n;i++){ for(int i=1;i<=ntot;i++){
one2n(i)=i; one2n(i)=i;
two2np1(i)=i+1; two2np1(i)=i+1;
} }
...@@ -241,15 +242,14 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto ...@@ -241,15 +242,14 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto
float usual_delta=0.05,zero_term_delta=0.00025; float usual_delta=0.05,zero_term_delta=0.00025;
//perturb each parameter by a bit, and store the cost. //perturb each parameter by a bit, and store the cost.
ColumnVector y; ColumnVector y=x;
for(int i=1;i<=n;i++){ for(int i=1;i<=n;i++){
// The values of nonvarying parameters should be the same in // The values of nonvarying parameters should be the same in
// all of the optional param vectors and therefore in all // all of the optional param vectors and therefore in all
// combinations of them in the remainder of the code. // combinations of them in the remainder of the code.
if(paramstovary(i)==1){ if(paramstovary(i)==1){
y=x;
if(y(i)!=0){y(i)=(1+usual_delta)*y(i);} if(y(i)!=0){y(i)=(1+usual_delta)*y(i);}
else{y(i)=(1+zero_term_delta);} else{y(i)=(1+zero_term_delta);}
en=func.evaluate(y); en=func.evaluate(y);
...@@ -265,12 +265,10 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto ...@@ -265,12 +265,10 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto
sort(v.begin(),v.end(),pair_comparer()); //wasn't that easy... sort(v.begin(),v.end(),pair_comparer()); //wasn't that easy...
string how=""; string how="";
ColumnVector xbar(n),xr(n),xe(n),xc(n),xcc(n),xtmp(n); ColumnVector xbar(ntot),xr(ntot),xe(ntot),xc(ntot),xcc(ntot),xtmp(ntot);
//cerr<<"starting loop"<<endl; //cerr<<"starting loop"<<endl;
while(iter<=maxiter){ while(iter<=maxiter){
iter++; iter++;
if(v[n].first-v[0].first< tolf){ if(v[n].first-v[0].first< tolf){
ColumnVector tmpvec1,tmpvec2; ColumnVector tmpvec1,tmpvec2;
bool stopsearch=true; bool stopsearch=true;
...@@ -283,7 +281,6 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto ...@@ -283,7 +281,6 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto
} }
if(stopsearch){break;} if(stopsearch){break;}
} }
//compute reflection point //compute reflection point
// xbar is average of best n paramsets. // xbar is average of best n paramsets.
...@@ -294,7 +291,7 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto ...@@ -294,7 +291,7 @@ void minsearch(ColumnVector& x, const EvalFunction& func, ColumnVector& paramsto
xbar=xbar/n; xbar=xbar/n;
xr=(1+rho)*xbar-rho*v[n].second; //reflection point xr=(1+rho)*xbar-rho*v[n].second; //reflection point
float en_xr=func.evaluate(xr);func_evals++; float en_xr=func.evaluate(xr);func_evals++;
if(en_xr < v[0].first){ //en_xr is better than our current best if(en_xr < v[0].first){ //en_xr is better than our current best
//compute expansion point //compute expansion point
xe=(1+rho*chi)*xbar-rho*chi*v[n].second; xe=(1+rho*chi)*xbar-rho*chi*v[n].second;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment