copasi/optimization/COptMethodTruncatedNewton.cpp
// callback function, evaluate the value of the objective function and its gradient
//(by finite differences), translated by f2c, edited by Pedro and then modified for COPASI by Joseph
callback function, evaluate the value of the objective function and its gradient
(by finite differences), translated by f2c, edited by Pedro and then modified for COPASI by Joseph
callback function evaluate the value of the objective function and its gradient ( by finite differences ) translated by f2c edited by Pedro and then modified for COPASI by Joseph
C_INT COptMethodTruncatedNewton::sFun(C_INT *n, C_FLOAT64 *x, C_FLOAT64 *f, C_FLOAT64 *g)
{
  C_INT i;
  for (i = 0; i < *n; i++)
    *mContainerVariables[i] = (x[i]);
  *f = evaluate();
  if (mEvaluationValue < mBestValue)
    {
      for (i = 0; i < *n; i++)
        mBest[i] = x[i];
      mBestValue = mEvaluationValue;
      mContinue = mpOptProblem->setSolution(mBestValue, mBest);
      mpParentTask->output(COutputInterface::DURING);
    }
  for (i = 0; i < *n && mContinue; i++)
    {
      if (x[i] != 0.0)
        {
          *mContainerVariables[i] = (x[i] * 1.001);
          g[i] = (evaluate() - *f) / (x[i] * 0.001);
        }
      else
        {
          *mContainerVariables[i] = (1e-7);
          g[i] = (evaluate() - *f) / 1e-7;
        }
      *mContainerVariables[i] = (x[i]);
    }
  if (!mContinue)
    throw bool(mContinue);
  return 0;
}
C_INT COptMethodTruncatedNewton :: sFun ( C_INT * n , C_FLOAT64 * x , C_FLOAT64 * f , C_FLOAT64 * g ) { C_INT i ; for ( i = 0 ; i < * n ; i ++ ) * mContainerVariables [ i ] = ( x [ i ] ) ; * f = evaluate ( ) ; if ( mEvaluationValue < mBestValue ) { for ( i = 0 ; i < * n ; i ++ ) mBest [ i ] = x [ i ] ; mBestValue = mEvaluationValue ; mContinue = mpOptProblem -> setSolution ( mBestValue , mBest ) ; mpParentTask -> output ( COutputInterface :: DURING ) ; } for ( i = 0 ; i < * n && mContinue ; i ++ ) { if ( x [ i ] != 0.0 ) { * mContainerVariables [ i ] = ( x [ i ] * 1.001 ) ; g [ i ] = ( evaluate ( ) - * f ) / ( x [ i ] * 0.001 ) ; } else { * mContainerVariables [ i ] = ( 1e-7 ) ; g [ i ] = ( evaluate ( ) - * f ) / 1e-7 ; } * mContainerVariables [ i ] = ( x [ i ] ) ; } if ( ! mContinue ) throw bool ( mContinue ) ; return 0 ; }
callback function, evaluate the value of the objective function and its gradient
(by finite differences), translated by f2c, edited by Pedro and then modified for COPASI by Joseph
callback function evaluate the value of the objective function and its gradient ( by finite differences ) translated by f2c edited by Pedro and then modified for COPASI by Joseph
// set the parameter values //carry out the function evaluation // Check whether we improved // We found a new best value lets report it. // and store that value // We found a new best value lets report it. // Calculate the gradient