def test_fit(): npr.seed(1) N = 10 D = 5 burnin = 100 mcmc_iters = 100 num_pending = 3 num_fantasies = 2 gp = GPClassifier(D, burnin=burnin, mcmc_iters=mcmc_iters, num_fantasies=num_fantasies) inputs = np.vstack((0.1 * npr.rand(N, D), npr.rand(N, D))) inputs[12] = np.ones(D) pending = npr.rand(3, D) W = npr.randn(D, 1) vals = (inputs - inputs.mean(0)).dot(W).flatten() > 0 gp.fit(inputs, vals, pending) probs = np.zeros(inputs.shape[0]) for i in xrange(gp.num_states): gp.set_state(i) probs += (gp.latent_values.value > 0) / float(mcmc_iters) assert np.all(probs[:N] < 0.5) and np.all(probs[N:] > 0.5) assert gp.values.shape[0] == 2 * N + num_pending assert gp.values.shape[1] == 2 assert gp.chain_length == burnin + mcmc_iters assert all( [np.all(p.value != p.initial_value) for p in gp.params.values()]) assert len(gp._cache_list) == mcmc_iters assert len(gp._hypers_list) == mcmc_iters assert len(gp._latent_values_list) == mcmc_iters assert len(gp._fantasy_values_list) == mcmc_iters
def test_fit(): npr.seed(1) N = 10 D = 5 burnin = 100 mcmc_iters = 100 num_pending = 3 num_fantasies = 2 gp = GPClassifier(D, burnin=burnin, mcmc_iters=mcmc_iters, num_fantasies=num_fantasies) inputs = np.vstack((0.1*npr.rand(N,D),npr.rand(N,D))) inputs[12] = np.ones(D) pending = npr.rand(3,D) W = npr.randn(D,1) vals = (inputs - inputs.mean(0)).dot(W).flatten() > 0 gp.fit(inputs, vals, pending) probs = np.zeros(inputs.shape[0]) for i in xrange(gp.num_states): gp.set_state(i) probs += (gp.latent_values.value > 0) / float(mcmc_iters) assert np.all(probs[:N] < 0.5) and np.all(probs[N:] > 0.5) assert gp.values.shape[0] == 2*N + num_pending assert gp.values.shape[1] == 2 assert gp.chain_length == burnin + mcmc_iters assert all([np.all(p.value != p.initial_value) for p in gp.params.values()]) assert len(gp._cache_list) == mcmc_iters assert len(gp._hypers_list) == mcmc_iters assert len(gp._latent_values_list) == mcmc_iters assert len(gp._fantasy_values_list) == mcmc_iters