Ejemplo n.º 1
0
    def setUp(self):
        N = 10
        x = np.linspace(-5,5,N)
        self.X = np.reshape(x, (-1, 1))

        self.basis = 'poly3'
        H, self.featurizer, self.featurizer_recovery = featurizer_from_string(self.X, self.basis, extract_dim=0)

        self.beta = [9.91898792e-01,  -1.62113090e+00,   3.15437605e+00,   1.25732838e+00]
        self.B = np.eye(4) * 9
        self.b = np.zeros((4,))

        p = np.dot(H, self.beta)

        def covar_matrix(x, k):
            n = len(x)
            K = np.zeros((n,n))
            for i in range(n):
                for j in range(n):
                    K[i,j] = k(x[i], x[j])
            return K
        k1 = lambda x1, x2 : .001*np.exp( - ((x1-x2)/1.5)**2 ) + (.001 if x1==x2 else 0)
        K1 = covar_matrix(x, k1)

        np.random.seed(0)
        f1 = np.random.multivariate_normal(mean=np.zeros((len(x),)), cov=K1)
        self.y1 = f1 + p


        self.cov = GPCov(wfn_params=[.001,], dfn_params=[ 1.5,], wfn_str="se", dfn_str="euclidean")
        self.noise_var = .001

        self.gp = GP(X=self.X,
                     y=self.y1,
                     noise_var = self.noise_var,
                     cov_main = self.cov,
                     basis = self.basis,
                     featurizer_recovery = self.featurizer_recovery,
                     param_mean=self.b,
                     param_cov=self.B,
                     compute_ll=True,
                     compute_grad=True,
                     sparse_threshold=0,
                     build_tree=False,
                     sparse_invert=True)
Ejemplo n.º 2
0
    def setUp(self):
        N = 25
        x = np.linspace(-5,5,N)
        self.X = np.reshape(x, (-1, 1))

        self.u = np.array(((-2.0,), (2.0,)))

        self.basis = 'poly3'
        H, self.featurizer, self.featurizer_recovery = featurizer_from_string(self.X, self.basis, extract_dim=0)

        self.beta = np.array([9.91898792e-01,  -1.62113090e+00,   3.15437605e+00,   1.25732838e+00])*10
        self.B = np.eye(4) * 9
        self.b = np.zeros((4,))

        self.p = np.dot(H, self.beta)

        f1 = np.array([-1.02804007, -1.54448568, -0.31653812, -0.46768499, 0.67463927, 1.06519473, -1.39472442, -0.72392324, -2.99133689, -0.59922449, -3.70430871, -1.75810012, -0.80376896, -0.50514541, -0.5459166, 1.6353825, -1.13032502, 0.80372166, -0.01374143, -1.16083918, -1.6099601, -4.37523678, -1.53780366, -2.98047752, -3.41214803])
        self.y1 = f1 + self.p

        self.cov_main = GPCov(wfn_params=[0.3,], dfn_params=[ 0.5,], wfn_str="compact2", dfn_str="euclidean")
        self.cov_fic = GPCov(wfn_params=[0.2,], dfn_params=[ 2.5,], wfn_str="se", dfn_str="euclidean", Xu = self.u)
        self.noise_var = .001


        self.gp = GP(X=self.X,
                     y=self.y1,
                     noise_var = self.noise_var,
                     cov_main = self.cov_main,
                     cov_fic = self.cov_fic,
                     basis = self.basis,
                     featurizer_recovery = self.featurizer_recovery,
                     param_mean=self.b,
                     param_cov=self.B,
                     compute_ll=True,
                     compute_grad=True,
                     compute_xu_grad=True,
                     sparse_threshold=0,
                     build_tree=False,
                     sparse_invert=True)