WebCab Optimization
v2.6
(J2EE Edition)

com.webcab.ejb.math.optimization.multidimensional
Interface Gradient

All Superinterfaces:
Function, MultiDimensionalFunction, Remote, Serializable

public interface Gradient
extends MultiDimensionalFunction

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.

Source Code Examples

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:

  1. getNoDimensions() - Returning the number of independent variables of the function.
  2. getValueAtVector(double[]) - Returns the value of the function f, at a given point.
  3. getGradientAtVector(double[]) - Returns the value of the gradient of the function f, at a given point.

Source Code Implemention on the Java (J2SE) Platform

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;
   }
}

Source Code Implementation for the EJB (J2EE) Platform

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;
   }
}

See Also:
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

getGradientAtVector

public double[] getGradientAtVector(double[] x)
                             throws Exception
Computes the gradient of the function in the point 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)