-- 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. See:
-- http://www.ics.forth.gr/~lourakis/levmar/.
--
-- 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
-- | For additional documentation see the documentation of the levmar C
-- library which this library is based on:
-- http://www.ics.forth.gr/~lourakis/levmar/
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.
--
--
-- - 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 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.
--
-- See:
-- http://en.wikipedia.org/wiki/Jacobian_matrix_and_determinant
--
--
-- - 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.
--
type Jacobian r = Params r -> Matrix r
-- | The Levenberg-Marquardt algorithm is overloaded to work on
-- Double and Float.
class LevMarable r
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 Typeable1 Options
instance Typeable1 Constraints
instance Typeable StopReason
instance Typeable1 Info
instance Typeable LevMarError
instance (Eq r, Container Vector r) => Eq (Constraints r)
instance Eq r => Eq (Options r)
instance Ord r => Ord (Options r)
instance Read r => Read (Options r)
instance Show r => Show (Options r)
instance Data r => Data (Options r)
instance (Read r, Element r) => Read (Constraints r)
instance (Show r, Element r) => Show (Constraints r)
instance Eq StopReason
instance Ord StopReason
instance Read StopReason
instance Show StopReason
instance Data StopReason
instance Enum StopReason
instance Eq r => Eq (Info r)
instance Ord r => Ord (Info r)
instance Read r => Read (Info r)
instance Show r => Show (Info r)
instance Data r => Data (Info r)
instance Eq LevMarError
instance Ord LevMarError
instance Read LevMarError
instance Show LevMarError
instance Data LevMarError
instance Exception LevMarError
instance Monoid (Constraints r)
instance LevMarable Double
instance LevMarable Float