From 5d772a8c1100c1504a6808aebcbfbeeb8e55f47c Mon Sep 17 00:00:00 2001 From: Max Zwiessele Date: Thu, 3 Dec 2015 08:48:28 +0000 Subject: [PATCH] [examples] added bgplvm stochastic example and parameter for dimensionality --- GPy/examples/dimensionality_reduction.py | 34 ++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/GPy/examples/dimensionality_reduction.py b/GPy/examples/dimensionality_reduction.py index 0d72949a..024b12ee 100644 --- a/GPy/examples/dimensionality_reduction.py +++ b/GPy/examples/dimensionality_reduction.py @@ -393,12 +393,12 @@ def ssgplvm_simulation(optimize=True, verbose=1, def bgplvm_simulation_missing_data(optimize=True, verbose=1, plot=True, plot_sim=False, - max_iters=2e4, percent_missing=.1, + max_iters=2e4, percent_missing=.1, d=13, ): from GPy import kern from GPy.models.bayesian_gplvm_minibatch import BayesianGPLVMMiniBatch - D1, D2, D3, N, num_inducing, Q = 13, 5, 8, 400, 3, 4 + D1, D2, D3, N, num_inducing, Q = d, 5, 8, 400, 3, 4 _, _, Ylist = _simulate_matern(D1, D2, D3, N, num_inducing, plot_sim) Y = Ylist[0] k = kern.Linear(Q, ARD=True) # + kern.white(Q, _np.exp(-2)) # + kern.bias(Q) @@ -421,6 +421,36 @@ def bgplvm_simulation_missing_data(optimize=True, verbose=1, m.kern.plot_ARD('BGPLVM Simulation ARD Parameters') return m +def bgplvm_simulation_missing_data_stochastics(optimize=True, verbose=1, + plot=True, plot_sim=False, + max_iters=2e4, percent_missing=.1, d=13, batchsize=2, + ): + from GPy import kern + from GPy.models.bayesian_gplvm_minibatch import BayesianGPLVMMiniBatch + + D1, D2, D3, N, num_inducing, Q = d, 5, 8, 400, 3, 4 + _, _, Ylist = _simulate_matern(D1, D2, D3, N, num_inducing, plot_sim) + Y = Ylist[0] + k = kern.Linear(Q, ARD=True) # + kern.white(Q, _np.exp(-2)) # + kern.bias(Q) + + inan = _np.random.binomial(1, percent_missing, size=Y.shape).astype(bool) # 80% missing data + Ymissing = Y.copy() + Ymissing[inan] = _np.nan + + m = BayesianGPLVMMiniBatch(Ymissing, Q, init="random", num_inducing=num_inducing, + kernel=k, missing_data=True, stochastic=True, batchsize=batchsize) + + m.Yreal = Y + + if optimize: + print("Optimizing model:") + m.optimize('bfgs', messages=verbose, max_iters=max_iters, + gtol=.05) + if plot: + m.X.plot("BGPLVM Latent Space 1D") + m.kern.plot_ARD('BGPLVM Simulation ARD Parameters') + return m + def mrd_simulation(optimize=True, verbose=True, plot=True, plot_sim=True, **kw): from GPy import kern