ad-4.3.1: Automatic Differentiation

Copyright (c) Edward Kmett 2015 BSD3 ekmett@gmail.com experimental GHC only None Haskell2010

Numeric.AD.Newton.Double

Description

Synopsis

# 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:

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

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:

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

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.

````>>> ````last \$ take 10 \$ fixedPoint cos 1
```0.7390851332151607
```

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.

````>>> ````last \$ take 10 \$ extremum cos 1
```0.0
```

# 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)
````>>> ````rosenbrock [0,0]
```1
`>>> ````rosenbrock (conjugateGradientDescent rosenbrock [0, 0] !! 5) < 0.1
```True
```

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.