Пример #1
0
 def test_invalid_dim(self, dim):
     """Tests that a warning is issued if the feature vectors do not have the correct
     dimension"""
     with pytest.raises(ValueError, match="Dimension of parameter vector"):
         features = np.ones((dim, dim + 1))
         expf = embed.ExpFeatures(features)
         expf(np.zeros(dim))
Пример #2
0
 def test_jacobian_predefined(self, dim):
     """Tests that the jacobian is computed correctly for pre-defined features and parameters"""
     k = dim - 2
     features = feats[k]
     expf = embed.ExpFeatures(features)
     g = expf.jacobian(ps[k])
     assert np.allclose(g, jacobian_f[k])
Пример #3
0
 def test_jacobian_identity(self, dim):
     """Tests that the jacobian is computed correctly compared to a general calculation using an
     identity matrix of feature vectors"""
     k = dim - 2
     features = np.eye(dim)
     expf = embed.ExpFeatures(features)
     exp = embed.Exp(dim)
     assert np.allclose(expf.jacobian(ps[k]), exp.jacobian(ps[k]))
Пример #4
0
 def test_jacobian_zero_params(self, dim):
     """Tests that the jacobian is equal to a matrix with -1 in all entries when parameters are
     zero"""
     features = np.ones((dim, dim))
     params = np.zeros(dim)
     expf = embed.ExpFeatures(features)
     g = expf.jacobian(params)
     assert np.allclose(-np.ones((dim, dim)), g)
Пример #5
0
    def test_exp_features_shape(self, dim, m):
        """Tests that the weights and jacobian have the correct shape for a range of different 
        sizes for the input features matrix"""
        features = np.ones((m, dim))
        expf = embed.ExpFeatures(features)
        params = np.ones(dim)

        assert expf(params).shape == (m,)
        assert expf.jacobian(params).shape == (m, dim)
Пример #6
0
 def test_predefined(self, dim):
     """Tests that weights are computed correctly for pre-defined features and parameters"""
     k = dim - 2
     features = feats[k]
     expf = embed.ExpFeatures(features)
     assert np.allclose(expf(ps[k]), weights_f[k])
Пример #7
0
 def test_zero_params(self, dim):
     """Tests that weights are equal to one when parameters are zero"""
     features = np.ones((dim, dim))
     expf = embed.ExpFeatures(features)
     params = np.zeros(dim)
     assert np.allclose(expf(params), np.ones(dim))