Ejemplo n.º 1
0
 def test_func_args(self):
     X = np.linspace(0, 1, 10)[:, None]
     Y = np.random.randn(10, 1)
     with Model() as model:
         # make a Gaussian model
         with pytest.raises(ValueError):
             random_test = gp.GP('random_test', cov_func=gp.mean.Zero(), observed={'X':X, 'Y':Y})
         with pytest.raises(ValueError):
             random_test = gp.GP('random_test', mean_func=gp.cov.Matern32(1, 1),
                                     cov_func=gp.cov.Matern32(1, 1), observed={'X':X, 'Y':Y})
Ejemplo n.º 2
0
 def test_sample(self):
     X = np.linspace(0,1,100)[:,None]
     Y = np.random.randn(100,1)
     with Model() as model:
         M = gp.mean.Zero()
         l = Uniform('l', 0, 5)
         K = gp.cov.Matern32(1, l)
         sigma = Uniform('sigma', 0, 10)
         # make a Gaussian model
         random_test = gp.GP('random_test', mean_func=M, cov_func=K, sigma=sigma, observed={'X':X, 'Y':Y})
         tr = sample(500, init=None, progressbar=False, random_seed=self.random_seed)
Ejemplo n.º 3
0
def gaussian(x, y):
    X = x.reshape(-1, 1)
    Z = linspace(-6, 6, 100).reshape(-1, 1)
    with Model() as gp_fit:
        ρ = Gamma('ρ', 1, 1)
        nu = Gamma('nu', 1, 1)
        K = nu * gp.cov.Matern32(1, ρ)
    with gp_fit:
        M = gp.mean.Zero()
        σ = HalfCauchy('σ', 2.5)
    with gp_fit:
        y_obs = gp.GP('y_obs', mean_func=M, cov_func=K, sigma=σ, observed={'X': X, 'Y': y})
    with gp_fit:
        gp_samples = pm.gp.sample_gp(trace[1000:], y_obs, Z, samples=50)
Ejemplo n.º 4
0
    def test_sample(self):
        X = np.linspace(0, 1, 10)[:, None]
        Y = np.random.randn(10)
        with Model() as model:
            M = gp.mean.Zero()
            l = Uniform('l', 0, 5)
            K = gp.cov.Matern32(1, l)
            sigma = Uniform('sigma', 0, 10)
            # make a Gaussian model
            random_test = gp.GP('random_test', mean_func=M, cov_func=K, sigma=sigma, observed={'X':X, 'Y':Y})
            tr = sample(20, init=None, progressbar=False, random_seed=self.random_seed)

        # test prediction
        Z = np.linspace(0, 1, 5)[:, None]
        with model:
            out = gp.sample_gp(tr[-3:], gp=random_test, X_values=Z, obs_noise=False,
                               random_seed=self.random_seed, progressbar=False, chol_const=True)