org.omegahat.Numerics.Optimizers
Class ModelObjectiveOmegahat

java.lang.Object
  |
  +--org.omegahat.Numerics.Optimizers.ModelObjectiveOmegahat
All Implemented Interfaces:
ModelObjective

public class ModelObjectiveOmegahat
extends java.lang.Object
implements ModelObjective

Create an object to evaluate a model function and possible gradients, starting from one or more Omegahat expressions.


Field Summary
protected  Evaluator evaluator
          The evaluator object to be used to evaluate the objective.
protected  ExpressionInt initialize
          An expression to be evaluated when the object is first intialized by the optimizer.
protected  ExpressionInt model
          The expression defining the model objective, at the current parameter values.
protected  java.lang.String[] parameterNames
           
 
Constructor Summary
ModelObjectiveOmegahat()
          Create a model objective for which the model (as an Omegahat expression) and the evaluator will be specified later.
ModelObjectiveOmegahat(ExpressionInt model)
          Create the complete model objective with the given model formula and an empty evaluator of class BasicEvaluator.
 
Method Summary
 void assignParameters(double[] pars)
          Assign the parameters to the evaluator's database.
 void assignParameters(ModelPointNumericInt arg)
          Assign the parameters from the model point to the evaluator's database.
 NumericArray collectGradient(ModelPointNumericInt x)
          Retrieve the gradient from the database, if it is there and non-null.
 NumericMatrix collectHessian(ModelPointNumericInt x)
          Retrieve the hessian from the database, if it is there and non-null.
 double collectValue(ModelPointNumericInt x)
          Retrieve the value from the database and assign it into the value property of the model point argument.
 ModelPoint eval(ModelPointNumericInt arg)
          Evaluate the model objective at this point.
 Evaluator getEvaluator()
          Accessor for evaluator field
 NumericArray getGradient(ModelPointNumericInt x)
          Retreive the return the computed gradient of the objective, and store it in the ModelPoint argument, if that is non-null.
 NumericMatrix getHessian(ModelPointNumericInt x)
          Retreive the return the computed hessian of the objective, and store it in the ModelPoint argument, if that is non-null.
 ExpressionInt getInitialize()
          Accessor for initialize field
 ExpressionInt getModel()
          Accessor for model field
 java.lang.String[] getParameterNames()
          Accessor for parameterNames field
 double getValue(ModelPointNumericInt x)
          Retreive the return the computed value of the objective, and store it in the ModelPoint argument, if that is non-null.
 boolean handleError(ModelPointNumericInt current, java.lang.Throwable e)
          Handle an exception or error that occurred during the fitting.
 Evaluator setEvaluator(Evaluator value)
          Accessor for setting evaluator field
 ExpressionInt setInitialize(ExpressionInt value)
          Accessor for setting initialize field
 ExpressionInt setModel(ExpressionInt value)
          Accessor for setting model field
 java.lang.String[] setParameterNames(java.lang.String[] value)
          Accessor for setting parameterNames field
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

evaluator

protected Evaluator evaluator
The evaluator object to be used to evaluate the objective.

If not specified, the initializing code will create one.


initialize

protected ExpressionInt initialize
An expression to be evaluated when the object is first intialized by the optimizer.

This may be used to attach database(s) or do other one-time computations.


model

protected ExpressionInt model
The expression defining the model objective, at the current parameter values.

The method for communicating the parameter values to the expression and for communicating the can be controlled in several ways. By default, the parameters are assigned under the name "Parameters" in the evaluator's default database. If the property parameterNames is set to a String[] array, the individual parameters will be assigned with the corresponding names.

When the expression completes, it should assign the value of the model objective with the name "Value"; if the gradient or hessian is computed by the expression, these should be stored as "Gradient" or Hessian respectively.

We expect to define alternative communication mechanisms in the future; in any case, other communication mechanisms can be defined by sub-classing this class and over-riding the assignParameters, getValue, getGradient, or getHessian methods as appropriate.


parameterNames

protected java.lang.String[] parameterNames
Constructor Detail

ModelObjectiveOmegahat

public ModelObjectiveOmegahat()
Create a model objective for which the model (as an Omegahat expression) and the evaluator will be specified later.

ModelObjectiveOmegahat

public ModelObjectiveOmegahat(ExpressionInt model)
Create the complete model objective with the given model formula and an empty evaluator of class BasicEvaluator.
Method Detail

getEvaluator

public Evaluator getEvaluator()
Accessor for evaluator field

setEvaluator

public Evaluator setEvaluator(Evaluator value)
Accessor for setting evaluator field

getInitialize

public ExpressionInt getInitialize()
Accessor for initialize field

setInitialize

public ExpressionInt setInitialize(ExpressionInt value)
Accessor for setting initialize field

getModel

public ExpressionInt getModel()
Accessor for model field

setModel

public ExpressionInt setModel(ExpressionInt value)
Accessor for setting model field

getParameterNames

public java.lang.String[] getParameterNames()
Accessor for parameterNames field

setParameterNames

public java.lang.String[] setParameterNames(java.lang.String[] value)
Accessor for setting parameterNames field

eval

public ModelPoint eval(ModelPointNumericInt arg)
Evaluate the model objective at this point. Update the point to contain the computed value and, if appropriate, derivatives.
Specified by:
eval in interface ModelObjective

assignParameters

public void assignParameters(double[] pars)
Assign the parameters to the evaluator's database.

assignParameters

public void assignParameters(ModelPointNumericInt arg)
Assign the parameters from the model point to the evaluator's database.
Specified by:
assignParameters in interface ModelObjective

getValue

public double getValue(ModelPointNumericInt x)
Description copied from interface: ModelObjective
Retreive the return the computed value of the objective, and store it in the ModelPoint argument, if that is non-null.
Specified by:
getValue in interface ModelObjective

getGradient

public NumericArray getGradient(ModelPointNumericInt x)
Description copied from interface: ModelObjective
Retreive the return the computed gradient of the objective, and store it in the ModelPoint argument, if that is non-null.

By convention, returns null if the gradient is not being computed.

Specified by:
getGradient in interface ModelObjective

getHessian

public NumericMatrix getHessian(ModelPointNumericInt x)
Description copied from interface: ModelObjective
Retreive the return the computed hessian of the objective, and store it in the ModelPoint argument, if that is non-null.

By convention, returns null if the hessian is not being computed.

Specified by:
getHessian in interface ModelObjective

collectValue

public double collectValue(ModelPointNumericInt x)
Retrieve the value from the database and assign it into the value property of the model point argument. Returns the value. The evaluation in the Omegaghat evaluator must have been done for this object, so this is essentially a utility method for subclasses that do not want to use the eval method.

collectGradient

public NumericArray collectGradient(ModelPointNumericInt x)
Retrieve the gradient from the database, if it is there and non-null. Assign it into the gradient property of the model point argument. Returns the gradient.

collectHessian

public NumericMatrix collectHessian(ModelPointNumericInt x)
Retrieve the hessian from the database, if it is there and non-null. Assign it into the hessian property of the model point argument. Returns the hessian.

If the model point has not been evaluated, first evaluate it.


handleError

public boolean handleError(ModelPointNumericInt current,
                           java.lang.Throwable e)
Handle an exception or error that occurred during the fitting.

The default handler just prints some error information and sets the value to NaN.