def test_setWeights(self): rbm = DeepRBM([2, 3, 1]) #wrong should throw error with self.assertRaises(ValueError): rbm.setWeights([np.array([0,0,0],[0,0,0]), np.array([0,0,0])]) rbm.setWeights([np.array([0,0,0],[0,0,0]), np.array([0,0,0]).reshape((1, 3))])
def test_setWeights(self): rbm = DeepRBM([2, 3, 1]) with self.assertRaises(ValueError): rbm.setWeights([ np.array([[0, 0], [0, 0], [0, 0]]), np.array([[0], [0], [0]]) ]) rbm.setWeights( [np.array([[0, 0], [0, 0], [0, 0]]), np.matrix([0, 0, 0])])
def test_sample(self): rbm = DeepRBM([2, 3, 1]) rbm.setWeights([np.array([[1,1],[1,1],[1,1]]), np.matrix([1,1,1])]) result = rbm.sample(np.array([0,0]), 0, 2, False) self.assertAlmostEqual(result[0], 0.8175745, 4) result = rbm.sample(np.array([[0,0],[1,1],[0,1]]), 0, 2, False) self.assertAlmostEqual(result[0], 0.8175745, 4) self.assertAlmostEqual(result[1], 0.933540476818325, 4) self.assertAlmostEqual(result[2], 0.8996350, 4) result = rbm.sample(np.array([0]), 2, 0, False) self.assertAlmostEqual(result[0,0], 0.8175745, 4) self.assertAlmostEqual(result[0,1], 0.8175745, 4)
def test_setWeights(self): rbm = DeepRBM([2, 3, 1]) with self.assertRaises(ValueError): rbm.setWeights([np.array([[0,0],[0,0],[0,0]]), np.array([[0],[0],[0]])]) rbm.setWeights([np.array([[0,0],[0,0],[0,0]]), np.matrix([0,0,0])])