Copyright | (c) Edward Kmett 2015 |
---|---|

License | BSD3 |

Maintainer | ekmett@gmail.com |

Stability | experimental |

Portability | GHC only |

Safe Haskell | None |

Language | Haskell2010 |

- findZero :: (forall s. AD s ForwardDouble -> AD s ForwardDouble) -> Double -> [Double]
- inverse :: (forall s. AD s ForwardDouble -> AD s ForwardDouble) -> Double -> Double -> [Double]
- fixedPoint :: (forall s. AD s ForwardDouble -> AD s ForwardDouble) -> Double -> [Double]
- extremum :: (forall s. AD s (On (Forward ForwardDouble)) -> AD s (On (Forward ForwardDouble))) -> Double -> [Double]
- conjugateGradientDescent :: Traversable f => (forall s. Chosen s => f (Or s (On (Forward ForwardDouble)) (Kahn Double)) -> Or s (On (Forward ForwardDouble)) (Kahn Double)) -> f Double -> [f Double]
- conjugateGradientAscent :: Traversable f => (forall s. Chosen s => f (Or s (On (Forward ForwardDouble)) (Kahn Double)) -> Or s (On (Forward ForwardDouble)) (Kahn Double)) -> f Double -> [f Double]

# Newton's Method (Forward AD)

findZero :: (forall s. AD s ForwardDouble -> AD s ForwardDouble) -> Double -> [Double] Source

The `findZero`

function finds a zero of a scalar function using
Newton's method; its output is a stream of increasingly accurate
results. (Modulo the usual caveats.) If the stream becomes constant
("it converges"), no further elements are returned.

Examples:

`>>>`

[1.0,2.5,2.05,2.000609756097561,2.0000000929222947,2.000000000000002,2.0]`take 10 $ findZero (\x->x^2-4) 1`

inverse :: (forall s. AD s ForwardDouble -> AD s ForwardDouble) -> Double -> Double -> [Double] Source

The `inverse`

function inverts a scalar function using
Newton's method; its output is a stream of increasingly accurate
results. (Modulo the usual caveats.) If the stream becomes
constant ("it converges"), no further elements are returned.

Example:

`>>>`

10.0`last $ take 10 $ inverse sqrt 1 (sqrt 10)`

fixedPoint :: (forall s. AD s ForwardDouble -> AD s ForwardDouble) -> Double -> [Double] Source

The `fixedPoint`

function find a fixedpoint of a scalar
function using Newton's method; its output is a stream of
increasingly accurate results. (Modulo the usual caveats.)

If the stream becomes constant ("it converges"), no further elements are returned.

`>>>`

0.7390851332151607`last $ take 10 $ fixedPoint cos 1`

extremum :: (forall s. AD s (On (Forward ForwardDouble)) -> AD s (On (Forward ForwardDouble))) -> Double -> [Double] Source

The `extremum`

function finds an extremum of a scalar
function using Newton's method; produces a stream of increasingly
accurate results. (Modulo the usual caveats.) If the stream
becomes constant ("it converges"), no further elements are returned.

`>>>`

0.0`last $ take 10 $ extremum cos 1`

# Gradient Ascent/Descent (Reverse AD)

conjugateGradientDescent :: Traversable f => (forall s. Chosen s => f (Or s (On (Forward ForwardDouble)) (Kahn Double)) -> Or s (On (Forward ForwardDouble)) (Kahn Double)) -> f Double -> [f Double] Source

Perform a conjugate gradient descent using reverse mode automatic differentiation to compute the gradient, and using forward-on-forward mode for computing extrema.

`>>>`

`let sq x = x * x`

`>>>`

`let rosenbrock [x,y] = sq (1 - x) + 100 * sq (y - sq x)`

`>>>`

1`rosenbrock [0,0]`

`>>>`

True`rosenbrock (conjugateGradientDescent rosenbrock [0, 0] !! 5) < 0.1`

conjugateGradientAscent :: Traversable f => (forall s. Chosen s => f (Or s (On (Forward ForwardDouble)) (Kahn Double)) -> Or s (On (Forward ForwardDouble)) (Kahn Double)) -> f Double -> [f Double] Source

Perform a conjugate gradient ascent using reverse mode automatic differentiation to compute the gradient.