Ariadne


Quick how-to

This page provides a very brief overview of main functions available in Ariadne for Gaussian process regression.

First step is to download Ariadne from NuGet and load it into F# interactive. We will also define some data in the Gaussian process format. The rest of this document shows how to do specific tasks with Gaussian processes.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
#r "Ariadne.dll"
#r "MathNet.Numerics.dll"
open Ariadne
open Ariadne.GaussianProcess
open Ariadne.Kernels
open Ariadne.Optimization

let data = 
  [{Locations = (...)
    Observations = (...) }]

Create covariance function (kernel)

1: 
2: 
3: 
4: 
5: 
let lengthscale = 3.0
let signalVariance = 15.0
let noiseVariance = 1.0

let sqExp = SquaredExp.SquaredExp(lengthscale, signalVariance, noiseVariance)

Create Gaussian process with a covariance function

1: 
2: 
3: 
4: 
5: 
// method 1
let gp1 = GaussianProcess(sqExp.Kernel, Some sqExp.NoiseVariance)

// method 2
let gp2 = sqExp.GaussianProcess()

Compute log likelihood

1: 
let loglik = gp1.LogLikelihood data

Use Metropolis-Hastings to find values for hyperparameters

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
open MathNet.Numerics

// specify prior distribution
let lengthscalePrior = Distributions.LogNormal.WithMeanVariance(2.0, 4.0)
let variancePrior = Distributions.LogNormal.WithMeanVariance(1.0, 5.0)
let noisePrior = Distributions.LogNormal.WithMeanVariance(0.5, 1.0)
let prior = SquaredExp.Prior(lengthscalePrior, variancePrior, noisePrior)

// get posterior mean values for hyperparameters
let sqExpMH = 
    sqExp
    |> SquaredExp.optimizeMetropolis data MetropolisHastings.defaultSettings prior

Use gradient descent to find values for hyperparameters

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
let settings = 
    { GradientDescent.Iterations = 10000; 
      GradientDescent.StepSize = 0.01}

let gradientFunction parameters = SquaredExp.fullGradient data parameters

// Run gradient descent
let sqExpGD = 
    gradientDescent gradientFunction settings (sqExp.Parameters)
    |> SquaredExp.ofParameters

Compute prediction for new time points (locations)

1: 
2: 
let allYears = [| 1985.0 .. 2015.0 |]
let predictValues, predictVariance = allYears |> gp1.Predict data

Compute predictive log likelihood for new observed data

1: 
2: 
3: 
4: 
let newObservation = {
    Locations = [| 2015.0 |]; Observations = [| 10.0 |]}

let predictiveLoglik = gp1.PredictiveLogLikelihood data newObservation

Plot the fitted Gaussian process

1: 
2: 
3: 
4: 
#r "FSharp.Charting.dll"

GaussianProcess.plot data gp1
GaussianProcess.plotRange (1980.0, 2020.0) data gp1
namespace Ariadne
module GaussianProcess

from Ariadne
module Kernels

from Ariadne
module Optimization

from Ariadne
val data : Observation<float> list

Full name: Howto.data
[|1988.0; 1993.0; 1996.0; 1999.0; 2001.0; 2002.0; 2003.0; 2004.0; 2005.0;
       2006.0; 2007.0; 2008.0; 2009.0|];
[|-15.52307692; 9.056923077; 6.786923077; -1.843076923; 0.2769230769;
       -3.623076923; -2.063076923; -2.183076923; -1.813076923; 2.806923077;
       4.386923077; 2.946923077; 0.7869230769|];
val lengthscale : float

Full name: Howto.lengthscale
val signalVariance : float

Full name: Howto.signalVariance
val noiseVariance : float

Full name: Howto.noiseVariance
val sqExp : SquaredExp.SquaredExp

Full name: Howto.sqExp
Multiple items
module SquaredExp

from Ariadne.Optimization

--------------------
module SquaredExp

from Ariadne.Kernels
Multiple items
type SquaredExp =
  new : lengthscale:float * signalVariance:float * noiseVariance:float -> SquaredExp
  member GaussianProcess : unit -> GaussianProcess<float>
  member Kernel : x1:float * x2:float -> float
  override ToString : unit -> string
  member Lengthscale : float
  member NoiseVariance : float
  member Parameters : float []
  member SignalVariance : float

Full name: Ariadne.Kernels.SquaredExp.SquaredExp

--------------------
new : lengthscale:float * signalVariance:float * noiseVariance:float -> SquaredExp.SquaredExp
val gp1 : GaussianProcess<float>

Full name: Howto.gp1
Multiple items
module GaussianProcess

from Ariadne

--------------------
type GaussianProcess<'T> =
  new : covariance:Kernel<'T> * noiseVariance:float option -> GaussianProcess<'T>
  new : covariance:Kernel<'T> * meanFunction:MeanFunction * noiseVariance:float option -> GaussianProcess<'T>
  member LogLikelihood : data:seq<Observation<'T>> -> float
  member PosteriorGaussianProcess : data:seq<Observation<'T>> -> newLocations:'T [] -> Vector<float> * Matrix<float>
  member Predict : data:seq<Observation<'T>> -> newLocations:'T [] -> float [] * float []
  member PredictiveLogLikelihood : data:seq<Observation<'T>> -> x:Observation<'T> -> float
  member Covariance : Kernel<'T>
  member Mean : MeanFunction
  member NoiseVariance : float option

Full name: Ariadne.GaussianProcess.GaussianProcess<_>

--------------------
new : covariance:Kernel<'T> * noiseVariance:float option -> GaussianProcess<'T>
new : covariance:Kernel<'T> * meanFunction:MeanFunction * noiseVariance:float option -> GaussianProcess<'T>
member SquaredExp.SquaredExp.Kernel : x1:float * x2:float -> float
union case Option.Some: Value: 'T -> Option<'T>
property SquaredExp.SquaredExp.NoiseVariance: float
val gp2 : GaussianProcess<float>

Full name: Howto.gp2
member SquaredExp.SquaredExp.GaussianProcess : unit -> GaussianProcess<float>
val loglik : float

Full name: Howto.loglik
member GaussianProcess.LogLikelihood : data:seq<Observation<'T>> -> float
namespace MathNet
namespace MathNet.Numerics
val lengthscalePrior : Distributions.LogNormal

Full name: Howto.lengthscalePrior
namespace MathNet.Numerics.Distributions
Multiple items
type LogNormal =
  new : mu:float * sigma:float -> LogNormal + 1 overload
  member CumulativeDistribution : x:float -> float
  member Density : x:float -> float
  member DensityLn : x:float -> float
  member Entropy : float
  member InverseCumulativeDistribution : p:float -> float
  member Maximum : float
  member Mean : float
  member Median : float
  member Minimum : float
  ...

Full name: MathNet.Numerics.Distributions.LogNormal

--------------------
Distributions.LogNormal(mu: float, sigma: float) : unit
Distributions.LogNormal(mu: float, sigma: float, randomSource: System.Random) : unit
Distributions.LogNormal.WithMeanVariance(mean: float, var: float, ?randomSource: System.Random) : Distributions.LogNormal
val variancePrior : Distributions.LogNormal

Full name: Howto.variancePrior
val noisePrior : Distributions.LogNormal

Full name: Howto.noisePrior
val prior : SquaredExp.Prior

Full name: Howto.prior
Multiple items
type Prior =
  new : lengthscalePrior:LogNormal * signalVariancePrior:LogNormal * noiseVariancePrior:LogNormal -> Prior
  member DensityLn : se:SquaredExp -> float
  member ParamsDensityLn : parameters:float [] -> float
  member Sample : unit -> SquaredExp
  member LengthscalePrior : LogNormal
  member NoiseVariancePrior : LogNormal
  member SignalVariancePrior : LogNormal

Full name: Ariadne.Kernels.SquaredExp.Prior

--------------------
new : lengthscalePrior:Distributions.LogNormal * signalVariancePrior:Distributions.LogNormal * noiseVariancePrior:Distributions.LogNormal -> SquaredExp.Prior
val sqExpMH : SquaredExp.SquaredExp

Full name: Howto.sqExpMH
val optimizeMetropolis : data:seq<Observation<float>> -> settings:MetropolisHastings.Settings -> prior:SquaredExp.Prior -> initialKernel:SquaredExp.SquaredExp -> SquaredExp.SquaredExp

Full name: Ariadne.Optimization.SquaredExp.optimizeMetropolis
module MetropolisHastings

from Ariadne.Optimization
val defaultSettings : MetropolisHastings.Settings

Full name: Ariadne.Optimization.MetropolisHastings.defaultSettings
val settings : GradientDescent.Settings

Full name: Howto.settings
module GradientDescent

from Ariadne.Optimization
val gradientFunction : parameters:float [] -> float []

Full name: Howto.gradientFunction
val parameters : float []
val fullGradient : data:seq<Observation<float>> -> parameters:float [] -> float []

Full name: Ariadne.Kernels.SquaredExp.fullGradient
val sqExpGD : SquaredExp.SquaredExp

Full name: Howto.sqExpGD
val gradientDescent : gradientFun:(Parameters -> Parameters) -> settings:GradientDescent.Settings -> initialLocation:Parameters -> float []

Full name: Ariadne.Optimization.gradientDescent
property SquaredExp.SquaredExp.Parameters: float []
val ofParameters : parameters:seq<float> -> SquaredExp.SquaredExp

Full name: Ariadne.Kernels.SquaredExp.ofParameters
val allYears : float []

Full name: Howto.allYears
val predictValues : float []

Full name: Howto.predictValues
val predictVariance : float []

Full name: Howto.predictVariance
member GaussianProcess.Predict : data:seq<Observation<'T>> -> newLocations:'T [] -> float [] * float []
val newObservation : Observation<float>

Full name: Howto.newObservation
val predictiveLoglik : float

Full name: Howto.predictiveLoglik
member GaussianProcess.PredictiveLogLikelihood : data:seq<Observation<'T>> -> x:Observation<'T> -> float
val plot : data:seq<Observation<float>> -> gp:GaussianProcess<float> -> FSharp.Charting.ChartTypes.GenericChart

Full name: Ariadne.GaussianProcess.plot
val plotRange : timeMin:float * timeMax:float -> data:seq<Observation<float>> -> gp:GaussianProcess<float> -> FSharp.Charting.ChartTypes.GenericChart

Full name: Ariadne.GaussianProcess.plotRange
Fork me on GitHub