-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_py.py
44 lines (31 loc) · 1.08 KB
/
test_py.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# For checking that importing the model with R dependency works ok
from GPConstr.model import GPmodel, Constraint
from GPConstr.kern import kernel_RBF
import pyDOE
import numpy as np
# Function to emulate
def fun(x1, x2):
return (x1*2)**2 + np.sin(x2*5)
# Define a model and print it
def main():
print('testing..')
# Design data
n_samples = 5
x_design = pyDOE.lhs(2, samples = n_samples, criterion = 'maximin', iterations = 1000)
y_design = np.array([fun(x[0], x[1]) for x in x_design])
# Initial parameters
gp_mean = 0 # Constant mean function
gp_likelihood = 0.000001 # Gaussian noise
kernel_variance = 1
kernel_lengthscale = [1, 1]
# Set up model
ker = kernel_RBF(variance = kernel_variance, lengthscale = kernel_lengthscale)
model = GPmodel(kernel = ker, likelihood = gp_likelihood, mean = gp_mean)
# Training data
model.X_training = x_design
model.Y_training = y_design
# Optimize
model.optimize(include_constraint = False, fix_likelihood = True)
print(model)
if __name__ == "__main__":
main()