COPASI API  4.16.103
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
COptMethodNelderMead Class Reference

#include <COptMethodNelderMead.h>

Inheritance diagram for COptMethodNelderMead:
Inheritance graph
[legend]
Collaboration diagram for COptMethodNelderMead:
Collaboration graph
[legend]

Public Member Functions

 COptMethodNelderMead (const COptMethodNelderMead &src, const CCopasiContainer *pParent=NULL)
 
virtual bool optimise ()
 
virtual ~COptMethodNelderMead ()
 
- Public Member Functions inherited from COptMethod
 COptMethod (const COptMethod &src, const CCopasiContainer *pParent=NULL)
 
bool isBounded (void)
 
virtual bool isValidProblem (const CCopasiProblem *pProblem)
 
void setProblem (COptProblem *problem)
 
virtual ~COptMethod ()
 
- Public Member Functions inherited from CCopasiMethod
 CCopasiMethod (const CCopasiMethod &src, const CCopasiContainer *pParent=NULL)
 
const CCopasiMethod::SubTypegetSubType () const
 
const CCopasiTask::TypegetType () const
 
virtual void load (CReadConfig &configBuffer, CReadConfig::Mode mode=CReadConfig::SEARCH)
 
virtual void print (std::ostream *ostream) const
 
virtual void printResult (std::ostream *ostream) const
 
virtual bool setCallBack (CProcessReport *pCallBack)
 
virtual ~CCopasiMethod ()
 
- Public Member Functions inherited from CCopasiParameterGroup
bool addGroup (const std::string &name)
 
bool addParameter (const CCopasiParameter &parameter)
 
bool addParameter (const std::string &name, const CCopasiParameter::Type type)
 
template<class CType >
bool addParameter (const std::string &name, const CCopasiParameter::Type type, const CType &value)
 
void addParameter (CCopasiParameter *pParameter)
 
CCopasiParameterGroupassertGroup (const std::string &name)
 
template<class CType >
CCopasiParameterassertParameter (const std::string &name, const CCopasiParameter::Type type, const CType &defaultValue)
 
index_iterator beginIndex () const
 
name_iterator beginName () const
 
 CCopasiParameterGroup (const CCopasiParameterGroup &src, const CCopasiContainer *pParent=NULL)
 
 CCopasiParameterGroup (const std::string &name, const CCopasiContainer *pParent=NULL, const std::string &objectType="ParameterGroup")
 
void clear ()
 
virtual bool elevateChildren ()
 
index_iterator endIndex () const
 
name_iterator endName () const
 
CCopasiParameterGroupgetGroup (const std::string &name)
 
const CCopasiParameterGroupgetGroup (const std::string &name) const
 
CCopasiParameterGroupgetGroup (const size_t &index)
 
const CCopasiParameterGroupgetGroup (const size_t &index) const
 
size_t getIndex (const std::string &name) const
 
std::string getKey (const std::string &name) const
 
std::string getKey (const size_t &index) const
 
virtual const std::string & getName (const size_t &index) const
 
virtual const CObjectInterfacegetObject (const CCopasiObjectName &cn) const
 
CCopasiParametergetParameter (const std::string &name)
 
const CCopasiParametergetParameter (const std::string &name) const
 
CCopasiParametergetParameter (const size_t &index)
 
const CCopasiParametergetParameter (const size_t &index) const
 
CCopasiParameter::Type getType (const std::string &name) const
 
CCopasiParameter::Type getType (const size_t &index) const
 
std::string getUniqueParameterName (const CCopasiParameter *pParameter) const
 
const CCopasiParameter::ValuegetValue (const std::string &name) const
 
const CCopasiParameter::ValuegetValue (const size_t &index) const
 
CCopasiParameter::ValuegetValue (const std::string &name)
 
CCopasiParameter::ValuegetValue (const size_t &index)
 
CCopasiParameterGroupoperator= (const CCopasiParameterGroup &rhs)
 
bool removeParameter (const std::string &name)
 
bool removeParameter (const size_t &index)
 
template<class CType >
bool setValue (const std::string &name, const CType &value)
 
template<class CType >
bool setValue (const size_t &index, const CType &value)
 
size_t size () const
 
bool swap (const size_t &iFrom, const size_t &iTo)
 
bool swap (index_iterator &from, index_iterator &to)
 
virtual ~CCopasiParameterGroup ()
 
- Public Member Functions inherited from CCopasiParameter
 CCopasiParameter (const CCopasiParameter &src, const CCopasiContainer *pParent=NULL)
 
 CCopasiParameter (const std::string &name, const Type &type, const void *pValue=NULL, const CCopasiContainer *pParent=NULL, const std::string &objectType="Parameter")
 
virtual CCopasiObjectName getCN () const
 
virtual const std::string & getKey () const
 
virtual std::string getObjectDisplayName (bool regular=true, bool richtext=false) const
 
const CCopasiParameter::TypegetType () const
 
const ValuegetValue () const
 
ValuegetValue ()
 
virtual voidgetValuePointer () const
 
CCopasiObjectgetValueReference () const
 
bool isValidValue (const C_FLOAT64 &value) const
 
bool isValidValue (const C_INT32 &value) const
 
bool isValidValue (const unsigned C_INT32 &value) const
 
bool isValidValue (const bool &value) const
 
bool isValidValue (const std::string &value) const
 
bool isValidValue (const CCopasiObjectName &value) const
 
bool isValidValue (const std::vector< CCopasiParameter * > &value) const
 
CCopasiParameteroperator= (const CCopasiParameter &rhs)
 
template<class CType >
bool setValue (const CType &value)
 
bool setValue (const std::vector< CCopasiParameter * > &value)
 
virtual ~CCopasiParameter ()
 
- Public Member Functions inherited from CCopasiContainer
virtual bool add (CCopasiObject *pObject, const bool &adopt=true)
 
 CCopasiContainer (const std::string &name, const CCopasiContainer *pParent=NULL, const std::string &type="CN", const unsigned C_INT32 &flag=CCopasiObject::Container)
 
 CCopasiContainer (const CCopasiContainer &src, const CCopasiContainer *pParent=NULL)
 
virtual std::string getChildObjectUnits (const CCopasiObject *pObject) const
 
virtual const objectMapgetObjects () const
 
virtual std::string getUnits () const
 
virtual const CCopasiObjectgetValueObject () const
 
virtual bool remove (CCopasiObject *pObject)
 
virtual ~CCopasiContainer ()
 
- Public Member Functions inherited from CCopasiObject
void addDirectDependency (const CCopasiObject *pObject)
 
 CCopasiObject (const CCopasiObject &src, const CCopasiContainer *pParent=NULL)
 
void clearDirectDependencies ()
 
void clearRefresh ()
 
bool dependsOn (DataObjectSet candidates, const DataObjectSet &context=DataObjectSet()) const
 
void getAllDependencies (DataObjectSet &dependencies, const DataObjectSet &context) const
 
virtual const DataObjectSetgetDirectDependencies (const DataObjectSet &context=DataObjectSet()) const
 
CCopasiContainergetObjectAncestor (const std::string &type) const
 
CCopasiDataModelgetObjectDataModel ()
 
const CCopasiDataModelgetObjectDataModel () const
 
const std::string & getObjectName () const
 
CCopasiContainergetObjectParent () const
 
const std::string & getObjectType () const
 
virtual const
CObjectInterface::ObjectSet
getPrerequisites () const
 
virtual RefreshgetRefresh () const
 
UpdateMethodgetUpdateMethod () const
 
bool hasCircularDependencies (DataObjectSet &candidates, DataObjectSet &verified, const DataObjectSet &context) const
 
bool hasUpdateMethod () const
 
bool isArray () const
 
bool isContainer () const
 
bool isDataModel () const
 
bool isMatrix () const
 
bool isNameVector () const
 
bool isNonUniqueName () const
 
virtual bool isPrerequisiteForContext (const CObjectInterface *pObject, const CMath::SimulationContextFlag &context, const CObjectInterface::ObjectSet &changedObjects) const
 
bool isReference () const
 
bool isRoot () const
 
bool isSeparator () const
 
bool isStaticString () const
 
bool isValueBool () const
 
bool isValueDbl () const
 
bool isValueInt () const
 
bool isValueInt64 () const
 
bool isValueString () const
 
bool isVector () const
 
virtual bool mustBeDeleted (const DataObjectSet &deletedObjects) const
 
void removeDirectDependency (const CCopasiObject *pObject)
 
void setDirectDependencies (const DataObjectSet &directDependencies)
 
bool setObjectName (const std::string &name)
 
virtual bool setObjectParent (const CCopasiContainer *pParent)
 
void setObjectValue (const C_FLOAT64 &value)
 
void setObjectValue (const C_INT32 &value)
 
void setObjectValue (const bool &value)
 
template<class CType >
void setRefresh (CType *pType, void(CType::*method)(void))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const C_FLOAT64 &))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const C_INT32 &))
 
template<class CType >
void setUpdateMethod (CType *pType, void(CType::*method)(const bool &))
 
virtual ~CCopasiObject ()
 
- Public Member Functions inherited from CObjectInterface
 CObjectInterface ()
 
virtual ~CObjectInterface ()
 

Private Member Functions

virtual bool cleanup ()
 
 COptMethodNelderMead (const CCopasiContainer *pParent=NULL)
 
const C_FLOAT64evaluate ()
 
virtual bool initialize ()
 
void initObjects ()
 

Private Attributes

C_FLOAT64 mBestValue
 
CVector< C_FLOAT64mCentroid
 
bool mContinue
 
CVector< C_FLOAT64mCurrent
 
C_FLOAT64 mEvaluationValue
 
size_t mhIteration
 
unsigned C_INT32 mIteration
 
unsigned C_INT32 mIterationLimit
 
C_FLOAT64 mScale
 
CMatrix< C_FLOAT64mSimplex
 
CVector< C_FLOAT64mStep
 
C_FLOAT64 mTolerance
 
CVector< C_FLOAT64mValue
 
size_t mVariableSize
 

Friends

COptMethodCOptMethod::createMethod (CCopasiMethod::SubType subType)
 

Additional Inherited Members

- Public Types inherited from CCopasiMethod
enum  SubType {
  unset = 0, RandomSearch, RandomSearchMaster, SimulatedAnnealing,
  CoranaWalk, DifferentialEvolution, ScatterSearch, GeneticAlgorithm,
  EvolutionaryProgram, SteepestDescent, HybridGASA, GeneticAlgorithmSR,
  HookeJeeves, LevenbergMarquardt, NelderMead, SRES,
  Statistics, ParticleSwarm, Praxis, TruncatedNewton,
  Newton, deterministic, LSODAR, directMethod,
  stochastic, tauLeap, adaptiveSA, hybrid,
  hybridLSODA, hybridODE45, DsaLsodar, tssILDM,
  tssILDMModified, tssCSP, mcaMethodReder, scanMethod,
  lyapWolf, sensMethod, EFMAlgorithm, EFMBitPatternTreeAlgorithm,
  EFMBitPatternAlgorithm, Householder, crossSectionMethod, linearNoiseApproximation
}
 
- Public Types inherited from CCopasiParameterGroup
typedef parameterGroup::iterator index_iterator
 
typedef
CCopasiContainer::objectMap::iterator 
name_iterator
 
typedef std::vector
< CCopasiParameter * > 
parameterGroup
 
- Public Types inherited from CCopasiParameter
enum  Type {
  DOUBLE = 0, UDOUBLE, INT, UINT,
  BOOL, GROUP, STRING, CN,
  KEY, FILE, EXPRESSION, INVALID
}
 
- Public Types inherited from CCopasiContainer
typedef std::multimap
< std::string, CCopasiObject * > 
objectMap
 
- Public Types inherited from CCopasiObject
typedef std::set< const
CCopasiObject * > 
DataObjectSet
 
typedef std::vector< Refresh * > DataUpdateSequence
 
- Public Types inherited from CObjectInterface
typedef std::set< const
CObjectInterface * > 
ObjectSet
 
typedef std::vector
< CObjectInterface * > 
UpdateSequence
 
- Static Public Member Functions inherited from COptMethod
static COptMethodcreateMethod (CCopasiMethod::SubType subType=CCopasiMethod::RandomSearch)
 
- Static Public Member Functions inherited from CCopasiObject
static std::vector< Refresh * > buildUpdateSequence (const DataObjectSet &objects, const DataObjectSet &uptoDateObjects, const DataObjectSet &context=DataObjectSet())
 
static void setRenameHandler (CRenameHandler *rh)
 
- Static Public Attributes inherited from CCopasiMethod
static const std::string SubTypeName []
 
static const char * XMLSubType []
 
- Static Public Attributes inherited from CCopasiParameter
static const std::string TypeName []
 
static const char * XMLType []
 
- Static Public Attributes inherited from CCopasiContainer
static const std::vector
< CCopasiContainer * > 
EmptyList
 
- Protected Types inherited from CCopasiObject
enum  Flag {
  Container = 0x1, Vector = 0x2, Matrix = 0x4, NameVector = 0x8,
  Reference = 0x10, ValueBool = 0x20, ValueInt = 0x40, ValueInt64 = 0x80,
  ValueDbl = 0x100, NonUniqueName = 0x200, StaticString = 0x400, ValueString = 0x800,
  Separator = 0x1000, ModelEntity = 0x2000, Array = 0x4000, DataModel = 0x8000,
  Root = 0x10000, Gui = 0x20000
}
 
- Protected Member Functions inherited from COptMethod
 COptMethod (const CCopasiTask::Type &taskType, const SubType &subType, const CCopasiContainer *pParent=NULL)
 
- Protected Member Functions inherited from CCopasiMethod
 CCopasiMethod (const CCopasiTask::Type &taskType, const SubType &subType, const CCopasiContainer *pParent=NULL)
 
- Protected Member Functions inherited from CCopasiParameterGroup
 CCopasiParameterGroup ()
 
- Protected Member Functions inherited from CCopasiContainer
template<class CType >
CCopasiObjectaddMatrixReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
template<class CType >
CCopasiObjectaddObjectReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
template<class CType >
CCopasiObjectaddVectorReference (const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
 
void initObjects ()
 
- Protected Member Functions inherited from CCopasiObject
 CCopasiObject ()
 
 CCopasiObject (const std::string &name, const CCopasiContainer *pParent=NULL, const std::string &type="CN", const unsigned C_INT32 &flag=0)
 
- Protected Attributes inherited from COptMethod
const bool mBounds
 
const std::vector< COptItem * > * mpOptContraints
 
const std::vector< COptItem * > * mpOptItem
 
COptProblemmpOptProblem
 
COptTaskmpParentTask
 
const std::vector
< UpdateMethod * > * 
mpSetCalculateVariable
 
- Protected Attributes inherited from CCopasiMethod
CProcessReportmpCallBack
 
- Protected Attributes inherited from CCopasiParameter
std::string mKey
 
CCopasiObjectmpValueReference
 
size_t mSize
 
Value mValue
 
- Protected Attributes inherited from CCopasiContainer
objectMap mObjects
 
- Static Protected Attributes inherited from CCopasiObject
static CRenameHandlersmpRenameHandler = NULL
 

Detailed Description

Definition at line 31 of file COptMethodNelderMead.h.

Constructor & Destructor Documentation

COptMethodNelderMead::COptMethodNelderMead ( const COptMethodNelderMead src,
const CCopasiContainer pParent = NULL 
)

Copy Constructor

Parameters
constCOptMethodNelderMead & src
constCCopasiContainer * pParent (default: NULL)

Definition at line 40 of file COptMethodNelderMead.cpp.

References initObjects().

41  :
42  COptMethod(src, pParent)
43 {initObjects();}
COptMethodNelderMead::~COptMethodNelderMead ( )
virtual

Destructor

Definition at line 45 of file COptMethodNelderMead.cpp.

References cleanup().

46 {cleanup();}
COptMethodNelderMead::COptMethodNelderMead ( const CCopasiContainer pParent = NULL)
private

Default Constructor

Parameters
constCCopasiContainer * pParent (default: NULL)

Definition at line 30 of file COptMethodNelderMead.cpp.

References CCopasiParameterGroup::addParameter(), C_FLOAT64, C_INT32, initObjects(), CCopasiParameter::UDOUBLE, and CCopasiParameter::UINT.

30  :
32 {
33  addParameter("Iteration Limit", CCopasiParameter::UINT, (unsigned C_INT32) 200);
34  addParameter("Tolerance", CCopasiParameter::UDOUBLE, (C_FLOAT64) 1.e-005);
36 
37  initObjects();
38 }
#define C_INT32
Definition: copasi.h:90
#define C_FLOAT64
Definition: copasi.h:92
bool addParameter(const CCopasiParameter &parameter)

Member Function Documentation

bool COptMethodNelderMead::cleanup ( )
privatevirtual

Cleanup arrays and pointers.

Returns
bool success

Reimplemented from COptMethod.

Definition at line 607 of file COptMethodNelderMead.cpp.

Referenced by initialize(), and ~COptMethodNelderMead().

608 {
609  return true;
610 }
const C_FLOAT64 & COptMethodNelderMead::evaluate ( )
private

Evaluate the objective function

Returns
bool continue

Definition at line 612 of file COptMethodNelderMead.cpp.

References COptProblem::calculate(), COptProblem::checkFunctionalConstraints(), COptProblem::checkParametricConstraints(), COptProblem::getCalculateValue(), mBestValue, mContinue, mEvaluationValue, and COptMethod::mpOptProblem.

Referenced by optimise().

613 {
614  // We do not need to check whether the parametric constraints are fulfilled
615  // since the parameters are created within the bounds.
616 
619 
620  // when we leave the either the parameter or functional domain
621  // we penalize the objective value by forcing it to be larger
622  // than the best value recorded so far.
627 
628  return mEvaluationValue;
629 }
COptProblem * mpOptProblem
Definition: COptMethod.h:56
virtual bool calculate()
virtual bool checkFunctionalConstraints()
virtual bool checkParametricConstraints()
const C_FLOAT64 & getCalculateValue() const
bool COptMethodNelderMead::initialize ( )
privatevirtual

Initialize arrays and pointer.

Returns
bool success

Reimplemented from COptMethod.

Definition at line 631 of file COptMethodNelderMead.cpp.

References CProcessReport::addItem(), cleanup(), CCopasiParameter::getValue(), COptMethod::initialize(), mBestValue, mCentroid, mContinue, mCurrent, mhIteration, mIteration, mIterationLimit, CCopasiMethod::mpCallBack, COptMethod::mpOptItem, mScale, mSimplex, mStep, mTolerance, mValue, mVariableSize, CCopasiParameter::Value::pUDOUBLE, CCopasiParameter::Value::pUINT, CMatrix< CType >::resize(), and CVector< CType >::resize().

Referenced by optimise().

632 {
633  cleanup();
634 
635  if (!COptMethod::initialize()) return false;
636 
637  mIterationLimit = * getValue("Iteration Limit").pUINT;
638  mTolerance = * getValue("Tolerance").pUDOUBLE;
639  mScale = * getValue("Scale").pUDOUBLE;
640 
641  mIteration = 0;
642 
643  if (mpCallBack)
644  mhIteration =
645  mpCallBack->addItem("Current Iteration",
646  mIteration,
647  & mIterationLimit);
648 
649  mVariableSize = mpOptItem->size();
650 
654 
657 
658  mBestValue = std::numeric_limits<C_FLOAT64>::infinity();
659 
660  mContinue = true;
661 
662  return true;
663 }
CMatrix< C_FLOAT64 > mSimplex
virtual bool initialize()
Definition: COptMethod.cpp:189
unsigned C_INT32 mIteration
unsigned C_INT32 mIterationLimit
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
CVector< C_FLOAT64 > mStep
CVector< C_FLOAT64 > mValue
CVector< C_FLOAT64 > mCentroid
size_t addItem(const std::string &name, const std::string &value, const std::string *pEndValue=NULL)
const Value & getValue() const
unsigned C_INT32 * pUINT
virtual void resize(size_t rows, size_t cols, const bool &copy=false)
Definition: CMatrix.h:151
const std::vector< COptItem * > * mpOptItem
Definition: COptMethod.h:70
CVector< C_FLOAT64 > mCurrent
CProcessReport * mpCallBack
void COptMethodNelderMead::initObjects ( )
private

Initialize contained objects.

Definition at line 48 of file COptMethodNelderMead.cpp.

References CCopasiContainer::addObjectReference(), mIteration, and CCopasiObject::ValueInt.

Referenced by COptMethodNelderMead().

49 {
51 }
unsigned C_INT32 mIteration
CCopasiObject * addObjectReference(const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
bool COptMethodNelderMead::optimise ( void  )
virtual

Execute the optimization algorithm calling simulation routine when needed. It is noted that this procedure can give feedback of its progress by the callback function set with SetCallback. @ return success;

Reimplemented from COptMethod.

Definition at line 171 of file COptMethodNelderMead.cpp.

References C_FLOAT64, COptItem::checkConstraint(), COutputInterface::DURING, evaluate(), CProcessReport::finishItem(), COptItem::getLowerBoundValue(), COptProblem::getSolutionVariables(), COptItem::getStartValue(), COptItem::getUpperBoundValue(), initialize(), max, mBestValue, mCentroid, mContinue, mCurrent, mEvaluationValue, mhIteration, mIteration, mIterationLimit, CCopasiMethod::mpCallBack, COptMethod::mpOptProblem, COptMethod::mpParentTask, COptMethod::mpSetCalculateVariable, mScale, mSimplex, mStep, mTolerance, mValue, mVariableSize, CCopasiTask::output(), CProcessReport::progressItem(), and COptProblem::setSolution().

172 {
173  if (!initialize())
174  {
175  if (mpCallBack)
177 
178  return false;
179  }
180 
181  // set tolerances for local minima test to zero
182  C_FLOAT64 abstol, reltol;
183  abstol = reltol = 0.0;
184 
185  // test convergence every iteration
186  size_t konvge;
187  konvge = 1;
188 
189  size_t iBest, iWorst;
190 
191  // double zero, half, one, delta;
192  C_FLOAT64 ccoeff, rcoeff, ecoeff;
193 
194  /* ---- reflection, extension and contraction coefficients. ---- */
195  /* parameters from Nelder and Mead */
196  //rcoeff = 1.0;
197  //ccoeff = 0.5;
198  //ecoeff = 2.0;
199 
200  /* Parameters from Parkinson and Hutchinson */
201  rcoeff = 2.0;
202  ccoeff = 0.25;
203  ecoeff = 2.5;
204 
205  C_FLOAT64 z, sum, ylo;
206  C_FLOAT64 curmin, del, x, yhi;
207  C_FLOAT64 small;
208  C_FLOAT64 factor = 0.8;
209 
210  size_t jcount, np1, i, j;
211 
212  bool ok, reflok, extnok, contok, quit, found; /* boolean variables */
213 
214  // initial point is first guess but we have to make sure that we
215  // are within the parameter domain
216  for (i = 0; i < mVariableSize; i++)
217  {
218  const COptItem & OptItem = *(*mpOptItem)[i];
219 
220  switch (OptItem.checkConstraint(OptItem.getStartValue()))
221  {
222  case - 1:
223  mCurrent[i] = *OptItem.getLowerBoundValue();
224  break;
225 
226  case 1:
227  mCurrent[i] = *OptItem.getUpperBoundValue();
228  break;
229 
230  case 0:
231  mCurrent[i] = OptItem.getStartValue();
232  break;
233  }
234 
235  (*(*mpSetCalculateVariable)[i])(mCurrent[i]);
236 
237  // set the magnitude of each parameter
238  mStep[i] = (*OptItem.getUpperBoundValue() - *OptItem.getLowerBoundValue()) / mScale;
239  }
240 
241  evaluate();
242 
243  if (!isnan(mEvaluationValue))
244  {
245  // and store that value
248 
249  // We found a new best value lets report it.
251  }
252 
253  quit = false;
254  found = false;
255 
256  np1 = mVariableSize + 1;
257  del = 1.0;
258 
259 First:
260 
261  /* ---- Construct the initial simplex. ---- */
262  for (i = 0; i < mVariableSize; ++i)
263  mSimplex[i][mVariableSize] = mCurrent[i];
264 
266 
267  for (j = 0; j < mVariableSize && mContinue; ++j)
268  {
269  x = mCurrent[j];
270 
271  // -- move a little in one dimension only --
272  mCurrent[j] += (mStep[j] * del);
273 
274  // Check constraint
275  const COptItem & OptItem = *(*mpOptItem)[j];
276 
277  if (mCurrent[j] > *OptItem.getUpperBoundValue())
278  mCurrent[j] = x - (mStep[j] * del);
279 
280  // Store the simplex corner
281  for (i = 0; i < mVariableSize; ++i)
282  mSimplex[i][j] = mCurrent[i];
283 
284  // Calculate the value for the corner
285  (*(*mpSetCalculateVariable)[j])(mCurrent[j]);
286  mValue[j] = evaluate();
287 
289  {
290  // and store that value
293 
294  // We found a new best value lets report it.
296  }
297 
298  // Reset
299  mCurrent[j] = x;
300  (*(*mpSetCalculateVariable)[j])(mCurrent[j]);
301  }
302 
303  /* ---- Simplex construction complete; now do some work. ---- */
304 
305  while (!found && !quit && mContinue)
306  {
307  /* ---- take some steps ---- */
308 
309  for (jcount = 1; jcount <= konvge; ++jcount)
310  {
311  /* ---- take a single step ---- */
312 
313  /* ---- find highest and lowest y values. yhi (=y[iWorst]) indicates
314  the vertex of the simplex to be replaced. */
315 
316  ylo = mValue[0];
317  yhi = ylo;
318  iBest = 0;
319  iWorst = 0;
320 
321  for (i = 1; i < np1; ++i)
322  {
323  if (mValue[i] < ylo) /* -- find the lowest value of the objective */
324  {
325  ylo = mValue[i];
326  iBest = i;
327  }
328 
329  if (mValue[i] > yhi) /* -- find the highest value of the objective -- */
330  {
331  yhi = mValue[i];
332  iWorst = i;
333  }
334  }
335 
336  /* ---- Calculate mCentroid, the centroid of the simplex vertices
337  excepting that with the y value yhi. (largest objective value) */
338 
339  for (i = 0; i < mVariableSize; ++i)
340  {
341  /* -- calculate the average in each dimension -- */
342  z = 0.0;
343 
344  for (j = 0; j < np1; ++j)
345  z += mSimplex[i][j];
346 
347  z -= mSimplex[i][iWorst];
348  mCentroid[i] = z / mVariableSize;
349  }
350 
351  /* ---- reflection through the centroid. ---- */
352 
353  for (i = 0; i < mVariableSize; ++i)
354  {
355  mCurrent[i] = (1.0 + rcoeff) * mCentroid[i] - rcoeff * mSimplex[i][iWorst];
356  (*(*mpSetCalculateVariable)[i])(mCurrent[i]);
357 
358  // enforce_bounds(&pstar[i], i); /* make sure it is inside */
359  }
360 
361  evaluate();
362  reflok = (mEvaluationValue < ylo); /* -- 1 if we have moved downhill -- */
363 
364  if (reflok) /* then */
365  {
366  ylo = mEvaluationValue;
367 
368  for (i = 0; i < mVariableSize; ++i)
369  mSimplex[i][iWorst] = mCurrent[i];
370 
371  mValue[iWorst] = ylo;
372 
373  // and store that value
375  {
378 
379  // We found a new best value lets report it.
381  }
382 
383  /* ---- successful reflection, so be bold and try extension */
384  for (i = 0; i < mVariableSize; ++i)
385  {
386  mCurrent[i] = ecoeff * mCurrent[i] + (1.0 - ecoeff) * mCentroid[i];
387  (*(*mpSetCalculateVariable)[i])(mCurrent[i]);
388 
389  // enforce_bounds(&p2star[i], i); /* make sure it is inside */
390  }
391 
392  evaluate();
393  extnok = (mEvaluationValue < ylo); /* -- 1 if we continue moved downhill -- */
394 
395  if (extnok)
396  {
397  /* ---- retain extension ---- */
398  ylo = mEvaluationValue;
399 
400  for (i = 0; i < mVariableSize; ++i)
401  mSimplex[i][iWorst] = mCurrent[i];
402 
403  mValue[iWorst] = ylo;
404 
405  // and store that value
407  {
410 
411  // We found a new best value lets report it.
413  }
414  }
415  } /* successful reflection */
416  else /* if reflok then else */
417  {
418  /* ---- reflection has not been successful. ystar is the function
419  value at the extended point. now look at the other points
420  of the simplex ...
421  if there are none > ystar then contract to a point within the simplex
422  if there is one > ystar then reduce the size of the extension
423  if there are many > ystar then retain the reflection as is. */
424 
425  size_t L = 0;
426 
427  for (i = 0; i < np1; ++i)
428  if (mValue[i] > mEvaluationValue)
429  L++;
430 
431  if (L == 1) /* then */
432  {
433  /* ---- reflection was not successful but we can try reducing the
434  extension by contracting on the reflection side of the centroid.
435  Record the reflection for the contraction below. */
436  for (i = 0; i < mVariableSize; ++i)
437  mSimplex[i][iWorst] = mCurrent[i];
438 
439  mValue[iWorst] = mEvaluationValue;
440  }
441 
442  if (L == 0 || L == 1) /* then */
443 
444  {
445  /* L == 0 : there are no other points with higher objectives so
446  try a contraction on the y(iWorst) side of the centroid.
447  i.e. within the simplex.
448  L == 1 : there is one other point with a higher objective so
449  try a contraction on the reflection side of the centroid. */
450  for (i = 0; i < mVariableSize; ++i)
451  {
452  mCurrent[i] = ccoeff * mSimplex[i][iWorst] + (1.0 - ccoeff) * mCentroid[i];
453  (*(*mpSetCalculateVariable)[i])(mCurrent[i]);
454 
455  // may not need to check boundaries since it is contraction
456  // enforce_bounds(&p2star[i], i); /* make sure it is inside */
457  }
458 
459  evaluate();
460  contok = (mEvaluationValue <= mValue[iWorst]); /* -- 1 if we have not gone uphill -- */
461 
462  if (contok) /* then */
463  {
464  /* ---- retain contraction ---- */
465  for (i = 0; i < mVariableSize; ++i)
466  mSimplex[i][iWorst] = mCurrent[i];
467 
468  mValue[iWorst] = mEvaluationValue;
469  }
470  else
471  {
472  /* ---- contract whole simplex about a point within itself
473  but close to the current minimum. ---- */
474  for (j = 0; j < np1; ++j)
475  {
476  for (i = 0; i < mVariableSize; ++i)
477  {
478  mSimplex[i][j] = (mSimplex[i][j] + mSimplex[i][iBest]) * 0.5;
479  mCurrent[i] = mSimplex[i][j];
480  (*(*mpSetCalculateVariable)[i])(mCurrent[i]);
481 
482  //enforce_bounds(&xmin[i], i); /* make sure it is inside */
483  }
484 
485  mValue[j] = evaluate();
486 
488  {
489  /* ---- retain extension ---- */
490  // and store that value
493 
494  // We found a new best value lets report it.
496  }
497  }
498  } /* if (contok) */
499  } /* contraction */
500  else /* if (L == 0) or (L == 1) then else */
501  {
502  /* ---- Retain the first reflection as there are many points in
503  the simplex that have higher objective values than
504  this new point. A change is better than nothing. ---- */
505  for (i = 0; i < mVariableSize; ++i)
506  mSimplex[i][iWorst] = mCurrent[i];
507 
508  mValue[iWorst] = mEvaluationValue;
509  }
510  } /* if Reflok then else .. */
511  } /* ---- procedure TakeAStep ----*/
512 
513  /* are we over the limit for number of function evaluations ? */
514  // quit = (icount > kcount);
515  // are we above the iteration limit?
516  ++mIteration;
517 
518  // signal another iteration
519  if (mpCallBack)
520  mContinue &= mpCallBack->progressItem(mhIteration);
521 
522  quit = (mIteration >= mIterationLimit);
523 
524  if (!quit) /* then */
525  {
526  /* ---- check to see if minimum reached.
527  calculation of the variance must be done in the highest
528  precision available. ---- */
529 
530  /* mean */
531  sum = 0.0;
532  curmin = 0.0;
533 
534  for (i = 0; i < np1; ++i)
535  {
536  sum += mValue[i];
537  curmin += mValue[i] * mValue[i];
538  }
539 
540  sum /= np1;
541  curmin /= np1;
542 
543  /* ---- curmin is the variance of the n+1 Fnelmin values at the
544  vertices. If we haven't reached the minimum to the
545  required accuracy then take a few more steps. */
546  found = (sqrt(curmin - sum * sum) < mTolerance);
547  }
548  } /* while not found and not quit ... */
549 
550  /* **** bail out if necessary **** */
551  if (quit || !mContinue) goto Finish;
552 
553  /* ---- Check around the currently selected point to see if it is a local minimum. */
554  small = fabs(mBestValue) * reltol + abstol;
556 
557  for (i = 0; i < mVariableSize; ++i)
558  (*(*mpSetCalculateVariable)[i])(mCurrent[i]);
559 
560  for (i = 0; i < mVariableSize; ++i)
561  {
562  /* ---- check along each dimension ---- */
563  C_FLOAT64 delta = mStep[i] * 1.0e-03;
564 
565  /* -- check along one direction -- */
566  (*(*mpSetCalculateVariable)[i])(mCurrent[i] + delta);
567  evaluate();
568 
569  if ((mEvaluationValue - mBestValue) < -small)
570  break;
571 
572  /* -- now check the other way -- */
573  (*(*mpSetCalculateVariable)[i])(mCurrent[i] - delta);
574  evaluate();
575 
576  if ((mEvaluationValue - mBestValue) < -small)
577  break;
578 
579  /* -- back to start -- */
580  (*(*mpSetCalculateVariable)[i])(mCurrent[i]);
581  }
582 
583  ok = (i == mVariableSize);
584 
585  /* ---- return on finding a local minimum to the desired accuracy. ---- */
586 
587  if (ok) /* then */
588  {
589  goto Finish;
590  }
591 
592  /* ---- Reduce the size of the simplex and restart the procedure. ---- */
593 
594  found = 0; /* -- we did not find a 1 minimum -- */
595  del = std::max(del * factor, 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon());
596 
597  goto First;
598 
599 Finish: /* end of procedure */
600 
601  if (mpCallBack)
603 
604  return true;
605 }
virtual C_INT32 checkConstraint() const
Definition: COptItem.cpp:401
COptTask * mpParentTask
Definition: COptMethod.h:58
CMatrix< C_FLOAT64 > mSimplex
unsigned C_INT32 mIteration
unsigned C_INT32 mIterationLimit
CVector< C_FLOAT64 > mStep
COptProblem * mpOptProblem
Definition: COptMethod.h:56
virtual void output(const COutputInterface::Activity &activity)
CVector< C_FLOAT64 > mValue
virtual bool progressItem(const size_t &handle)
CVector< C_FLOAT64 > mCentroid
const C_FLOAT64 & evaluate()
const std::vector< UpdateMethod * > * mpSetCalculateVariable
Definition: COptMethod.h:65
const C_FLOAT64 * getLowerBoundValue() const
Definition: COptItem.h:191
const CVector< C_FLOAT64 > & getSolutionVariables() const
virtual bool setSolution(const C_FLOAT64 &value, const CVector< C_FLOAT64 > &variables)
virtual bool finishItem(const size_t &handle)
const C_FLOAT64 & getStartValue() const
Definition: COptItem.cpp:199
#define C_FLOAT64
Definition: copasi.h:92
const C_FLOAT64 * getUpperBoundValue() const
Definition: COptItem.h:198
CVector< C_FLOAT64 > mCurrent
CProcessReport * mpCallBack
#define max(a, b)
Definition: f2c.h:176

Friends And Related Function Documentation

Member Data Documentation

C_FLOAT64 COptMethodNelderMead::mBestValue
private

The best value found so far

Definition at line 149 of file COptMethodNelderMead.h.

Referenced by evaluate(), initialize(), and optimise().

CVector<C_FLOAT64 > COptMethodNelderMead::mCentroid
private

The centroid of the simplex

Definition at line 134 of file COptMethodNelderMead.h.

Referenced by initialize(), and optimise().

bool COptMethodNelderMead::mContinue
private

Flag indicating whether the computation shall continue

Definition at line 159 of file COptMethodNelderMead.h.

Referenced by evaluate(), initialize(), and optimise().

CVector< C_FLOAT64 > COptMethodNelderMead::mCurrent
private

The current solution guess

Definition at line 139 of file COptMethodNelderMead.h.

Referenced by initialize(), and optimise().

C_FLOAT64 COptMethodNelderMead::mEvaluationValue
private

The result of a function evaluation

Definition at line 154 of file COptMethodNelderMead.h.

Referenced by evaluate(), and optimise().

size_t COptMethodNelderMead::mhIteration
private

Handle to the process report item "Current Iteration"

Definition at line 114 of file COptMethodNelderMead.h.

Referenced by initialize(), and optimise().

unsigned C_INT32 COptMethodNelderMead::mIteration
private

The number of iterations

Definition at line 109 of file COptMethodNelderMead.h.

Referenced by initialize(), initObjects(), and optimise().

unsigned C_INT32 COptMethodNelderMead::mIterationLimit
private

The maximum number of iterations

Definition at line 94 of file COptMethodNelderMead.h.

Referenced by initialize(), and optimise().

C_FLOAT64 COptMethodNelderMead::mScale
private

The scale

Definition at line 104 of file COptMethodNelderMead.h.

Referenced by initialize(), and optimise().

CMatrix< C_FLOAT64 > COptMethodNelderMead::mSimplex
private

The simplex

Definition at line 124 of file COptMethodNelderMead.h.

Referenced by initialize(), and optimise().

CVector< C_FLOAT64 > COptMethodNelderMead::mStep
private

The step taken

Definition at line 144 of file COptMethodNelderMead.h.

Referenced by initialize(), and optimise().

C_FLOAT64 COptMethodNelderMead::mTolerance
private

The tolerance

Definition at line 99 of file COptMethodNelderMead.h.

Referenced by initialize(), and optimise().

CVector< C_FLOAT64 > COptMethodNelderMead::mValue
private

Array of values of objective function for each corner of the simplex

Definition at line 129 of file COptMethodNelderMead.h.

Referenced by initialize(), and optimise().

size_t COptMethodNelderMead::mVariableSize
private

number of parameters

Definition at line 119 of file COptMethodNelderMead.h.

Referenced by initialize(), and optimise().


The documentation for this class was generated from the following files: