opto-0.1.0.0: General-purpose performant numeric optimization library

Copyright(c) Justin Le 2019
LicenseBSD3
Maintainerjustin@jle.im
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Numeric.Opto.Update

Description

A unified interface for values in vector spaces that can be added and scaled (purely and also in-place), and measured.

Synopsis

Documentation

class Num c => Linear c a | a -> c where Source #

If a is an instance of Linear c, you can add together values of a, and scale them using cs.

For example, if you have a vector of doubles, you can add them together component-wise, and scale them by multiplying every item by the scalar.

Mathematically, this means that a forms something like a module or vector space over c, where c can be any Num instance.

Minimal complete definition

Nothing

Methods

(.+.) :: a -> a -> a infixl 6 Source #

Add together as. Should be associative.

x .+. (y .+. z) == (x .+. y) .+. z

If a is an instance of Num, this can be just +.

zeroL :: a Source #

The "zero" a, meant to form an identity with .+..

x .+. zeroL == x
zeroL .+. y == y

If a is an instance of Num, this can be just 0.

(.*) :: c -> a -> a infixl 7 Source #

Scale an a by a factor c. Should distribute over .+..

a .* (x .+. y) == (a .* x) .+. (a .* y)
a .* (b .* c)  == (a * b) .* c

(.+.) :: (ADTRecord a, Constraints a (Linear c)) => a -> a -> a infixl 6 Source #

Add together as. Should be associative.

x .+. (y .+. z) == (x .+. y) .+. z

If a is an instance of Num, this can be just +.

zeroL :: (ADTRecord a, Constraints a (Linear c)) => a Source #

The "zero" a, meant to form an identity with .+..

x .+. zeroL == x
zeroL .+. y == y

If a is an instance of Num, this can be just 0.

(.*) :: (ADTRecord a, Constraints a (Linear c)) => c -> a -> a infixl 7 Source #

Scale an a by a factor c. Should distribute over .+..

a .* (x .+. y) == (a .* x) .+. (a .* y)
a .* (b .* c)  == (a * b) .* c
Instances
Linear Double Double Source # 
Instance details

Defined in Numeric.Opto.Update

Linear Float Float Source # 
Instance details

Defined in Numeric.Opto.Update

Linear Int Int Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.) :: Int -> Int -> Int Source #

zeroL :: Int Source #

(.*) :: Int -> Int -> Int Source #

Linear Integer Integer Source # 
Instance details

Defined in Numeric.Opto.Update

KnownNat n => Linear Double (R n) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.) :: R n -> R n -> R n Source #

zeroL :: R n Source #

(.*) :: Double -> R n -> R n Source #

Linear Rational (Ratio Integer) Source # 
Instance details

Defined in Numeric.Opto.Update

(KnownNat n, KnownNat m) => Linear Double (L n m) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.) :: L n m -> L n m -> L n m Source #

zeroL :: L n m Source #

(.*) :: Double -> L n m -> L n m Source #

(Linear c a, Linear c b) => Linear c (a, b) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.) :: (a, b) -> (a, b) -> (a, b) Source #

zeroL :: (a, b) Source #

(.*) :: c -> (a, b) -> (a, b) Source #

(Linear c (f a), Linear c (Rec f (b ': bs))) => Linear c (Rec f (a ': (b ': bs))) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.) :: Rec f (a ': (b ': bs)) -> Rec f (a ': (b ': bs)) -> Rec f (a ': (b ': bs)) Source #

zeroL :: Rec f (a ': (b ': bs)) Source #

(.*) :: c -> Rec f (a ': (b ': bs)) -> Rec f (a ': (b ': bs)) Source #

Linear c (f a) => Linear c (Rec f (a ': ([] :: [Type]))) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.) :: Rec f (a ': []) -> Rec f (a ': []) -> Rec f (a ': []) Source #

zeroL :: Rec f (a ': []) Source #

(.*) :: c -> Rec f (a ': []) -> Rec f (a ': []) Source #

(Linear c a, Linear c b, Linear c d) => Linear c (a, b, d) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.) :: (a, b, d) -> (a, b, d) -> (a, b, d) Source #

zeroL :: (a, b, d) Source #

(.*) :: c -> (a, b, d) -> (a, b, d) Source #

(Num a, Vector v a, KnownNat n) => Linear a (Vector v n a) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.) :: Vector v n a -> Vector v n a -> Vector v n a Source #

zeroL :: Vector v n a Source #

(.*) :: a -> Vector v n a -> Vector v n a Source #

(Linear c a, Linear c b, Linear c d, Linear c e) => Linear c (a, b, d, e) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.) :: (a, b, d, e) -> (a, b, d, e) -> (a, b, d, e) Source #

zeroL :: (a, b, d, e) Source #

(.*) :: c -> (a, b, d, e) -> (a, b, d, e) Source #

(Linear c a, Linear c b, Linear c d, Linear c e, Linear c f) => Linear c (a, b, d, e, f) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.) :: (a, b, d, e, f) -> (a, b, d, e, f) -> (a, b, d, e, f) Source #

zeroL :: (a, b, d, e, f) Source #

(.*) :: c -> (a, b, d, e, f) -> (a, b, d, e, f) Source #

RealFloat a => Linear (Complex a) (Complex a) Source # 
Instance details

Defined in Numeric.Opto.Update

sumLinear :: (Linear c a, Foldable t) => t a -> a Source #

Sum over a Foldable container of Linear c a

gAdd :: forall c a. (ADTRecord a, Constraints a (Linear c)) => a -> a -> a Source #

An implementation of .+. that works for records where every field is an instance of Linear c (that is, every field is additive and can be scaled by the same c).

gZeroL :: forall c a. (ADTRecord a, Constraints a (Linear c)) => a Source #

An implementation of zeroL that works for records where every field is an instance of Linear c (that is, every field is additive and can be scaled by the same c).

gScale :: forall c a. (ADTRecord a, Constraints a (Linear c)) => c -> a -> a Source #

An implementation of .* that works for records where every field is an instance of Linear c (that is, every field is additive and can be scaled by the same c).

class Linear c a => Metric c a where Source #

Class for values supporting an inner product and various norms.

Minimal complete definition

Nothing

Methods

(<.>) :: a -> a -> c infixl 7 Source #

Sum of component-wise product

norm_inf :: a -> c Source #

Maximum absolute component. Is undefined if no components exist.

norm_0 :: a -> c Source #

Number of non-zero components

norm_1 :: a -> c Source #

Sum of absolute components

norm_2 :: a -> c Source #

Square root of sum of squared components

quadrance :: a -> c Source #

Sum of squared components

(<.>) :: (ADT a, Constraints a (Metric c)) => a -> a -> c infixl 7 Source #

Sum of component-wise product

norm_inf :: (ADT a, Constraints a (Metric c), Ord c) => a -> c Source #

Maximum absolute component. Is undefined if no components exist.

norm_0 :: (ADT a, Constraints a (Metric c)) => a -> c Source #

Number of non-zero components

norm_1 :: (ADT a, Constraints a (Metric c)) => a -> c Source #

Sum of absolute components

norm_2 :: Floating c => a -> c Source #

Square root of sum of squared components

quadrance :: (ADT a, Constraints a (Metric c)) => a -> c Source #

Sum of squared components

Instances
Metric Double Double Source # 
Instance details

Defined in Numeric.Opto.Update

Metric Float Float Source # 
Instance details

Defined in Numeric.Opto.Update

Metric Int Int Source # 
Instance details

Defined in Numeric.Opto.Update

Metric Integer Integer Source # 
Instance details

Defined in Numeric.Opto.Update

KnownNat n => Metric Double (R n) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(<.>) :: R n -> R n -> Double Source #

norm_inf :: R n -> Double Source #

norm_0 :: R n -> Double Source #

norm_1 :: R n -> Double Source #

norm_2 :: R n -> Double Source #

quadrance :: R n -> Double Source #

Metric Rational (Ratio Integer) Source # 
Instance details

Defined in Numeric.Opto.Update

(KnownNat n, KnownNat m) => Metric Double (L n m) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(<.>) :: L n m -> L n m -> Double Source #

norm_inf :: L n m -> Double Source #

norm_0 :: L n m -> Double Source #

norm_1 :: L n m -> Double Source #

norm_2 :: L n m -> Double Source #

quadrance :: L n m -> Double Source #

(Metric c a, Metric c b, Ord c, Floating c) => Metric c (a, b) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(<.>) :: (a, b) -> (a, b) -> c Source #

norm_inf :: (a, b) -> c Source #

norm_0 :: (a, b) -> c Source #

norm_1 :: (a, b) -> c Source #

norm_2 :: (a, b) -> c Source #

quadrance :: (a, b) -> c Source #

(Floating c, Ord c, Metric c (f a), Metric c (Rec f (b ': bs))) => Metric c (Rec f (a ': (b ': bs))) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(<.>) :: Rec f (a ': (b ': bs)) -> Rec f (a ': (b ': bs)) -> c Source #

norm_inf :: Rec f (a ': (b ': bs)) -> c Source #

norm_0 :: Rec f (a ': (b ': bs)) -> c Source #

norm_1 :: Rec f (a ': (b ': bs)) -> c Source #

norm_2 :: Rec f (a ': (b ': bs)) -> c Source #

quadrance :: Rec f (a ': (b ': bs)) -> c Source #

Metric c (f a) => Metric c (Rec f (a ': ([] :: [Type]))) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(<.>) :: Rec f (a ': []) -> Rec f (a ': []) -> c Source #

norm_inf :: Rec f (a ': []) -> c Source #

norm_0 :: Rec f (a ': []) -> c Source #

norm_1 :: Rec f (a ': []) -> c Source #

norm_2 :: Rec f (a ': []) -> c Source #

quadrance :: Rec f (a ': []) -> c Source #

(Metric c a, Metric c b, Metric c d, Ord c, Floating c) => Metric c (a, b, d) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(<.>) :: (a, b, d) -> (a, b, d) -> c Source #

norm_inf :: (a, b, d) -> c Source #

norm_0 :: (a, b, d) -> c Source #

norm_1 :: (a, b, d) -> c Source #

norm_2 :: (a, b, d) -> c Source #

quadrance :: (a, b, d) -> c Source #

(Floating a, Ord a, Vector v a, KnownNat n) => Metric a (Vector v n a) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(<.>) :: Vector v n a -> Vector v n a -> a Source #

norm_inf :: Vector v n a -> a Source #

norm_0 :: Vector v n a -> a Source #

norm_1 :: Vector v n a -> a Source #

norm_2 :: Vector v n a -> a Source #

quadrance :: Vector v n a -> a Source #

(Metric c a, Metric c b, Metric c d, Metric c e, Ord c, Floating c) => Metric c (a, b, d, e) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(<.>) :: (a, b, d, e) -> (a, b, d, e) -> c Source #

norm_inf :: (a, b, d, e) -> c Source #

norm_0 :: (a, b, d, e) -> c Source #

norm_1 :: (a, b, d, e) -> c Source #

norm_2 :: (a, b, d, e) -> c Source #

quadrance :: (a, b, d, e) -> c Source #

(Metric c a, Metric c b, Metric c d, Metric c e, Metric c f, Ord c, Floating c) => Metric c (a, b, d, e, f) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(<.>) :: (a, b, d, e, f) -> (a, b, d, e, f) -> c Source #

norm_inf :: (a, b, d, e, f) -> c Source #

norm_0 :: (a, b, d, e, f) -> c Source #

norm_1 :: (a, b, d, e, f) -> c Source #

norm_2 :: (a, b, d, e, f) -> c Source #

quadrance :: (a, b, d, e, f) -> c Source #

RealFloat a => Metric (Complex a) (Complex a) Source # 
Instance details

Defined in Numeric.Opto.Update

gDot :: forall c a. (ADT a, Constraints a (Metric c), Num c) => a -> a -> c Source #

An implementation of gDot that works for records where every field is an instance of Metric c.

gNorm_inf :: forall c a. (ADT a, Constraints a (Metric c), Ord c) => a -> c Source #

An implementation of norm_inf that works for records where every field is an instance of Metric c.

gNorm_0 :: forall c a. (ADT a, Constraints a (Metric c), Num c) => a -> c Source #

An implementation of norm_0 that works for records where every field is an instance of Metric c.

gNorm_1 :: forall c a. (ADT a, Constraints a (Metric c), Num c) => a -> c Source #

An implementation of norm_1 that works for records where every field is an instance of Metric c.

gNorm_2 :: forall c a. (ADT a, Constraints a (Metric c), Floating c) => a -> c Source #

An implementation of norm_2 that works for records where every field is an instance of Metric c.

gQuadrance :: forall c a. (ADT a, Constraints a (Metric c), Num c) => a -> c Source #

An implementation of quadrance that works for records where every field is an instance of Metric c.

class (Mutable m a, Linear c a) => LinearInPlace m c a where Source #

Instaces of Linear that support certain in-place mutations. Inspired by the BLAS Level 1 API. A LinearInPlace m v c a means that v is a mutable reference to an a that can be updated as an action in monad m.

Minimal complete definition

Nothing

Methods

(.+.=) :: Ref m a -> a -> m () infix 4 Source #

Add a value in-place.

(.*=) :: Ref m a -> c -> m () infix 4 Source #

Scale a value in-place.

(.*+=) :: Ref m a -> (c, a) -> m () infix 4 Source #

Add a scaled value in-place.

Instances
Mutable m Double => LinearInPlace m Double Double Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.=) :: Ref m Double -> Double -> m () Source #

(.*=) :: Ref m Double -> Double -> m () Source #

(.*+=) :: Ref m Double -> (Double, Double) -> m () Source #

Mutable m Float => LinearInPlace m Float Float Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.=) :: Ref m Float -> Float -> m () Source #

(.*=) :: Ref m Float -> Float -> m () Source #

(.*+=) :: Ref m Float -> (Float, Float) -> m () Source #

Mutable m Rational => LinearInPlace m Rational Rational Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.=) :: Ref m Rational -> Rational -> m () Source #

(.*=) :: Ref m Rational -> Rational -> m () Source #

(.*+=) :: Ref m Rational -> (Rational, Rational) -> m () Source #

Mutable m Integer => LinearInPlace m Integer Integer Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.=) :: Ref m Integer -> Integer -> m () Source #

(.*=) :: Ref m Integer -> Integer -> m () Source #

(.*+=) :: Ref m Integer -> (Integer, Integer) -> m () Source #

Mutable m Int => LinearInPlace m Int Int Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.=) :: Ref m Int -> Int -> m () Source #

(.*=) :: Ref m Int -> Int -> m () Source #

(.*+=) :: Ref m Int -> (Int, Int) -> m () Source #

(PrimMonad m, KnownNat n) => LinearInPlace m Double (R n) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.=) :: Ref m (R n) -> R n -> m () Source #

(.*=) :: Ref m (R n) -> Double -> m () Source #

(.*+=) :: Ref m (R n) -> (Double, R n) -> m () Source #

(Mutable m (a, b), Linear c a, Linear c b) => LinearInPlace m c (a, b) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.=) :: Ref m (a, b) -> (a, b) -> m () Source #

(.*=) :: Ref m (a, b) -> c -> m () Source #

(.*+=) :: Ref m (a, b) -> (c, (a, b)) -> m () Source #

(PrimMonad m, KnownNat n, KnownNat k) => LinearInPlace m Double (L n k) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.=) :: Ref m (L n k) -> L n k -> m () Source #

(.*=) :: Ref m (L n k) -> Double -> m () Source #

(.*+=) :: Ref m (L n k) -> (Double, L n k) -> m () Source #

(LinearInPlace m c (f a), LinearInPlace m c (Rec f (b ': bs))) => LinearInPlace m c (Rec f (a ': (b ': bs))) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.=) :: Ref m (Rec f (a ': (b ': bs))) -> Rec f (a ': (b ': bs)) -> m () Source #

(.*=) :: Ref m (Rec f (a ': (b ': bs))) -> c -> m () Source #

(.*+=) :: Ref m (Rec f (a ': (b ': bs))) -> (c, Rec f (a ': (b ': bs))) -> m () Source #

LinearInPlace m c (f a) => LinearInPlace m c (Rec f (a ': ([] :: [Type]))) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.=) :: Ref m (Rec f (a ': [])) -> Rec f (a ': []) -> m () Source #

(.*=) :: Ref m (Rec f (a ': [])) -> c -> m () Source #

(.*+=) :: Ref m (Rec f (a ': [])) -> (c, Rec f (a ': [])) -> m () Source #

(Mutable m (a, b, d), Linear c a, Linear c b, Linear c d) => LinearInPlace m c (a, b, d) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.=) :: Ref m (a, b, d) -> (a, b, d) -> m () Source #

(.*=) :: Ref m (a, b, d) -> c -> m () Source #

(.*+=) :: Ref m (a, b, d) -> (c, (a, b, d)) -> m () Source #

(PrimMonad m, PrimState m ~ s, Num a, mv ~ Mutable v, Vector v a, KnownNat n) => LinearInPlace m a (Vector v n a) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.=) :: Ref m (Vector v n a) -> Vector v n a -> m () Source #

(.*=) :: Ref m (Vector v n a) -> a -> m () Source #

(.*+=) :: Ref m (Vector v n a) -> (a, Vector v n a) -> m () Source #

(Mutable m (a, b, d, e), Linear c a, Linear c b, Linear c d, Linear c e) => LinearInPlace m c (a, b, d, e) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.=) :: Ref m (a, b, d, e) -> (a, b, d, e) -> m () Source #

(.*=) :: Ref m (a, b, d, e) -> c -> m () Source #

(.*+=) :: Ref m (a, b, d, e) -> (c, (a, b, d, e)) -> m () Source #

(Mutable m (a, b, d, e, f), Linear c a, Linear c b, Linear c d, Linear c e, Linear c f) => LinearInPlace m c (a, b, d, e, f) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.=) :: Ref m (a, b, d, e, f) -> (a, b, d, e, f) -> m () Source #

(.*=) :: Ref m (a, b, d, e, f) -> c -> m () Source #

(.*+=) :: Ref m (a, b, d, e, f) -> (c, (a, b, d, e, f)) -> m () Source #

(Mutable m (Complex a), RealFloat a) => LinearInPlace m (Complex a) (Complex a) Source # 
Instance details

Defined in Numeric.Opto.Update

Methods

(.+.=) :: Ref m (Complex a) -> Complex a -> m () Source #

(.*=) :: Ref m (Complex a) -> Complex a -> m () Source #

(.*+=) :: Ref m (Complex a) -> (Complex a, Complex a) -> m () Source #

sumLinearInPlace :: (LinearInPlace m c a, Foldable t) => Ref m a -> t a -> m () Source #

Given some starting reference v, add every item in a foldable container into that reference in-place.

linearWit :: forall a c d. (Linear c a, Linear d a) => c :~: d Source #

If a and b are both Linear instances, then if a is equal to b, their scalars c and d must also be equal. This is necessary because GHC isn't happy with the functional dependency for some reason.