|
WebCab Optimization v2.6 (J2EE Edition) |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
This interface should be implemented by all user supplied functions that are multidimensional and have a gradient. Multidimensional functions are functions that have more than one variable.
With this section we provide source code examples which illustrate explicitly how a multi-dimensional function is implemented. In particular, we provide the source code for the implementation of a polynomial.
Here we provide the definition of the object function: f(x,y) = xy + 2x + 3.
whith the following gradient:(y+2, x).
In order to provide an implementation for this interface you are required
to provide an implementation for the following methods:
getNoDimensions() - Returning the number of independent variables of the function.getValueAtVector(double[]) - Returns the value of the function f, at a given point.getGradientAtVector(double[]) - Returns the value of the gradient of the function f,
at a given point.Here we provide the source code for the implementation of the function f(x,y) = xy + 2x + 3,
on the Java (J2SE) Platform.
import webcab.lib.math.optimization.multidimensional.*;
public class MyFunction implements MultiDimensionalFunction, Gradient {
// The constructor of the class.
//
public MyFunction() throws Exception {}
// Returns the number of independent variables which in this case is 2, since
// the function f(x,y) has two independent variables.
//
public int getNoDimensions () {
return 2;
}
// Returns the value of the objective function f(x,y) = xy + 2x +3, at a given point.
//
public double getValueAtVector(double[] evaluationPoint) {
return evaluationPoint[0]*evaluationPoint[1] + 2*evaluationPoint[0] + 3;
}
// Returns the value of the gradient of the objective function evaluated at
// a given point. That is, evaluate the array of doubles where the k-th term
// is the evaluation of the derivative of the function with respect to the
// k-th coordinate.
//
public double[] getGradientAtVector(double[] evaluationPoint) {
double gradient = new double[2];
gradient[0] = evaluationPoint[1] + 2;
gradient[1] = evaluationPoint[0];
return gradient;
}
}
Here we provide the source code for the implementation of the function f(x,y) = xy + 2x + 3,
for the EJB (J2EE) Platform.
import webcab.lib.math.optimization.multidimensional.*;
import java.rmi.*;
import javax.rmi.*;
import javax.naming.*;
import javax.ejb.*;
public class MyFunction implements MultiDimensionalFunction, Gradient {
// The constructor of the class.
//
public MyFunction() throws Exception {}
// Returns the number of independent variables which in this case is 2, since
// the function f(x,y) has two independent variables.
//
public int getNoDimensions () {
return 2;
}
// Returns the value of the objective function f(x,y) = xy + 2x +3, at a given point.
//
public double getValueAtVector(double[] evaluationPoint) {
return evaluationPoint[0]*evaluationPoint[1] + 2*evaluationPoint[0] + 3;
}
// Returns the value of the gradient of the objective function evaluated at
// a given point. That is, evaluate the array of doubles where the k-th term
// is the evaluation of the derivative of the function with respect to the
// k-th coordinate.
//
public double[] getGradientAtVector(double[] evaluationPoint) {
double gradient = new double[2];
gradient[0] = evaluationPoint[1] + 2;
gradient[1] = evaluationPoint[0];
return gradient;
}
}
This interface inherits from this interface.| Method Summary | |
double[] |
getGradientAtVector(double[] x)
Computes the gradient of the function in the point x. |
| Methods inherited from interface com.webcab.ejb.math.optimization.multidimensional.MultiDimensionalFunction |
getNoDimensions, getValueAtVector |
| Method Detail |
public double[] getGradientAtVector(double[] x)
throws Exception
x.
- Parameters:
x - a vector containing the values of the variables
- Returns:
- a vector containing the components of the gradient
Exception
|
WebCab Optimization v2.6 (J2EE Edition) |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||