fastmath.gp

Gaussian Processes

See more here

gaussian-process

(gaussian-process xss ys)(gaussian-process xss ys {:keys [kscale kernel noise normalize? L?], :or {kscale 1.0, kernel (k/kernel :gaussian 1.0), normalize? false, noise 1.0E-8, L? true}})

Examples

Object creation

(gaussian-process [1 2 3] [-1 2 1])
;;=> fastmath.gp.GaussianProcess@7860dc0e
(gaussian-process [1 2 3]
                  [-1 2 1]
                  {:normalize? true,
                   :kernel (k/kernel :gaussian 0.5),
                   :kscale 2.0,
                   :noise 0.1})
;;=> fastmath.gp.GaussianProcess@4cee1580

L

(L ys w chol n)(L gp-object)

posterior-samples

(posterior-samples gp-object xvals)(posterior-samples gp-object xvals stddev?)

Examples

With gaussian kernel

(let [gp (gaussian-process [-5 1 2]
                           [17 10 12]
                           {:kernel (k/kernel :gaussian 0.5)})]
  (posterior-samples gp (range -5 2 0.9)))
;;=> (16.999884359640117
;;=>  3.1208039260060736
;;=>  0.0765520018114407
;;=>  -0.5522472618655202
;;=>  -0.33565663425825365
;;=>  1.6468976690043093
;;=>  4.983383079352442
;;=>  10.567358405881329)

Plot of 10 posteriors (with gaussian kernel)

With periodic kernel

(let [gp (gaussian-process [-5 1 2]
                           [17 10 12]
                           {:kernel (k/kernel :periodic 0.2 6.5)})]
  (posterior-samples gp (range -5 2 0.9)))
;;=> (17.000057569911778
;;=>  1.8683865502451709
;;=>  0.4018489935338301
;;=>  0.12330897258784282
;;=>  0.1178539023717543
;;=>  0.5093262455624785
;;=>  -0.33890970733205694
;;=>  13.305376406992414)

Plot of 10 posteriors (with periodic kernel)

predict

(predict gp-object xval)(predict gp-object xval stddev?)

Examples

Usage

(let [gp (gaussian-process [-5 1 2] [17 10 12])]
  [(gp 1.1) (predict gp 1.1)])
;;=> [10.546027301365227 10.546027301365227]

Predict and return standard deviation

(let [gp (gaussian-process [-5 1 2] [17 10 12])]
  [(gp 1.1 true) (predict gp 1.1 true)])
;;=> [[10.546027301365227 0.05980825454330318]
;;=>  [10.546027301365227 0.05980825454330318]]

Gaussian process with confidence intervals

Predict and return standard deviation for normalized process

(let [gp (gaussian-process [-5 1 2] [17 10 12] {:normalize? true})]
  [(gp 1.1 true) (predict gp 1.1 true)])
;;=> [[10.09725781658689 0.2156417284518817]
;;=>  [10.09725781658689 0.2156417284518817]]

Gaussian process with confidence intervals for normalized process

predict-all

(predict-all gp-object xvals)(predict-all gp-object xvals stddev?)

Examples

Usage

(let [gp (gaussian-process [-5 1 2] [17 10 12])]
  (predict-all gp [-5 -2 1 2 3]))
;;=> (16.999999829999997
;;=>  0.23983287597866382
;;=>  9.99999995694442
;;=>  11.999999906114532
;;=>  6.277135459489308)

Predict and return standard deviation

(let [gp (gaussian-process [-5 1 2] [17 10 12])]
  (predict-all gp [-5 -2 1 2 3] true))
;;=> ([16.999999829999997 9.999999969612645E-5]
;;=>  [0.23983287597866382 0.9998441540162327]
;;=>  [9.99999995694442 9.999999858590342E-5]
;;=>  [11.999999906114532 9.99999980307919E-5]
;;=>  [6.277135459489308 0.739305317305734])

prior-samples

(prior-samples gp-object xvals)

Examples

Usage

(let [gp (gaussian-process [0 1 -2 -2.001] [-2 3 0.5 -0.6])]
  (prior-samples gp (range 0 1 0.1)))
;;=> (-0.792983868612105
;;=>  -0.6778147362568855
;;=>  -0.5444855711770306
;;=>  -0.39524525991973797
;;=>  -0.2333700621293956
;;=>  -0.06280864555710398
;;=>  0.1122325565000701
;;=>  0.28770104917887485
;;=>  0.46004918213031654
;;=>  0.6264783531606577
;;=>  0.7850508460072277)

Plot of 10 priors

With added noise

(let [gp
      (gaussian-process [0 1 -2 -2.001] [-2 3 0.5 -0.6] {:noise 0.1})]
  (prior-samples gp (range 0 1 0.1)))
;;=> (1.618775231635548
;;=>  1.6996793940243753
;;=>  1.7789859925516815
;;=>  1.8530283478463896
;;=>  1.9184179959440781
;;=>  1.9723383193987132
;;=>  2.0127647549733356
;;=>  2.0385803980887585
;;=>  2.0495734736475284
;;=>  2.046323665069238
;;=>  2.0300035786626176)

Plot of 10 priors (with noise)