3. Tutorial

In this section, code snippets showing how to use SURF are presented for quick start. A more detailed example can be found in Verification and Validation, in which there is a jupyter notebook that can run in Google Colab.

3.1. Neural network

The example below shows how to train a neural network on a data set, and use it to predict.

from surf.NN import SpatialNeuralNet

#---------------------------------------
# 1. Prepare your data
#---------------------------------------

data = load your data here
# data is a numpy matrix with columns: [x,y,value]
# ... see SURF.ET-AI.py for an example:
# https://github.com/NHERI-SimCenter/SURF/blob/master/examples/demo-NN.py

#---------------------------------------
# 2. Train the neural network
#---------------------------------------

# define a spatial neural network
# numNei is the number of nearest neighbors to be considered
nn = SpatialNeuralNet(rawData = data, numNei = 20)

# create a neural network that can take information of numNei points as input
nn.build_model()

# this trains the neural network on rawData
nn.train()

#---------------------------------------
# 3. Predict
#---------------------------------------

# define a point located at (x,y)
unkown_point = [x, y]

# predict a value at the unkown_point
predicted = nn.predict(unkown_point)

3.2. Random field

The example below shows how to define a spatial model for a data set, and insert it into random field to predict.

from surf.rf import SK
import surf.spatialModel as m

#---------------------------------------
# 1. Prepare your data
#---------------------------------------

data = load your data here
# data is a numpy matrix with columns: [x,y,value]
# ... see SURF.ET.py for an example:
# https://github.com/NHERI-SimCenter/SURF/blob/master/examples/demo-NN.py

#---------------------------------------
# 2. Define spatial model
#---------------------------------------

# correlation length
colLength = 0.1

# sill of the semivariogram
sill = np.var( data[:,2] )

# cov is covariance function;
# exponential means using exponential as the covariance function
cov = m.cov( m.exponential, ( colLength, sill ) )

#---------------------------------------
# 3. Predict
#---------------------------------------

# define a point located at (x,y)
unkown_point = [x, y]

# predict a value at the unkown_point
# N is the number of nearest neighbors to depend on
predicted_mu, predicted_std = SK( data, cov, unkown_point, N=100 )