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')  

# 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])

# And plot the results

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