public class MultivariableFunctionSolverIterationResults extends Object implements ICloneWithContext
MultivariableFunctionSolver
. This includes
the unperturbed run of the Function
(get
/ set
) and all of the perturbed
runs of the Function
(get
/ set
) for one time through the
MultivariableFunctionSolver
.Modifier | Constructor and Description |
---|---|
protected |
MultivariableFunctionSolverIterationResults(MultivariableFunctionSolverIterationResults existingInstance,
CopyContext context)
Initializes a new instance as a copy of an existing instance.
|
|
MultivariableFunctionSolverIterationResults(SolvableMultivariableFunctionResults functionResult,
SolvableMultivariableFunctionDerivativeResults derivativeResults,
int iteration,
SolverVariableSettings[] variableSettings,
SolverConstraintSettings[] constraintSettings)
Initializes a new instance.
|
public MultivariableFunctionSolverIterationResults(SolvableMultivariableFunctionResults functionResult, SolvableMultivariableFunctionDerivativeResults derivativeResults, int iteration, @Nonnull SolverVariableSettings[] variableSettings, @Nonnull SolverConstraintSettings[] constraintSettings)
functionResult
- The results of the computed SolvableMultivariableFunction
.derivativeResults
- The SolvableMultivariableFunctionDerivativeResults
that were computed
when the derivative of the function
was evaluated. This can be optional if
the derivative of the function was not evaluated in the iteration that made these results (as can happen on the final iteration).iteration
- The count of the iteration that produced these results. This should be zero based.variableSettings
- The settings of the variables that were used to compute all of the function evaluations.constraintSettings
- The settings of the constraints that were computed in all of the function evaluations.protected MultivariableFunctionSolverIterationResults(@Nonnull MultivariableFunctionSolverIterationResults existingInstance, @Nonnull CopyContext context)
See ICloneWithContext.clone(CopyContext)
for more information about how to implement this constructor
in a derived class.
existingInstance
- The existing instance to copy.context
- A CopyContext
that controls the depth of the copy.ArgumentNullException
- Thrown when existingInstance
or context
is null
.public Object clone(CopyContext context)
This method should be implemented to call a copy constructor on the class of the
object being cloned. The copy constructor should take the CopyContext
as a parameter
in addition to the existing instance to copy. The copy constructor should first call
CopyContext.addObjectMapping(T, T)
to identify the newly constructed instance
as a copy of the existing instance. It should then copy all fields, using
CopyContext.updateReference(T)
to copy any reference fields.
A typical implementation of ICloneWithContext
:
public static class MyClass implements ICloneWithContext {
public MyClass(MyClass existingInstance, CopyContext context) {
context.addObjectMapping(existingInstance, this);
someReference = context.updateReference(existingInstance.someReference);
}
@Override
public final Object clone(CopyContext context) {
return new MyClass(this, context);
}
private Object someReference;
}
In general, all fields that are reference types should be copied with a call to
CopyContext.updateReference(T)
. There are a couple of exceptions:
If one of these exceptions applies, the CopyContext
should be given an opportunity
to update the reference before the reference is copied explicitly. Use
CopyContext.updateReference(T)
to update the reference. If CopyContext.updateReference(T)
returns
the original object, indicating that the context does not have a replacement registered,
then copy the object manually by invoking a Clone method, a copy constructor, or by manually
constructing a new instance and copying the values.
alwaysCopy = context.updateReference(existingInstance.alwaysCopy);
if (existingInstance.alwaysCopy != null && alwaysCopy == existingInstance.alwaysCopy) {
alwaysCopy = (AlwaysCopy) existingInstance.alwaysCopy.clone(context);
}
If you are implementing an evaluator (a class that implements IEvaluator
), the
IEvaluator.updateEvaluatorReferences(agi.foundation.infrastructure.CopyContext)
method shares some responsibilities with the
copy context constructor. Code duplication can be avoided by doing the following:
CopyContext.updateReference(T)
. You should still call CopyContext.updateReference(T)
on any references to
non-evaluators.
IEvaluator.updateEvaluatorReferences(agi.foundation.infrastructure.CopyContext)
as the last line in the constructor and pass it the
same CopyContext
passed to the constructor.
IEvaluator.updateEvaluatorReferences(agi.foundation.infrastructure.CopyContext)
as normal. See the reference documentation for
IEvaluator.updateEvaluatorReferences(agi.foundation.infrastructure.CopyContext)
for more information on implementing that method.
public MyClass(MyClass existingInstance, CopyContext context) {
super(existingInstance, context);
someReference = context.updateReference(existingInstance.someReference);
evaluatorReference = existingInstance.evaluatorReference;
updateEvaluatorReferences(context);
}
@Override
public void updateEvaluatorReferences(CopyContext context) {
evaluatorReference = context.updateReference(evaluatorReference);
}
@Override
public Object clone(CopyContext context) {
return new MyClass(this, context);
}
private Object someReference;
private IEvaluator evaluatorReference;
clone
in interface ICloneWithContext
context
- The context to use to perform the copy.public final SolvableMultivariableFunctionDerivativeResults getDerivativeResults()
function's
derivative.public final SolvableMultivariableFunctionResults getFunctionResult()
public final int getIteration()
public final SolvableMultivariableFunctionResults getPerturbedResults(int index)
results
of the
Function
(get
/ set
) when the variable
with the same index
in the MultivariableFunctionSolver
was perturbed for this iteration.
Note that this may return null
if the Jacobian of the function that made these results was computed
analytically or if index
is higher than the number of variables in the function.index
- The index of the results to get.Function
(get
/ set
) when the variable
with the same index
in the MultivariableFunctionSolver
was perturbed for this iteration.public final SolverConstraintSettings[] getConstraintSettings()
SolverConstraintSettings
that correspond to the
constraints computed by the function
.
The order of the SolverConstraintSettings
in this array matches the order of the computed values.SolverConstraintSettings
that correspond to the values computed by all the
function evaluations in this set of results.public final SolverVariableSettings[] getVariableSettings()
SolverVariableSettings
that correspond to the variable values used to compute
all of the function evaluations. The order of the SolverVariableSettings
in this array matches
the order of the variable values.SolverVariableSettings
that correspond to the values used to compute all the
function evaluations in this set of results.public final int indexOfConstraint(SolverConstraintSettings constraint)
SolverConstraintSettings
in the array that is returned by the
MultivariableFunctionSolverIterationResults.getConstraintSettings()
method. This index also corresponds to the evaluated value
in the array returned by the SolvableMultivariableFunctionResults.getConstraintValues()
of
every SolvableMultivariableFunctionResults
stored in this set of results.constraint
- The SolverConstraintSettings
whose index is desired.SolverConstraintSettings
matching the constraint
and constraint value in all of the SolvableMultivariableFunctionResults
stored in this, or -1 if the
SolverConstraintSettings
is not stored in this set of results.public final int indexOfConstraint(String constraintName)
SolverConstraintSettings
with the matching
constraintName
in the array that is returned by the
MultivariableFunctionSolverIterationResults.getConstraintSettings()
method. This index also corresponds to the evaluated value
in the array returned by the SolvableMultivariableFunctionResults.getConstraintValues()
of
every SolvableMultivariableFunctionResults
stored in this set of results.constraintName
- The name of the SolverConstraintSettings
whose index is desired.SolverConstraintSettings
with the matching constraintName
and constraint value in all of the SolvableMultivariableFunctionResults
stored in this, or -1 if the
SolverConstraintSettings
is not stored in this set of results.public final int indexOfVariable(SolverVariableSettings variable)
SolverVariableSettings
in the array that is returned by the
MultivariableFunctionSolverIterationResults.getVariableSettings()
method. This index also corresponds to the variable values
in the array returned by the SolvableMultivariableFunctionResults.getVariablesUsed()
of
every SolvableMultivariableFunctionResults
stored in this set of results.variable
- The SolverVariableSettings
whose index is desired.SolverVariableSettings
matching the variable
and variable value in all of the SolvableMultivariableFunctionResults
stored in this, or -1 if the
SolverVariableSettings
is not stored in this set of results.public final int indexOfVariable(@Nullable String variableName)
SolverVariableSettings
with the matching
variableName
in the array that is returned by the
MultivariableFunctionSolverIterationResults.getVariableSettings()
method. This index also corresponds to the variable value
in the array returned by the SolvableMultivariableFunctionResults.getVariablesUsed()
of
every SolvableMultivariableFunctionResults
stored in this set of results.variableName
- The name of the SolverVariableSettings
whose index is desired.SolverVariableSettings
with the matching variableName
and variable value in all of the SolvableMultivariableFunctionResults
stored in this, or -1 if the
SolverVariableSettings
is not stored in this set of results.