levmar-1.2.1.8: An implementation of the Levenberg-Marquardt algorithm

Copyright (c) 2009 - 2014 Roel van Dijk & Bas van Dijk BSD-style (see the file LICENSE) Roel van Dijk Bas van Dijk Experimental None Haskell98

Numeric.LevMar

Description

For additional documentation see the documentation of the levmar C library which this library is based on:

Synopsis

# Model & Jacobian.

type Params r = Vector r Source #

Parameter vector of length m.

Ensure that m <= n where n is the length of the Samples vector.

type Samples r = Vector r Source #

Sample vector of length n.

Ensure that n >= m where m is the length of the Params vector.

type Model r = Params r -> Samples r Source #

A functional relation describing measurements represented as a function from a vector of parameters to a vector of expected samples.

• Ensure that the length m of the parameter vector equals the length of the initial parameter vector in levmar.
• Ensure that the length n of the output sample vector equals the length of the sample vector in levmar.
• Ensure that the length n of the output sample vector vector is bigger than or equal to the length m of the parameter vector.

type Jacobian r = Params r -> Matrix r Source #

The jacobian of the Model function. Expressed as a function from a vector of parameters to a matrix which for each expected sample describes the partial derivatives of the parameters.

• Ensure that the length m of the parameter vector equals the length of the initial parameter vector in levmar.
• Ensure that the output matrix has the dimension n><m where n is the number of samples and m is the number of parameters.

# Levenberg-Marquardt algorithm.

class LevMarable r where Source #

The Levenberg-Marquardt algorithm is overloaded to work on Double and Float.

Minimal complete definition

levmar

Methods

Arguments

 :: Model r Model -> Maybe (Jacobian r) Optional jacobian -> Params r Initial parameters of length m -> Samples r Sample vector of length n -> Int Maximum iterations -> Options r Minimization options -> Constraints r Constraints -> Either LevMarError (Params r, Info r, Matrix r)

The Levenberg-Marquardt algorithm.

Returns a triple of the found parameters, a structure containing information about the minimization and the covariance matrix corresponding to LS solution.

Ensure that n >= m.

Instances

 Source # Methods Source # Methods

# Minimization options.

data Options r Source #

Minimization options

Constructors

 Opts FieldsoptScaleInitMu :: !rScale factor for initial mu.optStopNormInfJacTe :: !rStopping thresholds for ||J^T e||_inf.optStopNorm2Dp :: !rStopping thresholds for ||Dp||_2.optStopNorm2E :: !rStopping thresholds for ||e||_2.optDelta :: !rStep used in the difference approximation to the Jacobian. If optDelta<0, the Jacobian is approximated with central differences which are more accurate (but slower!) compared to the forward differences employed by default.

Instances

 Eq r => Eq (Options r) Source # Methods(==) :: Options r -> Options r -> Bool #(/=) :: Options r -> Options r -> Bool # Data r => Data (Options r) Source # Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Options r -> c (Options r) #gunfold :: (forall b a. Data b => c (b -> a) -> c a) -> (forall a. a -> c a) -> Constr -> c (Options r) #toConstr :: Options r -> Constr #dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Options r)) #dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Options r)) #gmapT :: (forall b. Data b => b -> b) -> Options r -> Options r #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Options r -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Options r -> r #gmapQ :: (forall d. Data d => d -> u) -> Options r -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> Options r -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> Options r -> m (Options r) #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Options r -> m (Options r) #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Options r -> m (Options r) # Ord r => Ord (Options r) Source # Methodscompare :: Options r -> Options r -> Ordering #(<) :: Options r -> Options r -> Bool #(<=) :: Options r -> Options r -> Bool #(>) :: Options r -> Options r -> Bool #(>=) :: Options r -> Options r -> Bool #max :: Options r -> Options r -> Options r #min :: Options r -> Options r -> Options r # Read r => Read (Options r) Source # MethodsreadsPrec :: Int -> ReadS (Options r) # Show r => Show (Options r) Source # MethodsshowsPrec :: Int -> Options r -> ShowS #show :: Options r -> String #showList :: [Options r] -> ShowS #

Default minimization options

# Constraints

data Constraints r Source #

Ensure that these vectors have the same length as the number of parameters.

Constructors

 Constraints FieldslowerBounds :: !(Maybe (Params r))Optional lower boundsupperBounds :: !(Maybe (Params r))Optional upper boundsweights :: !(Maybe (Params r))Optional weightslinearConstraints :: !(Maybe (LinearConstraints r))Optional linear constraints

Instances

 (Eq r, Container Vector r, Num r) => Eq (Constraints r) Source # Methods(==) :: Constraints r -> Constraints r -> Bool #(/=) :: Constraints r -> Constraints r -> Bool # (Element r, Read r) => Read (Constraints r) Source # Methods (Element r, Show r) => Show (Constraints r) Source # MethodsshowsPrec :: Int -> Constraints r -> ShowS #show :: Constraints r -> String #showList :: [Constraints r] -> ShowS # Source # mempty is defined as a Constraints where all fields are Nothing.mappend merges two Constraints by taking the first non-Nothing value for each field. Methodsmappend :: Constraints r -> Constraints r -> Constraints r #mconcat :: [Constraints r] -> Constraints r #

type LinearConstraints r = (Matrix r, Vector r) Source #

Linear constraints consisting of a constraints matrix, k><m and a right hand constraints vector, of length k where m is the number of parameters and k is the number of constraints.

# Output

data Info r Source #

Information regarding the minimization.

Constructors

 Info FieldsinfNorm2initE :: !r||e||_2 at initial parameters.infNorm2E :: !r||e||_2 at estimated parameters.infNormInfJacTe :: !r||J^T e||_inf at estimated parameters.infNorm2Dp :: !r||Dp||_2 at estimated parameters.infMuDivMax :: !rmu/max[J^T J]_ii ] at estimated parameters.infNumIter :: !IntNumber of iterations.infStopReason :: !StopReasonReason for terminating.infNumFuncEvals :: !IntNumber of function evaluations.infNumJacobEvals :: !IntNumber of jacobian evaluations.infNumLinSysSolved :: !IntNumber of linear systems solved, i.e. attempts for reducing error.

Instances

 Eq r => Eq (Info r) Source # Methods(==) :: Info r -> Info r -> Bool #(/=) :: Info r -> Info r -> Bool # Data r => Data (Info r) Source # Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Info r -> c (Info r) #gunfold :: (forall b a. Data b => c (b -> a) -> c a) -> (forall a. a -> c a) -> Constr -> c (Info r) #toConstr :: Info r -> Constr #dataTypeOf :: Info r -> DataType #dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Info r)) #dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Info r)) #gmapT :: (forall b. Data b => b -> b) -> Info r -> Info r #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Info r -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Info r -> r #gmapQ :: (forall d. Data d => d -> u) -> Info r -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> Info r -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> Info r -> m (Info r) #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Info r -> m (Info r) #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Info r -> m (Info r) # Ord r => Ord (Info r) Source # Methodscompare :: Info r -> Info r -> Ordering #(<) :: Info r -> Info r -> Bool #(<=) :: Info r -> Info r -> Bool #(>) :: Info r -> Info r -> Bool #(>=) :: Info r -> Info r -> Bool #max :: Info r -> Info r -> Info r #min :: Info r -> Info r -> Info r # Read r => Read (Info r) Source # MethodsreadsPrec :: Int -> ReadS (Info r) #readList :: ReadS [Info r] # Show r => Show (Info r) Source # MethodsshowsPrec :: Int -> Info r -> ShowS #show :: Info r -> String #showList :: [Info r] -> ShowS #

Reason for terminating.

Constructors

 SmallGradient Stopped because of small gradient J^T e. SmallDp Stopped because of small Dp. MaxIterations Stopped because maximum iterations was reached. SingularMatrix Stopped because of singular matrix. Restart from current estimated parameters with increased optScaleInitMu. SmallestError Stopped because no further error reduction is possible. Restart with increased optScaleInitMu. SmallNorm2E Stopped because of small ||e||_2. InvalidValues Stopped because model function returned invalid values (i.e. NaN or Inf). This is a user error.

Instances

 Source # Methods Source # Methods Source # Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> StopReason -> c StopReason #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c StopReason #dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c StopReason) #dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c StopReason) #gmapT :: (forall b. Data b => b -> b) -> StopReason -> StopReason #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> StopReason -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> StopReason -> r #gmapQ :: (forall d. Data d => d -> u) -> StopReason -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> StopReason -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> StopReason -> m StopReason #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> StopReason -> m StopReason #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> StopReason -> m StopReason # Source # Methods Source # Methods Source # MethodsshowList :: [StopReason] -> ShowS #

Constructors

 LevMarError Generic error (not one of the others) LapackError A call to a lapack subroutine failed in the underlying C levmar library. FailedBoxCheck At least one lower bound exceeds the upper one. MemoryAllocationFailure A call to malloc failed in the underlying C levmar library. ConstraintMatrixRowsGtCols The matrix of constraints cannot have more rows than columns. ConstraintMatrixNotFullRowRank Constraints matrix is not of full row rank. TooFewMeasurements Cannot solve a problem with fewer measurements than unknowns. In case linear constraints are provided, this error is also returned when the number of measurements is smaller than the number of unknowns minus the number of equality constraints.

Instances

 Source # Methods Source # Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LevMarError -> c LevMarError #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c LevMarError #dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c LevMarError) #dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LevMarError) #gmapT :: (forall b. Data b => b -> b) -> LevMarError -> LevMarError #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LevMarError -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LevMarError -> r #gmapQ :: (forall d. Data d => d -> u) -> LevMarError -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> LevMarError -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> LevMarError -> m LevMarError #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> LevMarError -> m LevMarError #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> LevMarError -> m LevMarError # Source # Methods Source # Methods Source # MethodsshowList :: [LevMarError] -> ShowS # Source # Methods