Skip to content
Snippets Groups Projects
Commit 019de600 authored by Jesper Andersson's avatar Jesper Andersson
Browse files

Fixed bug that meant that amoeba only worked for strictly positive cost-functions

parent a9d6db82
No related branches found
No related tags found
No related merge requests found
......@@ -165,12 +165,12 @@ void Simplex::MultiContract()
void Simplex::UpdateRankIndicies()
{
double minv = std::numeric_limits<double>::max();
double maxv = std::numeric_limits<double>::min();
double maxv = -std::numeric_limits<double>::max();
for (unsigned int i=0; i<_fv.size(); i++) {
if (_fv[i] < minv) { minv = _fv[i]; _bsti = i; }
if (_fv[i] > maxv) { maxv = _fv[i]; _wrsti = i; }
}
maxv = std::numeric_limits<double>::min();
maxv = -std::numeric_limits<double>::max();
for (unsigned int i=0; i<_fv.size(); i++) {
if (i != _wrsti) {
if (_fv[i] > maxv) { maxv = _fv[i]; _nwsti = i; }
......
......@@ -400,32 +400,32 @@ NonlinOut levmar(const NonlinParam& p, const NonlinCF& cfo)
NonlinOut amoeba(const NonlinParam& p,
const NonlinCF& cfo)
{
// cout << "Initialsing simplex" << endl;
// cout << "Initialsing simplex" << endl; cout.flush();
Simplex smplx(p.Par(),cfo,p.GetAmoebaStart());
p.SetCF(smplx.BestFuncVal());
while (p.NextIter()) {
// Check for convergence based on fractional difference
// between best and worst points in simplex.
// cout << "New iteration: Checking for convergence" << endl;
// cout << "New iteration: Checking for convergence" << endl; cout.flush();
if (zero_cf_diff_conv(smplx.WorstFuncVal(),smplx.BestFuncVal(),p.FractionalCFTolerance())) {
p.SetStatus(NL_CFCONV);
return(p.Status());
}
// cout << "Attempting reflexion" << endl;
// cout << "Attempting reflexion" << endl; cout.flush();
double newf = smplx.Reflect(); // Attempt reflexion
// Extend into an expansion if reflexion very successful
if (newf <= smplx.BestFuncVal()) {
// cout << "Reflexion succesful: attempting expansion" << endl;
// cout << "Reflexion succesful: attempting expansion" << endl; cout.flush();
smplx.Expand(); // Attempt expansion
}
else if (newf >= smplx.SecondWorstFuncVal()) {
// cout << "New value worse than second worst: attempting contraction" << endl;
// cout << "New value worse than second worst: attempting contraction" << endl; cout.flush();
double worst_fval = smplx.WorstFuncVal();
newf = smplx.Contract(); // Do a contraction towards plane of "better" points
if (newf >= worst_fval) { // Didn't work. Contract towards best point
// cout << "Contraction unsuccesful: contracting towards best point" << endl;
// cout << "Contraction unsuccesful: contracting towards best point" << endl; cout.flush();
smplx.MultiContract();
}
}
......
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