def test_constraints_testmodel(self): self.testmodel['.*rbf'].constrain_negative() self.assertListEqual( self.testmodel.constraints[ transformations.NegativeLogexp()].tolist(), [0, 1]) self.testmodel['.*lengthscale'].constrain_bounded(0, 1) self.assertListEqual( self.testmodel.constraints[ transformations.NegativeLogexp()].tolist(), [1]) self.assertListEqual( self.testmodel.constraints[transformations.Logistic(0, 1)].tolist(), [0]) self.testmodel[''].unconstrain_negative() self.assertListEqual( self.testmodel.constraints[ transformations.NegativeLogexp()].tolist(), []) self.assertListEqual( self.testmodel.constraints[transformations.Logistic(0, 1)].tolist(), [0]) self.testmodel['.*lengthscale'].unconstrain_bounded(0, 1) self.assertListEqual( self.testmodel.constraints[transformations.Logistic(0, 1)].tolist(), [])
def test_constraints_set_direct(self): self.testmodel['.*rbf'].constrain_negative() self.testmodel['.*lengthscale'].constrain_bounded(0, 1) self.testmodel['.*variance'].fix() self.assertListEqual( self.testmodel.constraints[transformations.__fixed__].tolist(), [1, 2]) self.assertListEqual( self.testmodel.constraints[transformations.Logistic(0, 1)].tolist(), [0]) self.assertListEqual( self.testmodel.constraints[ transformations.NegativeLogexp()].tolist(), [1]) cache_constraints = self.testmodel.constraints.copy() self.testmodel.unconstrain() self.testmodel.likelihood.fix() self.assertListEqual(self.testmodel._fixes_.tolist(), [ transformations.UNFIXED, transformations.UNFIXED, transformations.FIXED ]) self.assertListEqual( self.testmodel.constraints[transformations.__fixed__].tolist(), [2]) self.assertListEqual( self.testmodel.constraints[transformations.Logistic(0, 1)].tolist(), []) self.assertListEqual( self.testmodel.constraints[ transformations.NegativeLogexp()].tolist(), []) self.testmodel.constraints = cache_constraints self.assertListEqual( self.testmodel.constraints[transformations.__fixed__].tolist(), [1, 2]) self.assertListEqual( self.testmodel.constraints[transformations.Logistic(0, 1)].tolist(), [0]) self.assertListEqual( self.testmodel.constraints[ transformations.NegativeLogexp()].tolist(), [1]) self.assertListEqual(self.testmodel._fixes_.tolist(), [ transformations.UNFIXED, transformations.FIXED, transformations.FIXED ]) self.assertIs(self.testmodel.constraints, self.testmodel.likelihood.constraints._param_index_ops) self.assertIs(self.testmodel.constraints, self.testmodel.kern.constraints._param_index_ops)
def test_add_parameter_in_hierarchy(self): self.test1.kern.rbf.link_parameter( Param("NEW", np.random.rand(2), transformations.NegativeLogexp()), 1) self.assertListEqual( self.test1.constraints[transformations.NegativeLogexp()].tolist(), list(range(self.param.size + 1, self.param.size + 1 + 2))) self.assertListEqual( self.test1.constraints[transformations.Logistic(0, 1)].tolist(), list(range(self.param.size))) self.assertListEqual( self.test1.constraints[transformations.Logexp(0, 1)].tolist(), np.r_[50, 53:55].tolist())