Introduction

Kriging is an invaluable tool in understanding the behavior of sparse data. It has proven effective in many aspects of engineering and in applications where data is "expensive", or difficult, to collect.

For information on how the math behind Kriging works, please refer to these excellent sources:

The goal of this toolbox is to make Kriging easily accessible in Python. The module is constant development, so please check back occasionally to see progress. If you encounter any problems, please report them on the Github Issue tracker.

Installation

Installation is simple! Install pyKriging with pip:

sudo pip install pykriging

To verify that everything has installed properly, try the following command at a command line prompt:

python -c 'import pyKriging'

If no errors turn up, pyKriging is ready to run. For plotting above two design variables, you'll also need MayaVI2 installed on your system.

Using pyKriging

pyKriging was designed to simply the process of creating surrogate models. The following example demonstrates how to create a sampling plan, evaluate a test function at those locations, create and train a Kriging model and add infill points to reduce the models Mean Squared Error (MSE).

import pyKriging  
from pyKriging.krige import kriging  
from pyKriging.samplingplan import samplingplan

# The Kriging model starts by defining a sampling plan, we use an optimal Latin Hypercube here
sp = samplingplan(2)  
X = sp.optimallhc(20)

# Next, we define the problem we would like to solve
testfun = pyKriging.testfunctions().branin  
y = testfun(X)

# Now that we have our initial data, we can create an instance of a Kriging model
k = kriging(X, y, testfunction=testfun, name='simple')  
k.train()

# Now, five infill points are added. Note that the model is re-trained after each point is added
numiter = 5  
for i in range(numiter):  
    print 'Infill iteration {0} of {1}....'.format(i + 1, numiter)
    newpoints = k.infill(1)
    for point in newpoints:
        k.addPoint(point, testfun(point)[0])
    k.train()

# And plot the results
k.plot()  

The result of this script should produce the following output. Your model may vary slightly, as pyKriging extensively uses Stochastic optimization to build these models.
An Example Model

Capabilities

Hypervolume Kriging Model Construction

pyKriging provides n-dimensional Kriging. Plotting facilities are included for 2D and 3D models (with MayaVI installed).

Automated Model Infill

Once an initial model is trained, pyKriging can recommend where your next sample should be placed in order to improve the model. pyKriging supports infill selection based a search for the maximum Mean Squared Error (MSE) or based on Expected Improvement. Mean squared error seeks to improve the overall accuracy of the model. Expected Improvement explores the likely minimums of the model, which is useful in many optimization activities. Please see the examples directory in the Github repository of examples on using the two types of model infill.

MSE Error Infill

Example infill based on MSE search

Expected Improvement Infill Example

Example infill based on an Expected Improvement search

Training History

The Snapshot feature allows for the monitoring of the Kriging training process. This allows a user to plot hyperparameter convergence, prediction accuracy (if an analytical function is provided) and prediction convergence. Please see the Github examples folder for more information on using the training history function.

Planned Improvements
  • Co-Kriging
  • Speed Improvement
  • Multi-processor support for training
  • Optimization tools for model exploitation