Safe Haskell | None |
---|---|
Language | Haskell98 |
Numerically solve convex Lagrange-multiplier problems with conjugate gradient descent.
Consider an example from the Wikipedia page on Lagrange multipliers in which we want to maximize the function f(x, y) = x + y, subject to the constraint x^2 + y^2 = 1:
>>>
maximize (\[x, y] -> x + y) [(\[x, y] -> x^2 + y^2) <=> 1] 0.00001 2
Right ([0.707,0.707], [-0.707])
The Right
indicates success; the first element of the pair is the
argument of the objective function at the maximum, and the second element
is a list of Lagrange multipliers.
- data Constraint
- (<=>) :: (forall a. Floating a => [a] -> a) -> (forall b. Floating b => b) -> Constraint
- maximize :: (forall a. Floating a => [a] -> a) -> [Constraint] -> Double -> Int -> Either (Result, Statistics) (Vector Double, Vector Double)
- minimize :: (forall a. Floating a => [a] -> a) -> [Constraint] -> Double -> Int -> Either (Result, Statistics) (Vector Double, Vector Double)
- feasible :: (Floating a, Field a, Element a) => (forall b. Floating b => [b] -> b) -> [Constraint] -> [a] -> Bool
Constraint type
data Constraint Source
An equality constraint of the form g(x, y, ...) = c
. Use <=>
to
construct a Constraint
.
(<=>) :: (forall a. Floating a => [a] -> a) -> (forall b. Floating b => b) -> Constraint infixr 1 Source
Build a Constraint
from a function and a constant
Optimizers
:: (forall a. Floating a => [a] -> a) | The objective function to minimize |
-> [Constraint] | A list of constraints |
-> Double | Stop iterating when the largest component of the gradient is smaller than this value |
-> Int | The arity of the objective function, which must equal the arity of the constraints |
-> Either (Result, Statistics) (Vector Double, Vector Double) | Either a |
Numerically maximize the Langrangian. The objective function and each of the constraints must take the same number of arguments.
:: (forall a. Floating a => [a] -> a) | The objective function to minimize |
-> [Constraint] | A list of constraints |
-> Double | Stop iterating when the largest component of the gradient is smaller than this value |
-> Int | The arity of the objective function, which must equal the arity of the constraints |
-> Either (Result, Statistics) (Vector Double, Vector Double) | Either a |
Numerically minimize the Langrangian. The objective function and each of the constraints must take the same number of arguments.
Experimental features
feasible :: (Floating a, Field a, Element a) => (forall b. Floating b => [b] -> b) -> [Constraint] -> [a] -> Bool Source
WARNING: Experimental.
This is not a true feasibility test for the function. I am not sure
exactly how to implement that. This just checks the feasiblility at a
point. If this ever returns false, solve
can fail.