def test_sample(self): sys.stdout.write('BinaryBinaryLabelRBM -> Performing sample test ...') numx.random.seed(42) data_dim = 12 label_dim = 8 input_dim = data_dim + label_dim hidden_dim = 10 batchsize = 3 rbm = Model.BinaryBinaryLabelRBM(data_dim, label_dim, hidden_dim) data = numx.random.rand(batchsize, input_dim) h = rbm.probability_h_given_v(data) assert numx.all(h.shape == (batchsize, hidden_dim)) h = rbm.sample_h(h) assert numx.all(h.shape == (batchsize, hidden_dim)) v = rbm.probability_v_given_h(h) assert numx.all(v.shape == (batchsize, input_dim)) v = rbm.sample_v(v) assert numx.all(v.shape == (batchsize, input_dim)) assert numx.all( numx.abs(numx.sum(v[:, data_dim:]) - batchsize) < self.epsilon) assert numx.all(v[:, 0:data_dim] >= 0.0) assert numx.all(v[:, 0:data_dim] <= 1.0) sys.stdout.flush() print(' successfully passed!') sys.stdout.flush() pass
def test___init__(self): sys.stdout.write('BinaryBinaryLabelRBM -> Performing init test ...') numx.random.seed(42) data_dim = 12 label_dim = 8 input_dim = data_dim + label_dim hidden_dim = 10 batchsize = 3 rbm = Model.BinaryBinaryLabelRBM(data_dim, label_dim, hidden_dim) assert numx.all(rbm.w.shape == (input_dim, hidden_dim)) assert numx.all(rbm.bv.shape == (1, input_dim)) assert numx.all(rbm.bh.shape == (1, hidden_dim)) assert numx.all(rbm.data_dim == data_dim) assert numx.all(rbm.label_dim == label_dim) assert numx.all(rbm.input_dim == input_dim) assert numx.all(rbm.output_dim == hidden_dim) print(' successfully passed!') sys.stdout.flush() pass