MCPcopy
hub / github.com/GPflow/GPflow / _prepare_models

Function _prepare_models

tests/gpflow/kernels/test_coregion.py:59–126  ·  view source on GitHub ↗

Prepare models to make sure the coregionalized model with diagonal coregion kernel and with fixed lengthscales is equivalent with normal GP regression.

()

Source from the content-addressed store, hash-verified

57
58
59def _prepare_models() -> Tuple[VGP, VGP, VGP]:
60 """
61 Prepare models to make sure the coregionalized model with diagonal coregion kernel and
62 with fixed lengthscales is equivalent with normal GP regression.
63 """
64 # 1. Two independent VGPs for two sets of data
65 k0 = gpflow.kernels.SquaredExponential()
66 set_trainable(k0.lengthscales, False)
67 k1 = gpflow.kernels.SquaredExponential()
68 set_trainable(k1.lengthscales, False)
69 vgp0 = VGP(
70 (Datum.X[0], Datum.Y[0]),
71 kernel=k0,
72 mean_function=Constant(),
73 likelihood=gpflow.likelihoods.Gaussian(),
74 num_latent_gps=1,
75 )
76 vgp1 = VGP(
77 (Datum.X[1], Datum.Y[1]),
78 kernel=k1,
79 mean_function=Constant(),
80 likelihood=gpflow.likelihoods.Gaussian(),
81 num_latent_gps=1,
82 )
83 # 2. Coregionalized VGP
84 kc = gpflow.kernels.SquaredExponential(active_dims=[0, 1])
85 set_trainable(kc.lengthscales, False)
86 set_trainable(kc.variance, False) # variance is handled by the Coregion kernel
87 coreg = gpflow.kernels.Coregion(output_dim=2, rank=1, active_dims=[2])
88 coreg.W.assign(np.zeros((2, 1))) # zero correlation between outputs
89 set_trainable(coreg.W, False)
90 lik = gpflow.likelihoods.SwitchedLikelihood(
91 [gpflow.likelihoods.Gaussian(), gpflow.likelihoods.Gaussian()]
92 )
93 mean_c = gpflow.mean_functions.SwitchedMeanFunction(
94 [gpflow.mean_functions.Constant(), gpflow.mean_functions.Constant()]
95 )
96 cvgp = VGP(
97 (Datum.X_augmented, Datum.Y_augmented),
98 kernel=kc * coreg,
99 mean_function=mean_c,
100 likelihood=lik,
101 num_latent_gps=1,
102 )
103
104 # Train them for a small number of iterations
105
106 opt = gpflow.optimizers.Scipy()
107 opt.minimize(
108 vgp0.training_loss,
109 variables=vgp0.trainable_variables,
110 options=dict(maxiter=1000),
111 method="BFGS",
112 )
113 opt.minimize(
114 vgp1.training_loss,
115 variables=vgp1.trainable_variables,
116 options=dict(maxiter=1000),

Callers 7

test_likelihood_varianceFunction · 0.85
test_kernel_varianceFunction · 0.85
test_mean_valuesFunction · 0.85
test_predict_fFunction · 0.85
test_predict_yFunction · 0.85
test_predict_log_densityFunction · 0.85
test_predict_f_samplesFunction · 0.85

Calls 5

minimizeMethod · 0.95
set_trainableFunction · 0.90
VGPClass · 0.90
assignMethod · 0.80
ConstantClass · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…