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

#include <COptMethodPS.h>

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

Public Member Functions

 COptMethodPS (const COptMethodPS &src, const CCopasiContainer *pParent=NULL)
 
virtual bool optimise ()
 
virtual ~COptMethodPS ()
 
- 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

void buildInformants ()
 
virtual bool cleanup ()
 
 COptMethodPS (const CCopasiContainer *pParent=NULL)
 
bool create (const size_t &index)
 
const C_FLOAT64evaluate ()
 
virtual bool initialize ()
 
void initObjects ()
 
bool move (const size_t &index)
 
bool reachedStdDeviation ()
 

Private Attributes

size_t mBestIndex
 
CMatrix< C_FLOAT64mBestPositions
 
CVector< C_FLOAT64mBestValues
 
bool mContinue
 
C_FLOAT64 mEvaluationValue
 
size_t mhIteration
 
CVector< CVector< C_FLOAT64 > > mIndividuals
 
std::vector< std::set< size_t > > mInformants
 
unsigned C_INT32 mIteration
 
unsigned C_INT32 mIterationLimit
 
size_t mNumInformed
 
size_t mNumInformedMin
 
CPermutationmpPermutation
 
CRandommpRandom
 
unsigned C_INT32 mSwarmSize
 
CVector< C_FLOAT64mValues
 
size_t mVariableSize
 
C_FLOAT64 mVariance
 
CMatrix< C_FLOAT64mVelocities
 

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 29 of file COptMethodPS.h.

Constructor & Destructor Documentation

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

Copy Constructor

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

Definition at line 61 of file COptMethodPS.cpp.

References initObjects().

62  :
63  COptMethod(src, pParent),
64  mIterationLimit(0),
65  mSwarmSize(0),
66  mVariance(0.0),
67  mpRandom(NULL),
68  mIteration(0),
70  mVariableSize(0),
71  mIndividuals(),
72  mValues(),
73  mVelocities(),
74  mBestValues(),
76  mpPermutation(NULL),
77  mInformants(),
78  mNumInformedMin(0),
79  mNumInformed(0),
80  mBestIndex(0),
82  mContinue(true)
83 {initObjects();}
unsigned C_INT32 mIteration
Definition: COptMethodPS.h:132
C_FLOAT64 mEvaluationValue
Definition: COptMethodPS.h:197
size_t mNumInformedMin
Definition: COptMethodPS.h:182
size_t mVariableSize
Definition: COptMethodPS.h:142
void initObjects()
#define C_INVALID_INDEX
Definition: copasi.h:222
CMatrix< C_FLOAT64 > mBestPositions
Definition: COptMethodPS.h:167
unsigned C_INT32 mIterationLimit
Definition: COptMethodPS.h:112
CVector< C_FLOAT64 > mValues
Definition: COptMethodPS.h:152
size_t mNumInformed
Definition: COptMethodPS.h:187
CPermutation * mpPermutation
Definition: COptMethodPS.h:172
unsigned C_INT32 mSwarmSize
Definition: COptMethodPS.h:117
size_t mBestIndex
Definition: COptMethodPS.h:192
std::vector< std::set< size_t > > mInformants
Definition: COptMethodPS.h:177
CVector< CVector< C_FLOAT64 > > mIndividuals
Definition: COptMethodPS.h:147
C_FLOAT64 mVariance
Definition: COptMethodPS.h:122
CRandom * mpRandom
Definition: COptMethodPS.h:127
size_t mhIteration
Definition: COptMethodPS.h:137
CMatrix< C_FLOAT64 > mVelocities
Definition: COptMethodPS.h:157
CVector< C_FLOAT64 > mBestValues
Definition: COptMethodPS.h:162
COptMethodPS::~COptMethodPS ( )
virtual

Destructor

Definition at line 85 of file COptMethodPS.cpp.

References cleanup().

86 {cleanup();}
virtual bool cleanup()
COptMethodPS::COptMethodPS ( const CCopasiContainer pParent = NULL)
private

Default Constructor

Parameters
constCCopasiContainer * pParent (default: NULL)

Definition at line 30 of file COptMethodPS.cpp.

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

30  :
32  mIterationLimit(0),
33  mSwarmSize(0),
34  mVariance(0.0),
35  mpRandom(NULL),
36  mIteration(0),
38  mVariableSize(0),
39  mIndividuals(),
40  mValues(),
41  mVelocities(),
42  mBestValues(),
44  mpPermutation(NULL),
45  mInformants(),
46  mNumInformedMin(0),
47  mNumInformed(0),
48  mBestIndex(0),
50  mContinue(true)
51 {
52  addParameter("Iteration Limit", CCopasiParameter::UINT, (unsigned C_INT32) 2000);
53  addParameter("Swarm Size", CCopasiParameter::UINT, (unsigned C_INT32) 50);
54  addParameter("Std. Deviation", CCopasiParameter::UDOUBLE, (C_FLOAT64) 1.0e-6);
55  addParameter("Random Number Generator", CCopasiParameter::UINT, (unsigned C_INT32) CRandom::mt19937);
56  addParameter("Seed", CCopasiParameter::UINT, (unsigned C_INT32) 0);
57 
58  initObjects();
59 }
unsigned C_INT32 mIteration
Definition: COptMethodPS.h:132
C_FLOAT64 mEvaluationValue
Definition: COptMethodPS.h:197
size_t mNumInformedMin
Definition: COptMethodPS.h:182
size_t mVariableSize
Definition: COptMethodPS.h:142
void initObjects()
#define C_INVALID_INDEX
Definition: copasi.h:222
#define C_INT32
Definition: copasi.h:90
CMatrix< C_FLOAT64 > mBestPositions
Definition: COptMethodPS.h:167
unsigned C_INT32 mIterationLimit
Definition: COptMethodPS.h:112
CVector< C_FLOAT64 > mValues
Definition: COptMethodPS.h:152
size_t mNumInformed
Definition: COptMethodPS.h:187
CPermutation * mpPermutation
Definition: COptMethodPS.h:172
unsigned C_INT32 mSwarmSize
Definition: COptMethodPS.h:117
size_t mBestIndex
Definition: COptMethodPS.h:192
#define C_FLOAT64
Definition: copasi.h:92
std::vector< std::set< size_t > > mInformants
Definition: COptMethodPS.h:177
CVector< CVector< C_FLOAT64 > > mIndividuals
Definition: COptMethodPS.h:147
C_FLOAT64 mVariance
Definition: COptMethodPS.h:122
bool addParameter(const CCopasiParameter &parameter)
CRandom * mpRandom
Definition: COptMethodPS.h:127
size_t mhIteration
Definition: COptMethodPS.h:137
CMatrix< C_FLOAT64 > mVelocities
Definition: COptMethodPS.h:157
CVector< C_FLOAT64 > mBestValues
Definition: COptMethodPS.h:162

Member Function Documentation

void COptMethodPS::buildInformants ( )
private

create the informant for each individual

Definition at line 389 of file COptMethodPS.cpp.

References mInformants, mNumInformed, mpPermutation, mSwarmSize, CPermutation::next(), CPermutation::pick(), and CPermutation::shuffle().

Referenced by optimise().

390 {
391  if (mNumInformed < mSwarmSize)
392  mNumInformed++;
393  else
394  return;
395 
396  mInformants.clear();
397  mInformants.resize(mSwarmSize);
399 
400  size_t i, j;
401  size_t Informant;
402 
403  for (i = 0; i < mSwarmSize; i++)
404  {
405  mInformants[i].insert(i);
406 
407  Informant = mpPermutation->pick();
408 
409  for (j = 1; j < mNumInformed; j++, Informant = mpPermutation->next())
410  {
411  if (Informant == i)
412  {
413  Informant = mpPermutation->next();
414  }
415 
416  mInformants[Informant].insert(i);
417  }
418  }
419 
420  return;
421 }
const size_t & next()
const size_t & pick()
size_t mNumInformed
Definition: COptMethodPS.h:187
void shuffle(const size_t &swaps=C_INVALID_INDEX)
CPermutation * mpPermutation
Definition: COptMethodPS.h:172
unsigned C_INT32 mSwarmSize
Definition: COptMethodPS.h:117
std::vector< std::set< size_t > > mInformants
Definition: COptMethodPS.h:177
bool COptMethodPS::cleanup ( )
privatevirtual

Cleanup arrays and pointers.

Returns
bool success

Reimplemented from COptMethod.

Definition at line 381 of file COptMethodPS.cpp.

References mpPermutation, mpRandom, and pdelete.

Referenced by initialize(), optimise(), and ~COptMethodPS().

382 {
383  pdelete(mpRandom);
385 
386  return true;
387 }
#define pdelete(p)
Definition: copasi.h:215
CPermutation * mpPermutation
Definition: COptMethodPS.h:172
CRandom * mpRandom
Definition: COptMethodPS.h:127
bool COptMethodPS::create ( const size_t &  index)
private

Create the indexed individual in the swarm

Parameters
constsize_t & index
Returns
bool continue

Definition at line 194 of file COptMethodPS.cpp.

References CVectorCore< CType >::array(), C_FLOAT64, COptItem::checkConstraint(), COutputInterface::DURING, evaluate(), COptItem::getLowerBoundValue(), CRandom::getRandomCC(), CRandom::getRandomNormal(), COptItem::getUpperBoundValue(), max, mBestIndex, mBestPositions, mBestValues, mContinue, min, mIndividuals, COptMethod::mpOptItem, COptMethod::mpOptProblem, COptMethod::mpParentTask, mpRandom, COptMethod::mpSetCalculateVariable, mValues, mVariableSize, mVelocities, CCopasiTask::output(), and COptProblem::setSolution().

Referenced by optimise().

195 {
196  C_FLOAT64 * pIndividual = mIndividuals[index].array();
197  C_FLOAT64 * pEnd = pIndividual + mVariableSize;
198  C_FLOAT64 * pVelocity = mVelocities[index];
199  C_FLOAT64 * pBestPosition = mBestPositions[index];
200  std::vector< COptItem * >::const_iterator itOptItem = mpOptItem->begin();
201  std::vector< UpdateMethod * >::const_iterator itSetCalculateVariable = mpSetCalculateVariable->begin();
202 
203  C_FLOAT64 mn, mx, la;
204 
205  for (; pIndividual != pEnd;
206  ++pIndividual, ++pVelocity, ++pBestPosition, ++itOptItem, ++itSetCalculateVariable)
207  {
208  COptItem & OptItem = **itOptItem;
209 
210  // calculate lower and upper bounds
211  mn = *OptItem.getLowerBoundValue();
212  mx = *OptItem.getUpperBoundValue();
213 
214  try
215  {
216  // First determine the location of the intervall
217  // Secondly determine whether to distribute the parameter linearly or not
218  // depending on the location and act uppon it.
219  if (0.0 <= mn) // the interval [mn, mx) is in [0, inf)
220  {
221  la = log10(mx) - log10(std::max(mn, std::numeric_limits< C_FLOAT64 >::min()));
222 
223  if (la < 1.8 || !(mn > 0.0)) // linear
224  {
225  *pIndividual = mn + mpRandom->getRandomCC() * (mx - mn);
226  *pVelocity = mn + mpRandom->getRandomCC() * (mx - mn) - *pIndividual;
227  }
228  else
229  {
230  *pIndividual = pow(10.0, log10(std::max(mn, std::numeric_limits< C_FLOAT64 >::min())) + la * mpRandom->getRandomCC());
231  *pVelocity =
232  pow(10.0, log10(std::max(mn, std::numeric_limits< C_FLOAT64 >::min())) + la * mpRandom->getRandomCC()) - *pIndividual;
233  }
234  }
235  else if (mx > 0) // 0 is in the interval (mn, mx)
236  {
237  la = log10(mx) + log10(-mn);
238 
239  if (la < 3.6) // linear
240  {
241  *pIndividual = mn + mpRandom->getRandomCC() * (mx - mn);
242  *pVelocity = mn + mpRandom->getRandomCC() * (mx - mn) - *pIndividual;
243  }
244  else
245  {
246  C_FLOAT64 mean = (mx + mn) * 0.5;
247  C_FLOAT64 sigma = std::min(std::numeric_limits< C_FLOAT64 >::max(), mx - mn) / 3.0;
248 
249  do
250  {
251  *pIndividual = mpRandom->getRandomNormal(mean, sigma);
252  }
253  while ((*pIndividual < mn) || (*pIndividual > mx));
254 
255  *pVelocity = mpRandom->getRandomNormal(mean, sigma) - *pIndividual;
256  }
257  }
258  else // the interval (mn, mx] is in (-inf, 0]
259  {
260  // Switch lower and upper bound and change sign, i.e.,
261  // we can treat it similarly as location 1:
262  mx = - *OptItem.getLowerBoundValue();
263  mn = - *OptItem.getUpperBoundValue();
264 
265  la = log10(mx) - log10(std::max(mn, std::numeric_limits< C_FLOAT64 >::min()));
266 
267  if (la < 1.8 || !(mn > 0.0)) // linear
268  {
269  *pIndividual = - (mn + mpRandom->getRandomCC() * (mx - mn));
270  *pVelocity = - (mn + mpRandom->getRandomCC() * (mx - mn)) - *pIndividual;
271  }
272  else
273  {
274  *pIndividual = - pow(10.0, log10(std::max(mn, std::numeric_limits< C_FLOAT64 >::min())) + la * mpRandom->getRandomCC());
275  *pVelocity =
276  - pow(10.0, log10(std::max(mn, std::numeric_limits< C_FLOAT64 >::min())) + la * mpRandom->getRandomCC()) - *pIndividual;
277  }
278  }
279  }
280 
281  catch (...)
282  {
283  *pIndividual = (mx + mn) * 0.5;
284  *pVelocity = 0.0;
285  }
286 
287  // force it to be within the bounds
288  switch (OptItem.checkConstraint(*pIndividual))
289  {
290  case - 1:
291  *pIndividual = *OptItem.getLowerBoundValue();
292  break;
293 
294  case 1:
295  *pIndividual = *OptItem.getUpperBoundValue();
296  break;
297  }
298 
299  *pBestPosition = *pIndividual;
300 
301  // We need to set the value here so that further checks take
302  // account of the value.
303  (**itSetCalculateVariable)(*pIndividual);
304  }
305 
306  // calculate its fitness
307  mBestValues[index] = mValues[index] = evaluate();
308 
309  if (mBestValues[index] < mBestValues[mBestIndex])
310  {
311  // and store that value
312  mBestIndex = index;
314 
315  // We found a new best value lets report it.
317  }
318 
319  return mContinue;
320 }
virtual C_INT32 checkConstraint() const
Definition: COptItem.cpp:401
COptTask * mpParentTask
Definition: COptMethod.h:58
const C_FLOAT64 & evaluate()
size_t mVariableSize
Definition: COptMethodPS.h:142
virtual C_FLOAT64 getRandomNormal(const C_FLOAT64 &mean, const C_FLOAT64 &sd)
Definition: CRandom.cpp:292
COptProblem * mpOptProblem
Definition: COptMethod.h:56
virtual void output(const COutputInterface::Activity &activity)
CMatrix< C_FLOAT64 > mBestPositions
Definition: COptMethodPS.h:167
virtual C_FLOAT64 getRandomCC()
Definition: CRandom.cpp:235
CVector< C_FLOAT64 > mValues
Definition: COptMethodPS.h:152
const std::vector< UpdateMethod * > * mpSetCalculateVariable
Definition: COptMethod.h:65
const C_FLOAT64 * getLowerBoundValue() const
Definition: COptItem.h:191
virtual bool setSolution(const C_FLOAT64 &value, const CVector< C_FLOAT64 > &variables)
const std::vector< COptItem * > * mpOptItem
Definition: COptMethod.h:70
size_t mBestIndex
Definition: COptMethodPS.h:192
#define C_FLOAT64
Definition: copasi.h:92
CVector< CVector< C_FLOAT64 > > mIndividuals
Definition: COptMethodPS.h:147
CType * array()
Definition: CVector.h:139
const C_FLOAT64 * getUpperBoundValue() const
Definition: COptItem.h:198
CRandom * mpRandom
Definition: COptMethodPS.h:127
CMatrix< C_FLOAT64 > mVelocities
Definition: COptMethodPS.h:157
#define min(a, b)
Definition: f2c.h:175
CVector< C_FLOAT64 > mBestValues
Definition: COptMethodPS.h:162
#define max(a, b)
Definition: f2c.h:176
const C_FLOAT64 & COptMethodPS::evaluate ( )
private

Evaluate the fitness of one individual

Returns
const C_FLOAT64 value

Definition at line 89 of file COptMethodPS.cpp.

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

Referenced by create(), move(), and optimise().

90 {
91  // We do not need to check whether the parametric constraints are fulfilled
92  // since the parameters are created within the bounds.
93 
94  // evaluate the fitness
96 
97  // check wheter the functional constraints are fulfilled
99  mEvaluationValue = std::numeric_limits<C_FLOAT64>::infinity();
100  else
102 
103  return mEvaluationValue;
104 }
C_FLOAT64 mEvaluationValue
Definition: COptMethodPS.h:197
COptProblem * mpOptProblem
Definition: COptMethod.h:56
virtual bool calculate()
virtual bool checkFunctionalConstraints()
const C_FLOAT64 & getCalculateValue() const
bool COptMethodPS::initialize ( )
privatevirtual

Initialize arrays and pointer.

Returns
bool success

Reimplemented from COptMethod.

Definition at line 327 of file COptMethodPS.cpp.

References CProcessReport::addItem(), cleanup(), CRandom::createGenerator(), CCopasiParameter::getValue(), COptMethod::initialize(), mBestPositions, mBestValues, mContinue, mhIteration, mIndividuals, mIteration, mIterationLimit, mNumInformed, mNumInformedMin, CCopasiMethod::mpCallBack, COptMethod::mpOptItem, mpPermutation, mpRandom, mSwarmSize, mValues, mVariableSize, mVariance, mVelocities, CCopasiParameter::Value::pUDOUBLE, CCopasiParameter::Value::pUINT, CMatrix< CType >::resize(), CVector< CType >::resize(), and CCopasiParameterGroup::setValue().

Referenced by optimise().

328 {
329  cleanup();
330 
331  if (!COptMethod::initialize()) return false;
332 
333  mIterationLimit = * getValue("Iteration Limit").pUINT;
334  mIteration = 0;
335 
336  if (mpCallBack)
337  mhIteration =
338  mpCallBack->addItem("Iteration Limit",
339  mIteration,
340  & mIterationLimit);
341 
342  mSwarmSize = * getValue("Swarm Size").pUINT;
343 
344  if (mSwarmSize < 5)
345  {
346  mSwarmSize = 5;
347  setValue("Swarm Size", mSwarmSize);
348  }
349 
350  mVariance = *getValue("Std. Deviation").pUDOUBLE;
351  mVariance *= mVariance;
352 
353  mpRandom =
354  CRandom::createGenerator(* (CRandom::Type *) getValue("Random Number Generator").pUINT,
355  * getValue("Seed").pUINT);
356 
357  mVariableSize = mpOptItem->size();
358 
360 
361  size_t i;
362 
363  for (i = 0; i < mSwarmSize; i++)
364  mIndividuals[i].resize(mVariableSize);
365 
366  mValues.resize(mSwarmSize);
367  mVelocities.resize(mSwarmSize, mVariableSize);
368  mBestValues.resize(mSwarmSize);
369  mBestPositions.resize(mSwarmSize, mVariableSize);
370 
371  mNumInformedMin = std::max<size_t>(mSwarmSize / 10, 5) - 1;
373 
374  mpPermutation = new CPermutation(mpRandom, mSwarmSize);
375 
376  mContinue = true;
377 
378  return mContinue;
379 }
unsigned C_INT32 mIteration
Definition: COptMethodPS.h:132
size_t mNumInformedMin
Definition: COptMethodPS.h:182
virtual bool initialize()
Definition: COptMethod.cpp:189
size_t mVariableSize
Definition: COptMethodPS.h:142
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
CMatrix< C_FLOAT64 > mBestPositions
Definition: COptMethodPS.h:167
unsigned C_INT32 mIterationLimit
Definition: COptMethodPS.h:112
static CRandom * createGenerator(CRandom::Type type=CRandom::mt19937, unsigned C_INT32 seed=0)
Definition: CRandom.cpp:49
CVector< C_FLOAT64 > mValues
Definition: COptMethodPS.h:152
size_t addItem(const std::string &name, const std::string &value, const std::string *pEndValue=NULL)
size_t mNumInformed
Definition: COptMethodPS.h:187
const Value & getValue() const
bool setValue(const std::string &name, const CType &value)
unsigned C_INT32 * pUINT
CPermutation * mpPermutation
Definition: COptMethodPS.h:172
virtual void resize(size_t rows, size_t cols, const bool &copy=false)
Definition: CMatrix.h:151
unsigned C_INT32 mSwarmSize
Definition: COptMethodPS.h:117
const std::vector< COptItem * > * mpOptItem
Definition: COptMethod.h:70
CVector< CVector< C_FLOAT64 > > mIndividuals
Definition: COptMethodPS.h:147
C_FLOAT64 mVariance
Definition: COptMethodPS.h:122
CRandom * mpRandom
Definition: COptMethodPS.h:127
size_t mhIteration
Definition: COptMethodPS.h:137
CMatrix< C_FLOAT64 > mVelocities
Definition: COptMethodPS.h:157
virtual bool cleanup()
CProcessReport * mpCallBack
CVector< C_FLOAT64 > mBestValues
Definition: COptMethodPS.h:162
void COptMethodPS::initObjects ( )
private

Initialize contained objects.

Definition at line 322 of file COptMethodPS.cpp.

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

Referenced by COptMethodPS().

323 {
325 }
unsigned C_INT32 mIteration
Definition: COptMethodPS.h:132
CCopasiObject * addObjectReference(const std::string &name, CType &reference, const unsigned C_INT32 &flag=0)
bool COptMethodPS::move ( const size_t &  index)
private

Move the indexed individual in the swarm

Parameters
constsize_t & index
Returns
bool continue

Definition at line 107 of file COptMethodPS.cpp.

References CVectorCore< CType >::array(), C_FLOAT64, COptItem::checkConstraint(), COutputInterface::DURING, evaluate(), COptItem::getLowerBoundValue(), CRandom::getRandomCC(), COptItem::getUpperBoundValue(), mBestIndex, mBestPositions, mBestValues, mContinue, mEvaluationValue, mIndividuals, mInformants, mNumInformed, mNumInformedMin, COptMethod::mpOptItem, COptMethod::mpOptProblem, COptMethod::mpParentTask, mpRandom, COptMethod::mpSetCalculateVariable, mValues, mVariableSize, mVelocities, CCopasiTask::output(), and COptProblem::setSolution().

Referenced by optimise().

108 {
109  const C_FLOAT64 w = 1 / (2 * log(2.0));
110  const C_FLOAT64 c = 0.5 + log(2.0);
111 
112  bool Improved = false;
113 
114  C_FLOAT64 * pIndividual = mIndividuals[index].array();
115  C_FLOAT64 * pEnd = pIndividual + mVariableSize;
116  C_FLOAT64 * pVelocity = mVelocities[index];
117  C_FLOAT64 * pBestPosition = mBestPositions[index];
118  std::vector< COptItem * >::const_iterator itOptItem = mpOptItem->begin();
119  std::vector< UpdateMethod * >::const_iterator itSetCalculateVariable = mpSetCalculateVariable->begin();
120 
121  C_FLOAT64 * pBestInformantPosition = mBestPositions[index];
122  C_FLOAT64 BestInformantValue = mBestValues[index];
123 
124  std::set< size_t >::const_iterator itInformant = mInformants[index].begin();
125  std::set< size_t >::const_iterator endInformant = mInformants[index].end();
126 
127  size_t i = mNumInformed + mNumInformedMin;
128 
129  for (; i && itInformant != endInformant; --i, ++itInformant)
130  if (mBestValues[*itInformant] < BestInformantValue)
131  {
132  BestInformantValue = mBestValues[*itInformant];
133  pBestInformantPosition = mBestPositions[*itInformant];
134  }
135 
136  for (; pIndividual != pEnd;
137  ++pIndividual, ++pVelocity, ++pBestPosition, ++itOptItem, ++itSetCalculateVariable, ++pBestInformantPosition)
138  {
139  *pVelocity *= w;
140  *pVelocity += c * mpRandom->getRandomCC() * (*pBestPosition - *pIndividual);
141  *pVelocity += c * mpRandom->getRandomCC() * (*pBestInformantPosition - *pIndividual);
142 
143  *pIndividual += *pVelocity;
144 
145  COptItem & OptItem = **itOptItem;
146 
147  // force it to be within the bounds
148  switch (OptItem.checkConstraint(*pIndividual))
149  {
150  case - 1:
151  *pIndividual = *OptItem.getLowerBoundValue();
152  *pVelocity = 0.0;
153  break;
154 
155  case 1:
156  *pIndividual = *OptItem.getUpperBoundValue();
157  *pVelocity = 0.0;
158  break;
159  }
160 
161  // We need to set the value here so that further checks take
162  // account of the value.
163  (**itSetCalculateVariable)(*pIndividual);
164  }
165 
166  // calculate its fitness
167  mValues[index] = evaluate();
168 
169  // Check if we improved individually
170  if (mEvaluationValue < mBestValues[index])
171  {
172  Improved = true;
173 
174  // Save the individually best value;
175  mBestValues[index] = mEvaluationValue;
176  memcpy(mBestPositions[index], mIndividuals[index].array(), sizeof(C_FLOAT64) * mVariableSize);
177 
178  // Check if we improved globally
180  {
181  // and store that value
182  mBestIndex = index;
184 
185  // We found a new best value lets report it.
187  }
188  }
189 
190  return Improved;
191 }
virtual C_INT32 checkConstraint() const
Definition: COptItem.cpp:401
COptTask * mpParentTask
Definition: COptMethod.h:58
const C_FLOAT64 & evaluate()
C_FLOAT64 mEvaluationValue
Definition: COptMethodPS.h:197
size_t mNumInformedMin
Definition: COptMethodPS.h:182
size_t mVariableSize
Definition: COptMethodPS.h:142
COptProblem * mpOptProblem
Definition: COptMethod.h:56
virtual void output(const COutputInterface::Activity &activity)
CMatrix< C_FLOAT64 > mBestPositions
Definition: COptMethodPS.h:167
virtual C_FLOAT64 getRandomCC()
Definition: CRandom.cpp:235
CVector< C_FLOAT64 > mValues
Definition: COptMethodPS.h:152
size_t mNumInformed
Definition: COptMethodPS.h:187
const std::vector< UpdateMethod * > * mpSetCalculateVariable
Definition: COptMethod.h:65
const C_FLOAT64 * getLowerBoundValue() const
Definition: COptItem.h:191
virtual bool setSolution(const C_FLOAT64 &value, const CVector< C_FLOAT64 > &variables)
const std::vector< COptItem * > * mpOptItem
Definition: COptMethod.h:70
size_t mBestIndex
Definition: COptMethodPS.h:192
#define C_FLOAT64
Definition: copasi.h:92
std::vector< std::set< size_t > > mInformants
Definition: COptMethodPS.h:177
CVector< CVector< C_FLOAT64 > > mIndividuals
Definition: COptMethodPS.h:147
CType * array()
Definition: CVector.h:139
const C_FLOAT64 * getUpperBoundValue() const
Definition: COptItem.h:198
CRandom * mpRandom
Definition: COptMethodPS.h:127
CMatrix< C_FLOAT64 > mVelocities
Definition: COptMethodPS.h:157
CVector< C_FLOAT64 > mBestValues
Definition: COptMethodPS.h:162
bool COptMethodPS::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 495 of file COptMethodPS.cpp.

References CVectorCore< CType >::array(), buildInformants(), C_FLOAT64, COptItem::checkConstraint(), cleanup(), create(), COutputInterface::DURING, evaluate(), CProcessReport::finishItem(), COptItem::getLowerBoundValue(), COptItem::getStartValue(), COptItem::getUpperBoundValue(), initialize(), mBestIndex, mBestPositions, mBestValues, mContinue, mhIteration, mIndividuals, mIteration, mIterationLimit, move(), CCopasiMethod::mpCallBack, COptMethod::mpOptItem, COptMethod::mpOptProblem, COptMethod::mpParentTask, COptMethod::mpSetCalculateVariable, mSwarmSize, mValues, mVariableSize, mVelocities, CCopasiTask::output(), CProcessReport::progressItem(), reachedStdDeviation(), and COptProblem::setSolution().

496 {
497  size_t i;
498 
499  if (!initialize())
500  {
501  if (mpCallBack)
503 
504  return false;
505  }
506 
507  C_FLOAT64 * pIndividual = mIndividuals[0].array();
508  C_FLOAT64 * pEnd = pIndividual + mVariableSize;
509  C_FLOAT64 * pVelocity = mVelocities[0];
510  C_FLOAT64 * pBestPosition = mBestPositions[0];
511  std::vector< COptItem * >::const_iterator itOptItem = mpOptItem->begin();
512  std::vector< UpdateMethod * >::const_iterator itSetCalculateVariable = mpSetCalculateVariable->begin();
513 
514  // initialise the population
515  // first individual is the initial guess
516  for (; pIndividual != pEnd;
517  ++pIndividual, ++pVelocity, ++pBestPosition, ++itOptItem, ++itSetCalculateVariable)
518  {
519  COptItem & OptItem = **itOptItem;
520 
521  *pIndividual = OptItem.getStartValue();
522 
523  // force it to be within the bounds
524  switch (OptItem.checkConstraint(*pIndividual))
525  {
526  case - 1:
527  *pIndividual = *OptItem.getLowerBoundValue();
528  break;
529 
530  case 1:
531  *pIndividual = *OptItem.getUpperBoundValue();
532  break;
533  }
534 
535  *pBestPosition = *pIndividual;
536  *pVelocity = 0.0;
537 
538  // We need to set the value here so that further checks take
539  // account of the value.
540  (**itSetCalculateVariable)(*pIndividual);
541  }
542 
543  // calculate its fitness
544  mBestValues[0] = mValues[0] = evaluate();
545 
546  // and store that value
547  mBestIndex = 0;
549 
550  // We found a new best value lets report it.
552 
553  // the others are random
554  for (i = 1; i < mSwarmSize && mContinue; i++)
555  create(i);
556 
557  // create the informant list
558  buildInformants();
559 
560  bool Improved;
561 
563  {
564  Improved = false;
565 
566  for (i = 0; i < mSwarmSize && mContinue; i++)
567  Improved |= move(i);
568 
569  if (!Improved)
570  buildInformants();
571  else if (reachedStdDeviation())
572  break;
573 
574  if (mpCallBack)
575  mContinue &= mpCallBack->progressItem(mhIteration);
576  }
577 
578  if (mpCallBack)
580 
581  cleanup();
582 
583  return true;
584 }
virtual C_INT32 checkConstraint() const
Definition: COptItem.cpp:401
unsigned C_INT32 mIteration
Definition: COptMethodPS.h:132
COptTask * mpParentTask
Definition: COptMethod.h:58
const C_FLOAT64 & evaluate()
bool move(const size_t &index)
size_t mVariableSize
Definition: COptMethodPS.h:142
COptProblem * mpOptProblem
Definition: COptMethod.h:56
virtual void output(const COutputInterface::Activity &activity)
bool create(const size_t &index)
CMatrix< C_FLOAT64 > mBestPositions
Definition: COptMethodPS.h:167
virtual bool progressItem(const size_t &handle)
unsigned C_INT32 mIterationLimit
Definition: COptMethodPS.h:112
CVector< C_FLOAT64 > mValues
Definition: COptMethodPS.h:152
const std::vector< UpdateMethod * > * mpSetCalculateVariable
Definition: COptMethod.h:65
const C_FLOAT64 * getLowerBoundValue() const
Definition: COptItem.h:191
virtual bool setSolution(const C_FLOAT64 &value, const CVector< C_FLOAT64 > &variables)
void buildInformants()
virtual bool finishItem(const size_t &handle)
bool reachedStdDeviation()
const C_FLOAT64 & getStartValue() const
Definition: COptItem.cpp:199
unsigned C_INT32 mSwarmSize
Definition: COptMethodPS.h:117
const std::vector< COptItem * > * mpOptItem
Definition: COptMethod.h:70
size_t mBestIndex
Definition: COptMethodPS.h:192
#define C_FLOAT64
Definition: copasi.h:92
CVector< CVector< C_FLOAT64 > > mIndividuals
Definition: COptMethodPS.h:147
CType * array()
Definition: CVector.h:139
const C_FLOAT64 * getUpperBoundValue() const
Definition: COptItem.h:198
size_t mhIteration
Definition: COptMethodPS.h:137
CMatrix< C_FLOAT64 > mVelocities
Definition: COptMethodPS.h:157
virtual bool cleanup()
CProcessReport * mpCallBack
virtual bool initialize()
CVector< C_FLOAT64 > mBestValues
Definition: COptMethodPS.h:162
bool COptMethodPS::reachedStdDeviation ( )
private

Definition at line 423 of file COptMethodPS.cpp.

References CVectorCore< CType >::array(), C_FLOAT64, mIndividuals, mNumInformed, mNumInformedMin, mSwarmSize, mValues, mVariableSize, and mVariance.

Referenced by optimise().

424 {
425  if (mNumInformed > mNumInformedMin + 1)
426  mNumInformed--;
427 
428  // Check whether the swarm has settled
429  C_FLOAT64 * pValue = mValues.array();
430  C_FLOAT64 * pEnd = pValue + mSwarmSize;
431 
432  C_FLOAT64 Delta;
433 
434  C_FLOAT64 Mean = 0.0;
435  C_FLOAT64 Variance = 0.0;
436  size_t N = 0;
437 
438  for (; pValue != pEnd; ++pValue)
439  {
440  // We need to deal with infinity values since they indicate failure
441  if (*pValue == std::numeric_limits<C_FLOAT64>::infinity())
442  return false;
443 
444  Delta = *pValue - Mean;
445  Mean += Delta / ++N;
446  // This uses the new mean, i.e., not Delta * Delta
447  Variance += Delta * (*pValue - Mean);
448  }
449 
450  Variance /= (N - 1);
451 
452  if (Variance > mVariance)
453  return false;
454 
455  // The variance of the function value is smaller than required. We now
456  // Check the variance of the flock positions.
457  CVector< C_FLOAT64 > FirstMoments(mVariableSize);
458  CVector< C_FLOAT64 > SecondMoments(mVariableSize);
459  FirstMoments = 0.0;
460  SecondMoments = 0.0;
461 
462  CVector< C_FLOAT64 > * pIndividual = mIndividuals.array();
463  CVector< C_FLOAT64 > * pIndividualEnd = pIndividual + mSwarmSize;
464 
465  C_FLOAT64 * pFirstMoment;
466  C_FLOAT64 * pSecondMoment;
467  pEnd = FirstMoments.array() + mVariableSize;
468 
469  for (; pIndividual != pIndividualEnd; ++pIndividual)
470  {
471  pFirstMoment = FirstMoments.array();
472  pSecondMoment = SecondMoments.array();
473  pValue = pIndividual->array();
474 
475  for (; pFirstMoment != pEnd; ++pFirstMoment, ++pSecondMoment, ++pValue)
476  {
477  *pFirstMoment += *pValue;
478  *pSecondMoment += *pValue * *pValue;
479  }
480  }
481 
482  pFirstMoment = FirstMoments.array();
483  pSecondMoment = SecondMoments.array();
484 
485  for (; pFirstMoment != pEnd; ++pFirstMoment, ++pSecondMoment)
486  {
487  Variance = (*pSecondMoment - *pFirstMoment * *pFirstMoment / mSwarmSize) / (mSwarmSize - 1);
488 
489  if (Variance > mVariance) return false;
490  }
491 
492  return true;
493 }
size_t mNumInformedMin
Definition: COptMethodPS.h:182
size_t mVariableSize
Definition: COptMethodPS.h:142
CVector< C_FLOAT64 > mValues
Definition: COptMethodPS.h:152
size_t mNumInformed
Definition: COptMethodPS.h:187
unsigned C_INT32 mSwarmSize
Definition: COptMethodPS.h:117
#define C_FLOAT64
Definition: copasi.h:92
CVector< CVector< C_FLOAT64 > > mIndividuals
Definition: COptMethodPS.h:147
CType * array()
Definition: CVector.h:139
C_FLOAT64 mVariance
Definition: COptMethodPS.h:122

Friends And Related Function Documentation

Member Data Documentation

size_t COptMethodPS::mBestIndex
private

Index of the best solution found so far.

Definition at line 192 of file COptMethodPS.h.

Referenced by create(), move(), and optimise().

CMatrix< C_FLOAT64 > COptMethodPS::mBestPositions
private

Matrix of best positions for each individual

Definition at line 167 of file COptMethodPS.h.

Referenced by create(), initialize(), move(), and optimise().

CVector< C_FLOAT64 > COptMethodPS::mBestValues
private

Vector of individual best values.

Definition at line 162 of file COptMethodPS.h.

Referenced by create(), initialize(), move(), and optimise().

bool COptMethodPS::mContinue
private

Indicates whether calculation shall continue

Definition at line 202 of file COptMethodPS.h.

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

C_FLOAT64 COptMethodPS::mEvaluationValue
private

The value of the last evaluation.

Definition at line 197 of file COptMethodPS.h.

Referenced by evaluate(), and move().

size_t COptMethodPS::mhIteration
private

Handle to the process report item "Current Iteration"

Definition at line 137 of file COptMethodPS.h.

Referenced by initialize(), and optimise().

CVector< CVector< C_FLOAT64 > > COptMethodPS::mIndividuals
private

Matrix of individuals with candidate values for the parameters

Definition at line 147 of file COptMethodPS.h.

Referenced by create(), initialize(), move(), optimise(), and reachedStdDeviation().

std::vector< std::set< size_t > > COptMethodPS::mInformants
private

Vector containing the set of informants for each individual.

Definition at line 177 of file COptMethodPS.h.

Referenced by buildInformants(), and move().

unsigned C_INT32 COptMethodPS::mIteration
private

current iterations

Definition at line 132 of file COptMethodPS.h.

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

unsigned C_INT32 COptMethodPS::mIterationLimit
private

maximal number of iterations

Definition at line 112 of file COptMethodPS.h.

Referenced by initialize(), and optimise().

size_t COptMethodPS::mNumInformed
private

The number of individual informed by each individual

Definition at line 187 of file COptMethodPS.h.

Referenced by buildInformants(), initialize(), move(), and reachedStdDeviation().

size_t COptMethodPS::mNumInformedMin
private

The minimal number of individuals informed by each individual

Definition at line 182 of file COptMethodPS.h.

Referenced by initialize(), move(), and reachedStdDeviation().

CPermutation* COptMethodPS::mpPermutation
private

A permutation of integers used to create the informants;

Definition at line 172 of file COptMethodPS.h.

Referenced by buildInformants(), cleanup(), and initialize().

CRandom* COptMethodPS::mpRandom
private

a pointer to the random number generator.

Definition at line 127 of file COptMethodPS.h.

Referenced by cleanup(), create(), initialize(), and move().

unsigned C_INT32 COptMethodPS::mSwarmSize
private

size of the population

Definition at line 117 of file COptMethodPS.h.

Referenced by buildInformants(), initialize(), optimise(), and reachedStdDeviation().

CVector< C_FLOAT64 > COptMethodPS::mValues
private

Vector of values of objective function of each individual

Definition at line 152 of file COptMethodPS.h.

Referenced by create(), initialize(), move(), optimise(), and reachedStdDeviation().

size_t COptMethodPS::mVariableSize
private

number of parameters

Definition at line 142 of file COptMethodPS.h.

Referenced by create(), initialize(), move(), optimise(), and reachedStdDeviation().

C_FLOAT64 COptMethodPS::mVariance
private

The variance acceptable for the solution

Definition at line 122 of file COptMethodPS.h.

Referenced by initialize(), and reachedStdDeviation().

CMatrix< C_FLOAT64 > COptMethodPS::mVelocities
private

Matrix of individual velocities

Definition at line 157 of file COptMethodPS.h.

Referenced by create(), initialize(), move(), and optimise().


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