|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Functional
Interface of a functional.
An implementation of this interface represents a function taking a fixed number of real input values to compute a single real output value. The gradient (first derivative) and hessian (second derivative) of the function can be calculated as well.
The design of this class is intended to faciliate optimization. To
calculate the function itself, its gradient or its hessian at a
given location in input space, one first has to move the whole
function to that location using setArgument(no.uib.cipr.matrix.Vector). Subsequent
calls to return given values will always assume that location to be
the function input. It is up to the function implementation to
split work between setArgument and the other methods
in a suitable fashion. An implementation may throw an
IllegalStateException if there was no call to
setArgument preceding any of the result calculation
methods, but is not required to do so.
A common way to use this interface woule look like this:
Functional functional = constructFunctional();
int size = functional.getInputDimension(size);
Vector x = constructInitialValue(size);
double value;
Vector gradient = null;
Matrix hessian = null;
while (/* condition */) {
functional.setArgument(x);
value = functional.value();
gradient = functional.gradient(gradient);
hessian = functional.hessian(hessian);
// work with results, modify x appropriately
}
| Method Summary | |
|---|---|
int |
getInputDimension()
Return the dimension of the input space. |
no.uib.cipr.matrix.Vector |
gradient(no.uib.cipr.matrix.Vector g)
Calculate gradient. |
no.uib.cipr.matrix.Matrix |
hessian(no.uib.cipr.matrix.Matrix h)
Calculate hessian. |
void |
setArgument(no.uib.cipr.matrix.Vector x)
Set function arguments for subsequent calls. |
double |
value()
Calculate function value. |
double |
valueChange()
Calculate change in function value. |
| Method Detail |
|---|
int getInputDimension()
void setArgument(no.uib.cipr.matrix.Vector x)
x - the argument vecotor of the functiondouble value()
Calculates the function value at the position given by the most
recent call to setArgument(Vector).
IllegalStateException - if there was no preceding call to
setArgumentdouble valueChange()
Calculates the difference between the function value at the
position given by the most recent call to
setArgument(Vector) and the function value returned by
the last call to value().
IllegalStateException - if there was no preceding call to
setArgument or valueno.uib.cipr.matrix.Vector gradient(no.uib.cipr.matrix.Vector g)
Calculates the gradient of the function at the position given
by the most recent call to setArgument(Vector).
The caller may provide a preallocated vector as an argument,
and the implementation of the function may choose whether or
not to use that object instead of allocating a new one. Passing
null will cause the implementation to always
allocate a suitable vector object. The caller is encouraged to
pass the result of a previous invocation to reuse such objects.
g - a preallocated vector that may be used for the result
IllegalStateException - if there was no preceding call to
setArgumentno.uib.cipr.matrix.Matrix hessian(no.uib.cipr.matrix.Matrix h)
Calculates the function value at the position given by the most
recent call to setArgument(Vector).
The caller may provide a preallocated matrix as an argument,
and the implementation of the function may choose whether or
not to use that object instead of allocating a new one. Passing
null will cause the implementation to always
allocate a suitable matrix object. The caller is encouraged to
pass the result of a previous invocation to reuse such objects.
h - a preallocated matrix that may be used for the result
IllegalStateException - if there was no preceding call to
setArgument
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||