-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | An implementation of the Levenberg-Marquardt algorithm -- -- The Levenberg-Marquardt algorithm is an iterative technique that finds -- a local minimum of a function that is expressed as the sum of squares -- of nonlinear functions. It has become a standard technique for -- nonlinear least-squares problems and can be thought of as a -- combination of steepest descent and the Gauss-Newton method. When the -- current solution is far from the correct one, the algorithm behaves -- like a steepest descent method: slow, but guaranteed to converge. When -- the current solution is close to the correct solution, it becomes a -- Gauss-Newton method. -- -- Optional box- and linear constraints can be given. Both single and -- double precision floating point types are supported. -- -- The actual algorithm is implemented in a C library which is -- bundled with bindings-levmar which this package depends on. -- -- A note regarding the license: -- -- This library depends on bindings-levmar which is bundled -- together with a C library which falls under the GPL. Please be aware -- of this when distributing programs linked with this library. For -- details see the description and license of bindings-levmar. @package levmar @version 1.2.1.8 -- | For additional documentation see the documentation of the levmar -- C library which this library is based on: module Numeric.LevMar -- | Parameter vector of length m. -- -- Ensure that m <= n where n is the length of the -- Samples vector. type Params r = Vector r -- | Sample vector of length n. -- -- Ensure that n >= m where m is the length of the -- Params vector. type Samples r = Vector r -- | A functional relation describing measurements represented as a -- function from a vector of parameters to a vector of expected samples. -- -- type Model r = Params r -> Samples r -- | 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. -- -- type Jacobian r = Params r -> Matrix r -- | The Levenberg-Marquardt algorithm is overloaded to work on -- Double and Float. class LevMarable 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. levmar :: LevMarable r => Model r -> Maybe (Jacobian r) -> Params r -> Samples r -> Int -> Options r -> Constraints r -> Either LevMarError (Params r, Info r, Matrix r) -- | Minimization options data Options r Opts :: !r -> !r -> !r -> !r -> !r -> Options r -- | Scale factor for initial mu. [optScaleInitMu] :: Options r -> !r -- | Stopping thresholds for ||J^T e||_inf. [optStopNormInfJacTe] :: Options r -> !r -- | Stopping thresholds for ||Dp||_2. [optStopNorm2Dp] :: Options r -> !r -- | Stopping thresholds for ||e||_2. [optStopNorm2E] :: Options r -> !r -- | Step 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. [optDelta] :: Options r -> !r -- | Default minimization options defaultOpts :: Fractional r => Options r -- | Ensure that these vectors have the same length as the number of -- parameters. data Constraints r Constraints :: !(Maybe (Params r)) -> !(Maybe (Params r)) -> !(Maybe (Params r)) -> !(Maybe (LinearConstraints r)) -> Constraints r -- | Optional lower bounds [lowerBounds] :: Constraints r -> !(Maybe (Params r)) -- | Optional upper bounds [upperBounds] :: Constraints r -> !(Maybe (Params r)) -- | Optional weights [weights] :: Constraints r -> !(Maybe (Params r)) -- | Optional linear constraints [linearConstraints] :: Constraints r -> !(Maybe (LinearConstraints r)) -- | 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. type LinearConstraints r = (Matrix r, Vector r) -- | Information regarding the minimization. data Info r Info :: !r -> !r -> !r -> !r -> !r -> !Int -> !StopReason -> !Int -> !Int -> !Int -> Info r -- | ||e||_2 at initial parameters. [infNorm2initE] :: Info r -> !r -- | ||e||_2 at estimated parameters. [infNorm2E] :: Info r -> !r -- | ||J^T e||_inf at estimated parameters. [infNormInfJacTe] :: Info r -> !r -- | ||Dp||_2 at estimated parameters. [infNorm2Dp] :: Info r -> !r -- | mu/max[J^T J]_ii ] at estimated parameters. [infMuDivMax] :: Info r -> !r -- | Number of iterations. [infNumIter] :: Info r -> !Int -- | Reason for terminating. [infStopReason] :: Info r -> !StopReason -- | Number of function evaluations. [infNumFuncEvals] :: Info r -> !Int -- | Number of jacobian evaluations. [infNumJacobEvals] :: Info r -> !Int -- | Number of linear systems solved, i.e. attempts for reducing error. [infNumLinSysSolved] :: Info r -> !Int -- | Reason for terminating. data StopReason -- | Stopped because of small gradient J^T e. SmallGradient :: StopReason -- | Stopped because of small Dp. SmallDp :: StopReason -- | Stopped because maximum iterations was reached. MaxIterations :: StopReason -- | Stopped because of singular matrix. Restart from current estimated -- parameters with increased optScaleInitMu. SingularMatrix :: StopReason -- | Stopped because no further error reduction is possible. Restart with -- increased optScaleInitMu. SmallestError :: StopReason -- | Stopped because of small ||e||_2. SmallNorm2E :: StopReason -- | Stopped because model function returned invalid values (i.e. NaN or -- Inf). This is a user error. InvalidValues :: StopReason data LevMarError -- | Generic error (not one of the others) LevMarError :: LevMarError -- | A call to a lapack subroutine failed in the underlying C levmar -- library. LapackError :: LevMarError -- | At least one lower bound exceeds the upper one. FailedBoxCheck :: LevMarError -- | A call to malloc failed in the underlying C levmar library. MemoryAllocationFailure :: LevMarError -- | The matrix of constraints cannot have more rows than columns. ConstraintMatrixRowsGtCols :: LevMarError -- | Constraints matrix is not of full row rank. ConstraintMatrixNotFullRowRank :: LevMarError -- | 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. TooFewMeasurements :: LevMarError instance Data.Data.Data Numeric.LevMar.LevMarError instance GHC.Show.Show Numeric.LevMar.LevMarError instance GHC.Read.Read Numeric.LevMar.LevMarError instance GHC.Classes.Ord Numeric.LevMar.LevMarError instance GHC.Classes.Eq Numeric.LevMar.LevMarError instance Data.Data.Data r => Data.Data.Data (Numeric.LevMar.Info r) instance GHC.Show.Show r => GHC.Show.Show (Numeric.LevMar.Info r) instance GHC.Read.Read r => GHC.Read.Read (Numeric.LevMar.Info r) instance GHC.Classes.Ord r => GHC.Classes.Ord (Numeric.LevMar.Info r) instance GHC.Classes.Eq r => GHC.Classes.Eq (Numeric.LevMar.Info r) instance GHC.Enum.Enum Numeric.LevMar.StopReason instance Data.Data.Data Numeric.LevMar.StopReason instance GHC.Show.Show Numeric.LevMar.StopReason instance GHC.Read.Read Numeric.LevMar.StopReason instance GHC.Classes.Ord Numeric.LevMar.StopReason instance GHC.Classes.Eq Numeric.LevMar.StopReason instance (Internal.Matrix.Element r, GHC.Show.Show r) => GHC.Show.Show (Numeric.LevMar.Constraints r) instance (Internal.Matrix.Element r, GHC.Read.Read r) => GHC.Read.Read (Numeric.LevMar.Constraints r) instance Data.Data.Data r => Data.Data.Data (Numeric.LevMar.Options r) instance GHC.Show.Show r => GHC.Show.Show (Numeric.LevMar.Options r) instance GHC.Read.Read r => GHC.Read.Read (Numeric.LevMar.Options r) instance GHC.Classes.Ord r => GHC.Classes.Ord (Numeric.LevMar.Options r) instance GHC.Classes.Eq r => GHC.Classes.Eq (Numeric.LevMar.Options r) instance (GHC.Classes.Eq r, Internal.Numeric.Container Data.Vector.Storable.Vector r, GHC.Num.Num r) => GHC.Classes.Eq (Numeric.LevMar.Constraints r) instance Numeric.LevMar.LevMarable GHC.Types.Float instance Numeric.LevMar.LevMarable GHC.Types.Double instance GHC.Exception.Exception Numeric.LevMar.LevMarError instance GHC.Base.Monoid (Numeric.LevMar.Constraints r)