hmatrix-nlopt-0.2.0.0: Interface HMatrix with the NLOPT minimizer
Copyright (c) Matthew Peddie 2017 BSD3 Matthew Peddie provisional GHC Safe-Inferred Haskell2010

Numeric.NLOPT

Description

This module provides a high-level, hmatrix-compatible interface to the NLOPT library by Steven G. Johnson.

# Documentation

Most non-numerical details are documented, but for specific information on what the optimization methods do, how constraints are handled, etc., you should consult:

# Example program

The following interactive session example uses the Nelder-Mead simplex algorithm, a derivative-free local optimizer, to minimize a trivial function with a minimum of 22.0 at (0, 0).

>>> import Numeric.LinearAlgebra ( dot, fromList )
>>> let objf x = x dot x + 22                         -- define objective
>>> let stop = ObjectiveRelativeTolerance 1e-6 :| []    -- define stopping criterion
>>> let algorithm = NELDERMEAD objf [] Nothing          -- specify algorithm
>>> let problem = LocalProblem 2 stop algorithm         -- specify problem
>>> let x0 = fromList [5, 10]                           -- specify initial guess
>>> minimizeLocal problem x0
Right (Solution {solutionCost = 22.0, solutionParams = [0.0,0.0], solutionResult = FTOL_REACHED})

Synopsis

# Specifying the objective function

type Objective Source #

Arguments

 = Vector Double Parameter vector -> Double Objective function value

An objective function that calculates the objective value at the given parameter vector.

Arguments

 = Vector Double Parameter vector -> (Double, Vector Double) (Objective function value, gradient)

An objective function that calculates both the objective value and the gradient of the objective with respect to the input parameter vector, at the given parameter vector.

Arguments

 = Vector Double Parameter vector x -> Vector Double Vector v to precondition at x -> Vector Double Preconditioned vector vpre

A preconditioner function, which computes vpre = H(x) v, where H is the Hessian matrix: the positive semi-definite second derivative at the given parameter vector x, or an approximation thereof.

# Specifying the constraints

## Bound constraints

data Bounds Source #

Bound constraints are specified by vectors of the same dimension as the parameter space.

## Example program

The following interactive session example enforces lower bounds on the example from the beginning of the module. This prevents the optimizer from locating the true minimum at (0, 0); a slightly higher constrained minimum at (1, 1) is found. Note that the optimizer returns XTOL_REACHED rather than FTOL_REACHED, because the bound constraint is active at the final minimum.

>>> import Numeric.LinearAlgebra ( dot, fromList )
>>> let objf x = x dot x + 22                           -- define objective
>>> let stop = ObjectiveRelativeTolerance 1e-6 :| []      -- define stopping criterion
>>> let lowerbound = LowerBounds $fromList [1, 1] -- specify bounds >>> let algorithm = NELDERMEAD objf [lowerbound] Nothing -- specify algorithm >>> let problem = LocalProblem 2 stop algorithm -- specify problem >>> let x0 = fromList [5, 10] -- specify initial guess >>> minimizeLocal problem x0 Right (Solution {solutionCost = 24.0, solutionParams = [1.0,1.0], solutionResult = XTOL_REACHED})  Constructors  LowerBounds (Vector Double) Lower bound vector v means we want x >= v. UpperBounds (Vector Double) Upper bound vector u means we want x <= u. #### Instances Instances details  Source # Instance detailsDefined in Numeric.NLOPT Methods Source # Instance detailsDefined in Numeric.NLOPT MethodsshowsPrec :: Int -> Bounds -> ShowS #showList :: [Bounds] -> ShowS # Source # Instance detailsDefined in Numeric.NLOPT Methods(==) :: Bounds -> Bounds -> Bool #(/=) :: Bounds -> Bounds -> Bool # ## Nonlinear constraints Note that most NLOPT algorithms do not support nonlinear constraints natively; if you need to enforce nonlinear constraints, you may want to use the AugLagAlgorithm family of solvers, which can add nonlinear constraints to some algorithm that does not support them by a principled modification of the objective function. ## Example program The following interactive session example enforces a scalar constraint on the problem given in the beginning of the module: the parameters must always sum to 1. The minimizer finds a constrained minimum of 22.5 at (0.5, 0.5). >>> import Numeric.LinearAlgebra ( dot, fromList, toList ) >>> let objf x = x dot x + 22 >>> let stop = ObjectiveRelativeTolerance 1e-9 :| [] >>> -- define constraint function: >>> let constraintf x = sum (toList x) - 1.0 >>> -- define constraint object to pass to the algorithm: >>> let constraint = EqualityConstraint (Scalar constraintf) 1e-6 >>> let algorithm = COBYLA objf [] [] [constraint] Nothing >>> let problem = LocalProblem 2 stop algorithm >>> let x0 = fromList [5, 10] >>> minimizeLocal problem x0 Right (Solution {solutionCost = 22.500000000013028, solutionParams = [0.5000025521533521,0.49999744784664796], solutionResult = FTOL_REACHED})  ### Constraint functions Arguments  = Vector Double Parameter vector x -> Double Constraint violation (deviation from 0) A constraint function which returns c(x) given the parameter vector x. The constraint will enforce that c(x) == 0 (equality constraint) or c(x) <= 0 (inequality constraint). Arguments  = Vector Double Parameter vector -> (Double, Vector Double) (Constraint violation, constraint gradient) A constraint function which returns c(x) given the parameter vector x along with the gradient of c(x) with respect to x at that point. The constraint will enforce that c(x) == 0 (equality constraint) or c(x) <= 0 (inequality constraint). Arguments  = Vector Double Parameter vector -> Word Constraint vector size -> Vector Double Constraint violation vector A constraint function which returns a vector c(x) given the parameter vector x. The constraint will enforce that c(x) == 0 (equality constraint) or c(x) <= 0 (inequality constraint). Arguments  = Vector Double Parameter vector -> Word Constraint vector size -> (Vector Double, Matrix Double) (Constraint violation vector, constraint Jacobian) A constraint function which returns c(x) given the parameter vector x along with the Jacobian (first derivative) matrix of c(x) with respect to x at that point. The constraint will enforce that c(x) == 0 (equality constraint) or c(x) <= 0 (inequality constraint). ### Constraint types data Constraint s v Source # Constructors  Scalar s A scalar constraint. Vector Word v A vector constraint. Preconditioned Preconditioner s A scalar constraint with an attached preconditioning function. data EqualityConstraint s v Source # An equality constraint, comprised of both the constraint function (or functions, if a preconditioner is used) along with the desired tolerance. Constructors  EqualityConstraint Fields data InequalityConstraint s v Source # An inequality constraint, comprised of both the constraint function (or functions, if a preconditioner is used) along with the desired tolerance. Constructors  InequalityConstraint Fields ### Collections of constraints A collection of equality constraints that do not supply constraint derivatives. A collection of equality constraints that supply constraint derivatives. A collection of inequality constraints that do not supply constraint derivatives. A collection of inequality constraints that supply constraint derivatives. # Stopping conditions The NonEmpty data type from NonEmpty is re-exported here, because it is used to ensure that you always specify at least one stopping condition. A StoppingCondition tells NLOPT when to stop working on a minimization problem. When multiple StoppingConditions are provided, the problem will stop when any one condition is met. Constructors  MinimumValue Double Stop minimizing when an objective value J less than or equal to the provided value is found. ObjectiveRelativeTolerance Double Stop minimizing when an optimization step changes the objective value J by less than the provided tolerance multiplied by |J|. ObjectiveAbsoluteTolerance Double Stop minimizing when an optimization step changes the objective value by less than the provided tolerance. ParameterRelativeTolerance Double Stop when an optimization step changes every element of the parameter vector x by less than x scaled by the provided tolerance. ParameterAbsoluteTolerance (Vector Double) Stop when an optimization step changes every element of the parameter vector x by less than the corresponding element in the provided vector of tolerances values. MaximumEvaluations Word Stop when the number of evaluations of the objective function exceeds the provided count. MaximumTime Double Stop when the optimization time exceeds the provided time (in seconds). This is not a precise limit. #### Instances Instances details  Source # Instance detailsDefined in Numeric.NLOPT Methods Source # Instance detailsDefined in Numeric.NLOPT MethodsshowList :: [StoppingCondition] -> ShowS # Source # Instance detailsDefined in Numeric.NLOPT Methods data NonEmpty a # Non-empty (and non-strict) list type. Since: base-4.9.0.0 Constructors  a :| [a] infixr 5 #### Instances Instances details  Since: base-4.9.0.0 Instance detailsDefined in Data.Foldable Methodsfold :: Monoid m => NonEmpty m -> m #foldMap :: Monoid m => (a -> m) -> NonEmpty a -> m #foldMap' :: Monoid m => (a -> m) -> NonEmpty a -> m #foldr :: (a -> b -> b) -> b -> NonEmpty a -> b #foldr' :: (a -> b -> b) -> b -> NonEmpty a -> b #foldl :: (b -> a -> b) -> b -> NonEmpty a -> b #foldl' :: (b -> a -> b) -> b -> NonEmpty a -> b #foldr1 :: (a -> a -> a) -> NonEmpty a -> a #foldl1 :: (a -> a -> a) -> NonEmpty a -> a #toList :: NonEmpty a -> [a] #null :: NonEmpty a -> Bool #length :: NonEmpty a -> Int #elem :: Eq a => a -> NonEmpty a -> Bool #maximum :: Ord a => NonEmpty a -> a #minimum :: Ord a => NonEmpty a -> a #sum :: Num a => NonEmpty a -> a #product :: Num a => NonEmpty a -> a # Since: base-4.9.0.0 Instance detailsDefined in Data.Traversable Methodstraverse :: Applicative f => (a -> f b) -> NonEmpty a -> f (NonEmpty b) #sequenceA :: Applicative f => NonEmpty (f a) -> f (NonEmpty a) #mapM :: Monad m => (a -> m b) -> NonEmpty a -> m (NonEmpty b) #sequence :: Monad m => NonEmpty (m a) -> m (NonEmpty a) # Since: base-4.9.0.0 Instance detailsDefined in GHC.Base Methodspure :: a -> NonEmpty a #(<*>) :: NonEmpty (a -> b) -> NonEmpty a -> NonEmpty b #liftA2 :: (a -> b -> c) -> NonEmpty a -> NonEmpty b -> NonEmpty c #(*>) :: NonEmpty a -> NonEmpty b -> NonEmpty b #(<*) :: NonEmpty a -> NonEmpty b -> NonEmpty a # Since: base-4.9.0.0 Instance detailsDefined in GHC.Base Methodsfmap :: (a -> b) -> NonEmpty a -> NonEmpty b #(<$) :: a -> NonEmpty b -> NonEmpty a # Since: base-4.9.0.0 Instance detailsDefined in GHC.Base Methods(>>=) :: NonEmpty a -> (a -> NonEmpty b) -> NonEmpty b #(>>) :: NonEmpty a -> NonEmpty b -> NonEmpty b #return :: a -> NonEmpty a # Since: base-4.9.0.0 Instance detailsDefined in GHC.Base Methods(<>) :: NonEmpty a -> NonEmpty a -> NonEmpty a #sconcat :: NonEmpty (NonEmpty a) -> NonEmpty a #stimes :: Integral b => b -> NonEmpty a -> NonEmpty a # Instance detailsDefined in GHC.Generics Associated Typestype Rep (NonEmpty a) :: Type -> Type # Methodsfrom :: NonEmpty a -> Rep (NonEmpty a) x #to :: Rep (NonEmpty a) x -> NonEmpty a # Read a => Read (NonEmpty a) Since: base-4.11.0.0 Instance detailsDefined in GHC.Read MethodsreadsPrec :: Int -> ReadS (NonEmpty a) # Show a => Show (NonEmpty a) Since: base-4.11.0.0 Instance detailsDefined in GHC.Show MethodsshowsPrec :: Int -> NonEmpty a -> ShowS #show :: NonEmpty a -> String #showList :: [NonEmpty a] -> ShowS # Eq a => Eq (NonEmpty a) Since: base-4.9.0.0 Instance detailsDefined in GHC.Base Methods(==) :: NonEmpty a -> NonEmpty a -> Bool #(/=) :: NonEmpty a -> NonEmpty a -> Bool # Ord a => Ord (NonEmpty a) Since: base-4.9.0.0 Instance detailsDefined in GHC.Base Methodscompare :: NonEmpty a -> NonEmpty a -> Ordering #(<) :: NonEmpty a -> NonEmpty a -> Bool #(<=) :: NonEmpty a -> NonEmpty a -> Bool #(>) :: NonEmpty a -> NonEmpty a -> Bool #(>=) :: NonEmpty a -> NonEmpty a -> Bool #max :: NonEmpty a -> NonEmpty a -> NonEmpty a #min :: NonEmpty a -> NonEmpty a -> NonEmpty a # Instance detailsDefined in GHC.Generics Associated Typestype Rep1 NonEmpty :: k -> Type # Methodsfrom1 :: forall (a :: k). NonEmpty a -> Rep1 NonEmpty a #to1 :: forall (a :: k). Rep1 NonEmpty a -> NonEmpty a # type Rep (NonEmpty a) Since: base-4.6.0.0 Instance detailsDefined in GHC.Generics type Rep (NonEmpty a) = D1 ('MetaData "NonEmpty" "GHC.Base" "base" 'False) (C1 ('MetaCons ":|" ('InfixI 'LeftAssociative 9) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [a]))) type Rep1 NonEmpty Since: base-4.6.0.0 Instance detailsDefined in GHC.Generics type Rep1 NonEmpty = D1 ('MetaData "NonEmpty" "GHC.Base" "base" 'False) (C1 ('MetaCons ":|" ('InfixI 'LeftAssociative 9) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1 :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1 [])))

This specifies how to initialize the random number generator for stochastic algorithms.

Constructors

 SeedValue Word Seed the RNG with the provided value. SeedFromTime Seed the RNG using the system clock. Don'tSeed Don't perform any explicit initialization of the RNG.

#### Instances

Instances details
 Source # Instance detailsDefined in Numeric.NLOPT Methods Source # Instance detailsDefined in Numeric.NLOPT MethodsshowList :: [RandomSeed] -> ShowS # Source # Instance detailsDefined in Numeric.NLOPT Methods

newtype Population Source #

This specifies the population size for algorithms that use a pool of solutions.

Constructors

 Population Word

#### Instances

Instances details
 Source # Instance detailsDefined in Numeric.NLOPT Methods Source # Instance detailsDefined in Numeric.NLOPT MethodsshowList :: [Population] -> ShowS # Source # Instance detailsDefined in Numeric.NLOPT Methods

newtype VectorStorage Source #

This specifies the memory size to be used by algorithms like LBFGS which store approximate Hessian or Jacobian matrices.

Constructors

 VectorStorage Word

#### Instances

Instances details
 Source # Instance detailsDefined in Numeric.NLOPT Methods Source # Instance detailsDefined in Numeric.NLOPT MethodsshowList :: [VectorStorage] -> ShowS # Source # Instance detailsDefined in Numeric.NLOPT Methods

newtype InitialStep Source #

This vector with the same dimension as the parameter vector x specifies the initial step for the optimizer to take. (This applies to local gradient-free algorithms, which cannot use gradients to estimate how big a step to take.)

Constructors

 InitialStep (Vector Double)

#### Instances

Instances details
 Source # Instance detailsDefined in Numeric.NLOPT Methods Source # Instance detailsDefined in Numeric.NLOPT MethodsshowList :: [InitialStep] -> ShowS # Source # Instance detailsDefined in Numeric.NLOPT Methods

# Minimization problems

## Local minimization

These are the local minimization algorithms provided by NLOPT. Please see the NLOPT algorithm manual for more details on how the methods work and how they relate to one another. Note that some local methods require you provide derivatives (gradients or Jacobians) for your objective function and constraint functions.

Optional parameters are wrapped in a Maybe; for example, if you see Maybe VectorStorage, you can simply specify Nothing to use the default behavior.

Constructors

 LBFGS_NOCEDAL ObjectiveD (Maybe VectorStorage) Limited-memory BFGS LBFGS ObjectiveD (Maybe VectorStorage) Limited-memory BFGS VAR2 ObjectiveD (Maybe VectorStorage) Shifted limited-memory variable-metric, rank-2 VAR1 ObjectiveD (Maybe VectorStorage) Shifted limited-memory variable-metric, rank-1 TNEWTON ObjectiveD (Maybe VectorStorage) Truncated Newton's method TNEWTON_RESTART ObjectiveD (Maybe VectorStorage) Truncated Newton's method with automatic restarting TNEWTON_PRECOND ObjectiveD (Maybe VectorStorage) Preconditioned truncated Newton's method TNEWTON_PRECOND_RESTART ObjectiveD (Maybe VectorStorage) Preconditioned truncated Newton's method with automatic restarting MMA ObjectiveD InequalityConstraintsD Method of moving averages SLSQP ObjectiveD [Bounds] InequalityConstraintsD EqualityConstraintsD Sequential Least-Squares Quadratic Programming CCSAQ ObjectiveD Preconditioner Conservative Convex Separable Approximation PRAXIS Objective [Bounds] (Maybe InitialStep) PRincipal AXIS gradient-free local optimization COBYLA Objective [Bounds] InequalityConstraints EqualityConstraints (Maybe InitialStep) Constrained Optimization BY Linear Approximations NEWUOA Objective (Maybe InitialStep) Powell's NEWUOA algorithm NEWUOA_BOUND Objective [Bounds] (Maybe InitialStep) Powell's NEWUOA algorithm with bounds by SGJ NELDERMEAD Objective [Bounds] (Maybe InitialStep) Nelder-Mead Simplex gradient-free method SBPLX Objective [Bounds] (Maybe InitialStep) NLOPT implementation of Rowan's Subplex algorithm BOBYQA Objective [Bounds] (Maybe InitialStep) Bounded Optimization BY Quadratic Approximations

Constructors

 LocalProblem Fieldslsize :: WordThe dimension of the parameter vector.lstop :: NonEmpty StoppingConditionAt least one stopping conditionlalgorithm :: LocalAlgorithmAlgorithm specification

## Example program

The following interactive session example enforces the same scalar constraint as the nonlinear constraint example, but this time it uses the SLSQP solver to find the minimum.

>>> import Numeric.LinearAlgebra ( dot, fromList, toList, scale )
>>> let objf x = (x dot x + 22, 2 scale x)
>>> let stop = ObjectiveRelativeTolerance 1e-9 :| []
>>> let constraintf x = (sum (toList x) - 1.0, fromList [1, 1])
>>> let constraint = EqualityConstraint (Scalar constraintf) 1e-6
>>> let algorithm = SLSQP objf [] [] [constraint]
>>> let problem = LocalProblem 2 stop algorithm
>>> let x0 = fromList [5, 10]
>>> minimizeLocal problem x0
Right (Solution {solutionCost = 22.5, solutionParams = [0.4999999999999998,0.5000000000000002], solutionResult = FTOL_REACHED})


## Global minimization

These are the global minimization algorithms provided by NLOPT. Please see the NLOPT algorithm manual for more details on how the methods work and how they relate to one another.

Optional parameters are wrapped in a Maybe; for example, if you see Maybe Population, you can simply specify Nothing to use the default behavior.

Constructors

 DIRECT Objective DIviding RECTangles DIRECT_L Objective DIviding RECTangles, locally-biased variant DIRECT_L_RAND Objective RandomSeed DIviding RECTangles, "slightly randomized" DIRECT_NOSCAL Objective DIviding RECTangles, unscaled version DIRECT_L_NOSCAL Objective DIviding RECTangles, locally-biased and unscaled DIRECT_L_RAND_NOSCAL Objective RandomSeed DIviding RECTangles, locally-biased, unscaled and "slightly randomized" ORIG_DIRECT Objective InequalityConstraints DIviding RECTangles, original FORTRAN implementation ORIG_DIRECT_L Objective InequalityConstraints DIviding RECTangles, locally-biased, original FORTRAN implementation STOGO ObjectiveD Stochastic Global Optimization. This algorithm is only available if you have linked with libnlopt_cxx. STOGO_RAND ObjectiveD RandomSeed Stochastic Global Optimization, randomized variant. This algorithm is only available if you have linked with libnlopt_cxx. CRS2_LM Objective RandomSeed (Maybe Population) Controlled Random Search with Local Mutation ISRES Objective InequalityConstraints EqualityConstraints RandomSeed (Maybe Population) Improved Stochastic Ranking Evolution Strategy ESCH Objective Evolutionary Algorithm MLSL Objective LocalProblem (Maybe Population) Original Multi-Level Single-Linkage MLSL_LDS Objective LocalProblem (Maybe Population) Multi-Level Single-Linkage with Sobol Low-Discrepancy Sequence for starting points

Constructors

 GlobalProblem FieldslowerBounds :: Vector DoubleLower bounds for xupperBounds :: Vector DoubleUpper bounds for xgstop :: NonEmpty StoppingConditionAt least one stopping conditiongalgorithm :: GlobalAlgorithmAlgorithm specification

Arguments

 :: GlobalProblem Problem specification -> Vector Double Initial parameter guess -> Either Result Solution Optimization results

Solve the specified global optimization problem.

# Example program

The following interactive session example uses the ISRES algorithm, a stochastic, derivative-free global optimizer, to minimize a trivial function with a minimum of 22.0 at (0, 0). The search is conducted within a box from -10 to 10 in each dimension.

>>> import Numeric.LinearAlgebra ( dot, fromList )
>>> let objf x = x dot x + 22                              -- define objective
>>> let stop = ObjectiveRelativeTolerance 1e-12 :| []        -- define stopping criterion
>>> let algorithm = ISRES objf [] [] (SeedValue 22) Nothing  -- specify algorithm
>>> let lowerbounds = fromList [-10, -10]                    -- specify bounds
>>> let upperbounds = fromList [10, 10]                      -- specify bounds
>>> let problem = GlobalProblem lowerbounds upperbounds stop algorithm
>>> let x0 = fromList [5, 8]                                 -- specify initial guess
>>> minimizeGlobal problem x0
Right (Solution {solutionCost = 22.000000000002807, solutionParams = [-1.660591102367038e-6,2.2407062393213684e-7], solutionResult = FTOL_REACHED})


## Minimization by augmented Lagrangian

The Augmented Lagrangian solvers allow you to enforce nonlinear constraints while using local or global algorithms that don't natively support them. The subsidiary problem is used to do the minimization, but the AUGLAG methods modify the objective to enforce the constraints. Please see the NLOPT algorithm manual for more details on how the methods work and how they relate to one another.

See the documentation for AugLagProblem for an important note about the constraint functions.

Constructors

 AUGLAG_LOCAL LocalProblem InequalityConstraints InequalityConstraintsD AUGmented LAGrangian with a local subsidiary method AUGLAG_EQ_LOCAL LocalProblem AUGmented LAGrangian with a local subsidiary method and with penalty functions only for equality constraints AUGLAG_GLOBAL GlobalProblem InequalityConstraints InequalityConstraintsD AUGmented LAGrangian with a global subsidiary method AUGLAG_EQ_GLOBAL GlobalProblem AUGmented LAGrangian with a global subsidiary method and with penalty functions only for equality constraints.

IMPORTANT NOTE

For augmented lagrangian problems, you, the user, are responsible for providing the appropriate type of constraint. If the subsidiary problem requires an ObjectiveD, then you should provide constraint functions with derivatives. If the subsidiary problem requires an Objective, you should provide constraint functions without derivatives. If you don't do this, you may get a runtime error.

Constructors

 AugLagProblem FieldsalEquality :: EqualityConstraintsPossibly empty set of equality constraintsalEqualityD :: EqualityConstraintsDPossibly empty set of equality constraints with derivativesalalgorithm :: AugLagAlgorithmAlgorithm specification.

## Example program

The following interactive session example enforces the same scalar constraint as the nonlinear constraint example, but this time it uses the augmented Lagrangian method to enforce the constraint and the SBPLX algorithm, which does not support nonlinear constraints itself, to perform the minimization. As before, the parameters must always sum to 1, and the minimizer finds the same constrained minimum of 22.5 at (0.5, 0.5).

>>> import Numeric.LinearAlgebra ( dot, fromList, toList )
>>> let objf x = x dot x + 22
>>> let stop = ObjectiveRelativeTolerance 1e-9 :| []
>>> let algorithm = SBPLX objf [] Nothing
>>> let subproblem = LocalProblem 2 stop algorithm
>>> let x0 = fromList [5, 10]
>>> minimizeLocal subproblem x0
Right (Solution {solutionCost = 22.0, solutionParams = [0.0,0.0], solutionResult = FTOL_REACHED})
>>> -- define constraint function:
>>> let constraintf x = sum (toList x) - 1.0
>>> -- define constraint object to pass to the algorithm:
>>> let constraint = EqualityConstraint (Scalar constraintf) 1e-6
>>> let problem = AugLagProblem [constraint] [] (AUGLAG_EQ_LOCAL subproblem)
>>> minimizeAugLag problem x0
Right (Solution {solutionCost = 22.500000015505844, solutionParams = [0.5000880506776678,0.4999119493223323], solutionResult = FTOL_REACHED})


## Results

data Solution Source #

This structure is returned in the event of a successful optimization.

Constructors

 Solution FieldssolutionCost :: DoubleThe objective function value at the minimumsolutionParams :: Vector DoubleThe parameter vector which minimizes the objectivesolutionResult :: ResultWhy the optimizer stopped

#### Instances

Instances details
 Source # Instance detailsDefined in Numeric.NLOPT Methods Source # Instance detailsDefined in Numeric.NLOPT MethodsshowList :: [Solution] -> ShowS # Source # Instance detailsDefined in Numeric.NLOPT Methods

data Result #

Mostly self-explanatory.

Constructors

 FAILURE Generic failure code INVALID_ARGS OUT_OF_MEMORY ROUNDOFF_LIMITED FORCED_STOP SUCCESS Generic success code STOPVAL_REACHED FTOL_REACHED XTOL_REACHED MAXEVAL_REACHED MAXTIME_REACHED

#### Instances

Instances details
 Instance detailsDefined in Numeric.Optimization.NLOPT.Bindings Methods Instance detailsDefined in Numeric.Optimization.NLOPT.Bindings MethodstoEnum :: Int -> Result #enumFrom :: Result -> [Result] #enumFromThen :: Result -> Result -> [Result] #enumFromTo :: Result -> Result -> [Result] #enumFromThenTo :: Result -> Result -> Result -> [Result] # Instance detailsDefined in Numeric.Optimization.NLOPT.Bindings Methods Instance detailsDefined in Numeric.Optimization.NLOPT.Bindings MethodsshowsPrec :: Int -> Result -> ShowS #showList :: [Result] -> ShowS # Instance detailsDefined in Numeric.Optimization.NLOPT.Bindings Methods(==) :: Result -> Result -> Bool #(/=) :: Result -> Result -> Bool #