Extreme Optimization – Numerical Algorithm Support

Posted by JoshReuben on Geeks with Blogs See other posts from Geeks with Blogs or by JoshReuben
Published on Sat, 08 Jan 2011 07:59:20 GMT Indexed on 2011/01/08 8:55 UTC
Read the original article Hit count: 401

Filed under:

 

Function Delegates

  • Many calculations involve the repeated evaluation of one or more user-supplied functions eg Numerical integration. The EO MathLib provides delegate types for common function signatures and the FunctionFactory class can generate new delegates from existing ones.
  • RealFunction delegate - takes one Double parameter – can encapsulate most of the static methods of the System.Math class, as well as the classes in the Extreme.Mathematics.SpecialFunctions namespace:

var sin = new RealFunction(Math.Sin);

var result = sin(1);

  • BivariateRealFunction delegate - takes two Double parameters:

var atan2 = new BivariateRealFunction (Math.Atan2);

var result = atan2(1, 2);

  • TrivariateRealFunction delegate – represents a function takes three Double arguments
  • ParameterizedRealFunction delegate - represents a function taking one Integer and one Double argument that returns a real number. The Pow method implements such a function, but the arguments need order re-arrangement:

static double Power(int exponent, double x)

{

return ElementaryFunctions.Pow(x, exponent);

}

...

var power = new ParameterizedRealFunction(Power);

var result = power(6, 3.2);

  • A ComplexFunction delegate - represents a function that takes an Extreme.Mathematics.DoubleComplex argument and also returns a complex number.
  • MultivariateRealFunction delegate - represents a function that takes an Extreme.Mathematics.LinearAlgebra.Vector argument and returns a real number.
  • MultivariateVectorFunction delegate - represents a function that takes a Vector argument and returns a Vector.
  • FastMultivariateVectorFunction delegate - represents a function that takes an input Vector argument and an output Matrix argument – avoiding object construction

 

The FunctionFactory class

  • RealFromBivariateRealFunction and RealFromParameterizedRealFunction helper methods - transform BivariateRealFunction or a ParameterizedRealFunction into a RealFunction delegate by fixing one of the arguments, and treating this as a new function of a single argument.

var tenthPower = FunctionFactory.RealFromParameterizedRealFunction(power, 10);

var result = tenthPower(x);

  • Note: There is no direct way to do this programmatically in C# - in F# you have partial value functions where you supply a subset of the arguments (as a travelling closure) that the function expects. When you omit arguments, F# generates a new function that holds onto/remembers the arguments you passed in and "waits" for the other parameters to be supplied.

let sumVals x y = x + y    

let sumX = sumVals 10     // Note: no 2nd param supplied.

    // sumX is a new function generated from partially applied sumVals.

    // ie "sumX is a partial application of sumVals."

let sum = sumX 20

    // Invokes sumX, passing in expected int (parameter y from original)

 

val sumVals : int -> int -> int

val sumX : (int -> int)

val sum : int = 30

  • RealFunctionsToVectorFunction and RealFunctionsToFastVectorFunction helper methods - combines an array of delegates returning a real number or a vector into vector or matrix functions. The resulting vector function returns a vector whose components are the function values of the delegates in the array.

var funcVector = FunctionFactory.RealFunctionsToVectorFunction(

    new MultivariateRealFunction(myFunc1),

    new MultivariateRealFunction(myFunc2));

 

The IterativeAlgorithm<T> abstract base class

  • Iterative algorithms are common in numerical computing - a method is executed repeatedly until a certain condition is reached, approximating the result of a calculation with increasing accuracy until a certain threshold is reached. If the desired accuracy is achieved, the algorithm is said to converge.
  • This base class is derived by many classes in the Extreme.Mathematics.EquationSolvers and Extreme.Mathematics.Optimization namespaces, as well as the ManagedIterativeAlgorithm class which contains a driver method that manages the iteration process.

 

The ConvergenceTest abstract base class

 

Concrete Types of Convergence Test classes

 

The AlgorithmHelper Class

© Geeks with Blogs or respective owner