Jump to content

File:Gaussianprocess posterior.svg

Page contents not supported in other languages.
This is a file from the Wikimedia Commons
From Wikibooks, open books for an open world

Original file (SVG file, nominally 360 × 180 pixels, file size: 43 KB)

Summary

Description
English: Posterior gaussian process visualized by random samples
Date
Source Own work
Author Physikinger
SVG development
InfoField
 
The SVG code is valid.
 
This plot was created with Matplotlib.
Source code
InfoField

Python code

#This source code is public domain 
#Author: Christian Schirm
import numpy, scipy.spatial
import matplotlib.pyplot as plt
def covMat(x1, x2, covFunc, noise=0):  # Covariance matrix
    cov = covFunc(scipy.spatial.distance_matrix(numpy.atleast_2d(x1).T, numpy.atleast_2d(x2).T))
    if noise: cov += numpy.diag(numpy.ones(len(cov))*noise)
    return cov

def interpol(x_known, y_known, x_unknown, covFunc, noise=0, sigmaPrior=1):
    Ckk = covMat(x_known, x_known, covFunc)
    Cuk = covMat(x_unknown, x_known, covFunc, noise=0)
    y_unknown = numpy.dot(Cuk, numpy.dot(numpy.linalg.inv(Ckk), y_known)) 
    CkkInv = numpy.linalg.inv(Ckk)
    sigma_unknown = numpy.sqrt(sigmaPrior * sigmaPrior - numpy.diag(numpy.dot(Cuk, numpy.dot(CkkInv, Cuk.T))))
    return y_unknown, sigma_unknown
    
covFunc = lambda d: numpy.exp(-(d**1.9/8.)) # Covariance function

x_known = numpy.array([2,3,7])
y_known = numpy.array([-1,0,1])
x_unknown = numpy.linspace(0, 10, 300)
y_unknown, sigma_unknown = interpol(x_known, y_known, x_unknown, covFunc)    

Ckk = covMat(x_known, x_known, covFunc, noise=0.0)
Cuu = covMat(x_unknown, x_unknown, covFunc, noise=0.00)
CkkInv = numpy.linalg.inv(Ckk)
Cuk = covMat(x_unknown, x_known, covFunc, noise=0)
m = 0 #numpy.mean(y)
covPost = Cuu - numpy.dot(numpy.dot(Cuk,CkkInv),Cuk.T)
y_unknown = numpy.dot(numpy.dot(Cuk,CkkInv),y_known)
fig = plt.figure(figsize=(4.0,2))
for i in range(8):
    y_random = numpy.random.multivariate_normal(x_unknown.ravel()*0, covPost)
    plt.plot(x_unknown, y_unknown + y_random,  label=u'Prediction')
sigma = numpy.sqrt(numpy.diag(covPost))
plt.plot(x_known, y_known,'ko')
plt.axis([0,10,-3,3])
plt.savefig('Gaussianprocess_posterior.svg')

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

21 August 2017

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current14:09, 25 February 2018Thumbnail for version as of 14:09, 25 February 2018360 × 180 (43 KB)PhysikingerWithout confidence interval
14:08, 25 February 2018Thumbnail for version as of 14:08, 25 February 2018360 × 180 (43 KB)PhysikingerWithout confidence interval
21:56, 21 August 2017Thumbnail for version as of 21:56, 21 August 2017360 × 180 (59 KB)PhysikingerUser created page with UploadWizard

The following page uses this file:

Global file usage

The following other wikis use this file:

Metadata