Click or drag to resize
Accord.NET (logo)

NonlinearConjugateGradient Class

Non-linear Conjugate Gradient (WARNING: This code can not be used for commercial purposes. It is MANDATORY to check the accompanying license file for this particular module AND the source code for more details before you use this code).
Inheritance Hierarchy
SystemObject
  Accord.Math.OptimizationBaseOptimizationMethod
    Accord.Math.OptimizationBaseGradientOptimizationMethod
      Accord.Math.OptimizationNonlinearConjugateGradient

Namespace:  Accord.Math.Optimization
Assembly:  Accord.Math.Noncommercial (in Accord.Math.Noncommercial.dll) Version: 3.8.0
Syntax
public class NonlinearConjugateGradient : BaseGradientOptimizationMethod, 
	IGradientOptimizationMethod, IOptimizationMethod, IOptimizationMethod<double[], double>, 
	IGradientOptimizationMethod<double[], double>, IFunctionOptimizationMethod<double[], double>
Request Example View Source

The NonlinearConjugateGradient type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyEvaluations
Public propertyFunction
Gets or sets the function to be optimized.
(Inherited from BaseOptimizationMethod.)
Public propertyGradient
Gets or sets a function returning the gradient vector of the function to be optimized for a given value of its free parameters.
(Inherited from BaseGradientOptimizationMethod.)
Public propertyIterations
Public propertyMaxIterations
Gets or sets the maximum number of iterations to be performed. Default is 100.
Public propertyNumberOfVariables
Gets the number of variables (free parameters) in the optimization problem.
(Inherited from BaseOptimizationMethod.)
Public propertySolution
Gets the current solution found, the values of the parameters which optimizes the function.
(Inherited from BaseOptimizationMethod.)
Public propertyToken
Gets or sets a cancellation token that can be used to stop the learning algorithm while it is running.
(Inherited from BaseOptimizationMethod.)
Public propertyValue
Gets the output of the function at the current Solution.
(Inherited from BaseOptimizationMethod.)
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodMaximize
Finds the maximum value of a function. The solution vector will be made available at the Solution property.
(Inherited from BaseGradientOptimizationMethod.)
Public methodMaximize(Double)
Finds the maximum value of a function. The solution vector will be made available at the Solution property.
(Inherited from BaseOptimizationMethod.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodMinimize
Finds the minimum value of a function. The solution vector will be made available at the Solution property.
(Inherited from BaseGradientOptimizationMethod.)
Public methodMinimize(Double)
Finds the minimum value of a function. The solution vector will be made available at the Solution property.
(Inherited from BaseOptimizationMethod.)
Protected methodOnNumberOfVariablesChanged
Called when the NumberOfVariables property has changed.
(Inherited from BaseOptimizationMethod.)
Protected methodOptimize
Implements the actual optimization algorithm. This method should try to minimize the objective function.
(Overrides BaseOptimizationMethodOptimize.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

This code has been contributed by Peter Sergio Larsen based on the original from Edward Rasmussen's FminCG. Please note that this code is only available under a special license that specifically denies the use for commercial applications and is thus not compatible with the LGPL and the GPL. Use at your own risk.

To use this class, add a reference to the Accord.Math.Noncommercial.dll assembly that resides inside the Release/Noncommercial folder of the framework's installation directory.

The copyright license, plus the original documentation for this code, is shown below.

function [X, fX, i] = fmincg(f, X, options, P1, P2, P3, P4, P5)
% Minimize a continuous differentialble multivariate function. Starting point
% is given by "X" (D by 1), and the function named in the string "f", must
% return a function value and a vector of partial derivatives. The Polack-
% Ribiere flavour of conjugate gradients is used to compute search directions,
% and a line search using quadratic and cubic polynomial approximations and the
% Wolfe-Powell stopping criteria is used together with the slope ratio method
% for guessing initial step sizes. Additionally a bunch of checks are made to
% make sure that exploration is taking place and that extrapolation will not
% be unboundedly large. The "length" gives the length of the run: if it is
% positive, it gives the maximum number of line searches, if negative its
% absolute gives the maximum allowed number of function evaluations. You can
% (optionally) give "length" a second component, which will indicate the
% reduction in function value to be expected in the first line-search (defaults
% to 1.0). The function returns when either its length is up, or if no further
% progress can be made (ie, we are at a minimum, or so close that due to
% numerical problems, we cannot get any closer). If the function terminates
% within a few iterations, it could be an indication that the function value
% and derivatives are not consistent (ie, there may be a bug in the
% implementation of your "f" function). The function returns the found
% solution "X", a vector of function values "fX" indicating the progress made
% and "i" the number of iterations (line searches or function evaluations,
% depending on the sign of "length") used.
%
% Usage: [X, fX, i] = fmincg(f, X, options, P1, P2, P3, P4, P5)
%
% See also: checkgrad 
%
% Copyright (C) 2001 and 2002 by Carl Edward Rasmussen. Date 2002-02-13
%
%
% (C) Copyright 1999, 2000 & 2001, Carl Edward Rasmussen
% 
% Permission is granted for anyone to copy, use, or modify these
% programs and accompanying documents for purposes of research or
% education, provided this copyright notice is retained, and note is
% made of any changes that have been made.
% 
% These programs and documents are distributed without any warranty,
% express or implied.  As the programs were written for research
% purposes only, they have not been tested to the degree that would be
% advisable in any important application.  All use of these programs is
% entirely at the user's own risk.

Modifications have been made so this code could fit under Accord.NET's IGradientOptimizationMethod interface. Modifications were necessary to port the original code from MATLAB/Octave to C#.

See Also