A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://accord-framework.net/docs/html/T_Accord_Math_Optimization_QuadraticObjectiveFunction.htm below:

QuadraticObjectiveFunction Class

Quadratic objective function.

Inheritance Hierarchy Namespace:  Accord.Math.Optimization
Assembly:

Accord.Math (in Accord.Math.dll) Version: 3.8.0

Syntax
public class QuadraticObjectiveFunction : NonlinearObjectiveFunction, 
	IObjectiveFunction
Public Class QuadraticObjectiveFunction
	Inherits NonlinearObjectiveFunction
	Implements IObjectiveFunction
Request Example View Source

The QuadraticObjectiveFunction type exposes the following members.

Constructors Properties Methods   Name Description Equals

Determines whether the specified object is equal to the current object.

(Inherited from Object.) Finalize

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.

(Inherited from Object.) GetHashCode

Serves as the default hash function.

(Inherited from Object.) GetType

Gets the Type of the current instance.

(Inherited from Object.) MemberwiseClone

Creates a shallow copy of the current Object.

(Inherited from Object.) ToString

Returns a String that represents this instance.

(Overrides ObjectToString.) TryParse(String, QuadraticObjectiveFunction)

Attempts to create a QuadraticObjectiveFunction from a String representation.

TryParse(String, CultureInfo, QuadraticObjectiveFunction)

Attempts to create a QuadraticObjectiveFunction from a String representation.

Top Operators Extension Methods   Name Description HasMethod

Checks whether an object implements a method with the given name.

(Defined by ExtensionMethods.) IsEqual

Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.

(Defined by Matrix.) To(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.) ToT 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.) Top Remarks

In mathematics, a quadratic function, a quadratic polynomial, a polynomial of degree 2, or simply a quadratic, is a polynomial function in one or more variables in which the highest-degree term is of the second degree. For example, a quadratic function in three variables x, y, and z contains exclusively terms x², y², z², xy, xz, yz, x, y, z, and a constant:

f(x,y,z) = ax² + by² +cz² + dxy + exz + fyz + gx + hy + iz + j

Please note that the function's constructor expects the function expression to be given on this form. Scalar values must be located on the left of the variables, and no term should be duplicated in the quadratic expression. Please take a look on the examples section of this page for some examples of expected functions.

References:

Examples

Examples of valid quadratic functions are:

var f1 = new QuadraticObjectiveFunction("x² + 1");
var f2 = new QuadraticObjectiveFunction("-x*y + y*z");
var f3 = new QuadraticObjectiveFunction("-2x² + xy - y² - 10xz + z²");
var f4 = new QuadraticObjectiveFunction("-2x² + xy - y² + 5y");

It is also possible to specify quadratic functions using lambda expressions. In this case, it is first necessary to create some dummy symbol variables to act as placeholders in the quadratic expressions. Their value is not important, as they will only be used to parse the form of the expression, not its value.

double x = 0, y = 0, z = 0;

var g1 = new QuadraticObjectiveFunction(() => x * x + 1);
var g2 = new QuadraticObjectiveFunction(() => -x * y + y * z);
var g3 = new QuadraticObjectiveFunction(() => -2 * x * x + x * y - y * y - 10 * x * z + z * z);
var g4 = new QuadraticObjectiveFunction(() => -2 * x * x + x * y - y * y + 5 * y);

Finally, for large problems, it is usually best to declare quadratic problems using matrices and vectors. Without loss of generality, the quadratic matrix can always be taken to be symmetric (as the anti- symmetric part has no contribution to the function). For efficiency reasons, the quadratic matrix must be symmetric.

var h1 = new QuadraticObjectiveFunction("3x² - 4y² + 6xy + 3x + 2y");

double[,] Q = { { 6, 6 }, { 6, -8 } }; 
double[] d = { 3, 2 };


var h2 = new QuadraticObjectiveFunction(Q, d);

After those functions are created, you can either query their values using

f1.Function(new [] { 5.0 }); 

Or you can pass it to a quadratic optimization method such as Goldfarb-Idnani to explore its minimum or maximal points:

double x = 0, y = 0, z = 0;


var f = new QuadraticObjectiveFunction(() => x * x - 2 * x * y + 3 * y * y + z * z - 4 * x - 5 * y - z);


var constraints = new List<LinearConstraint>();
constraints.Add(new LinearConstraint(f, () => 6 * x - 7 * y <= 8));
constraints.Add(new LinearConstraint(f, () => 9 * x + 1 * y <= 11));
constraints.Add(new LinearConstraint(f, () => 9 * x - y <= 11));
constraints.Add(new LinearConstraint(f, () => -z - y == 12));


GoldfarbIdnani solver = new GoldfarbIdnani(f, constraints);


bool success = solver.Minimize();

double value = solver.Value;
double[] solutions = solver.Solution;

Sometimes it is easiest to compose quadratic functions as linear combinations of other quadratic functions. The QuadraticObjectiveFunction supports this by overloading the addition and multiplication operators.


var f1 = new QuadraticObjectiveFunction("2x² + 4y² - 2xy + 6");
var f2 = new QuadraticObjectiveFunction("3x² - 4y² + 6xy + 3x + 2y");










QuadraticObjectiveFunction f = f1 + (2 * f2); 


double[] x = { 1, 2 };

double result1 = f1.Function(x);
double result2 = f2.Function(x);

double result = f.Function(x);          
double check = result1 + 2 * result2;   
See Also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4