def test_gaussian_vis_layer_make_state(): """ Verifies that GaussianVisLayer.make_state creates a shared variable whose value passes check_gaussian_samples In this case the layer lives in a VectorSpace """ n = 5 rows = None cols = None channels = None num_samples = 1000 tol = .042 # tolerated variance beta = 1/tol # precision parameter layer = GaussianVisLayer(nvis = n, init_beta=beta) rng = np.random.RandomState([2012,11,1]) mean = rng.uniform(1e-6, 1. - 1e-6, (n,)) z= mean layer.set_biases(z.astype(config.floatX)) init_state = layer.make_state(num_examples=num_samples, numpy_rng=rng) value = init_state.get_value() check_gaussian_samples(value, num_samples, n, rows, cols, channels, mean, tol)
def test_gaussian_vis_layer_make_state(): """ Verifies that GaussianVisLayer.make_state creates a shared variable whose value passes check_gaussian_samples In this case the layer lives in a VectorSpace """ n = 5 rows = None cols = None channels = None num_samples = 1000 tol = .042 # tolerated variance beta = 1 / tol # precision parameter layer = GaussianVisLayer(nvis=n, init_beta=beta) rng = np.random.RandomState([2012, 11, 1]) mean = rng.uniform(1e-6, 1. - 1e-6, (n, )) z = mean layer.set_biases(z.astype(config.floatX)) init_state = layer.make_state(num_examples=num_samples, numpy_rng=rng) value = init_state.get_value() check_gaussian_samples(value, num_samples, n, rows, cols, channels, mean, tol)
def test_gaussian_vis_layer_sample_conv(): """ Verifies that GaussianVisLayer.sample returns an expression whose value passes check_gaussian_samples. In this case the layer lives in a Conv2DSpace """ assert hasattr(np, 'exp') n = None num_samples = 1000 tol = .042 # tolerated variance beta = 1/tol # precision parameter rows = 3 cols = 3 channels = 3 # axes for batch, rows, cols, channels, can be given in any order axes = ['b', 0, 1, 'c'] random.shuffle(axes) axes = tuple(axes) print 'axes:', axes class DummyLayer(object): """ A layer that we build for the test that just uses a state as its downward message. """ def downward_state(self, state): return state def downward_message(self, state): return state vis = GaussianVisLayer(nvis=None,rows=rows, cols=cols, channels=channels, init_beta=beta, axes=axes) hid = DummyLayer() rng = np.random.RandomState([2012,11,1,259]) mean = rng.uniform(1e-6, 1. - 1e-6, (rows, cols, channels)) ofs = rng.randn(rows,cols,channels) vis.set_biases(ofs.astype(config.floatX)) #z = inverse_sigmoid_numpy(mean) - ofs z = mean -ofs z_var = sharedX(np.zeros((num_samples, rows, cols, channels)) + z) theano_rng = MRG_RandomStreams(2012+11+1) sample = vis.sample(state_above=z_var, layer_above=hid, theano_rng=theano_rng) sample = sample.eval() check_gaussian_samples(sample, num_samples, n, rows, cols, channels, mean, tol)
def test_gaussian_vis_layer_sample(): """ Verifies that GaussianVisLayer.sample returns an expression whose value passes check_gaussian_samples In this case the layer lives in a VectorSpace """ assert hasattr(np, 'exp') n = 5 num_samples = 1000 tol = .042 # tolerated variance beta = 1 / tol # precision parameter rows = None cols = None channels = None class DummyLayer(object): """ A layer that we build for the test that just uses a state as its downward message. """ def downward_state(self, state): return state def downward_message(self, state): return state vis = GaussianVisLayer(nvis=n, init_beta=beta) hid = DummyLayer() rng = np.random.RandomState([2012, 11, 1, 259]) mean = rng.uniform(1e-6, 1. - 1e-6, (n, )) ofs = rng.randn(n) vis.set_biases(ofs.astype(config.floatX)) #z = inverse_sigmoid_numpy(mean) - ofs z = mean - ofs # linear activation function z_var = sharedX(np.zeros((num_samples, n)) + z) # mean will be z_var + mu theano_rng = MRG_RandomStreams(2012 + 11 + 1) sample = vis.sample(state_above=z_var, layer_above=hid, theano_rng=theano_rng) sample = sample.eval() check_gaussian_samples(sample, num_samples, n, rows, cols, channels, mean, tol)
def test_gaussian_vis_layer_sample(): """ Verifies that GaussianVisLayer.sample returns an expression whose value passes check_gaussian_samples In this case the layer lives in a VectorSpace """ assert hasattr(np, 'exp') n = 5 num_samples = 1000 tol = .042 # tolerated variance beta = 1/tol # precision parameter rows = None cols = None channels = None class DummyLayer(object): """ A layer that we build for the test that just uses a state as its downward message. """ def downward_state(self, state): return state def downward_message(self, state): return state vis = GaussianVisLayer(nvis=n, init_beta=beta) hid = DummyLayer() rng = np.random.RandomState([2012,11,1,259]) mean = rng.uniform(1e-6, 1. - 1e-6, (n,)) ofs = rng.randn(n) vis.set_biases(ofs.astype(config.floatX)) #z = inverse_sigmoid_numpy(mean) - ofs z=mean -ofs # linear activation function z_var = sharedX(np.zeros((num_samples, n)) + z) # mean will be z_var + mu theano_rng = MRG_RandomStreams(2012+11+1) sample = vis.sample(state_above=z_var, layer_above=hid, theano_rng=theano_rng) sample = sample.eval() check_gaussian_samples(sample, num_samples, n, rows, cols, channels, mean, tol)
def test_gaussian_vis_layer_make_state_conv(): """ Verifies that GaussianVisLayer.make_state creates a shared variable whose value passes check_gaussian_samples In this case the layer lives in a Conv2DSpace """ n = None rows = 3 cols = 3 channels = 3 num_samples = 1000 tol = .042 # tolerated variance beta = 1 / tol # precision parameter # axes for batch, rows, cols, channels, can be given in any order axes = ['b', 0, 1, 'c'] random.shuffle(axes) axes = tuple(axes) print 'axes:', axes layer = GaussianVisLayer(rows=rows, cols=cols, channels=channels, init_beta=beta, axes=axes) # rng = np.random.RandomState([2012,11,1]) rng = np.random.RandomState() mean = rng.uniform(1e-6, 1. - 1e-6, (rows, cols, channels)) #z = inverse_sigmoid_numpy(mean) z = mean layer.set_biases(z.astype(config.floatX)) init_state = layer.make_state(num_examples=num_samples, numpy_rng=rng) value = init_state.get_value() check_gaussian_samples(value, num_samples, n, rows, cols, channels, mean, tol)
def test_gaussian_vis_layer_make_state_conv(): """ Verifies that GaussianVisLayer.make_state creates a shared variable whose value passes check_gaussian_samples In this case the layer lives in a Conv2DSpace """ n = None rows = 3 cols = 3 channels = 3 num_samples = 1000 tol = .042 # tolerated variance beta = 1/tol # precision parameter # axes for batch, rows, cols, channels, can be given in any order axes = ['b', 0, 1, 'c'] random.shuffle(axes) axes = tuple(axes) print 'axes:', axes layer = GaussianVisLayer(rows=rows, cols=cols, channels=channels, init_beta=beta, axes=axes) # rng = np.random.RandomState([2012,11,1]) rng = np.random.RandomState() mean = rng.uniform(1e-6, 1. - 1e-6, (rows, cols, channels)) #z = inverse_sigmoid_numpy(mean) z= mean layer.set_biases(z.astype(config.floatX)) init_state = layer.make_state(num_examples=num_samples, numpy_rng=rng) value = init_state.get_value() check_gaussian_samples(value, num_samples, n, rows, cols, channels, mean, tol)
def test_gaussian_vis_layer_sample_conv(): """ Verifies that GaussianVisLayer.sample returns an expression whose value passes check_gaussian_samples. In this case the layer lives in a Conv2DSpace """ assert hasattr(np, 'exp') n = None num_samples = 1000 tol = .042 # tolerated variance beta = 1 / tol # precision parameter rows = 3 cols = 3 channels = 3 # axes for batch, rows, cols, channels, can be given in any order axes = ['b', 0, 1, 'c'] random.shuffle(axes) axes = tuple(axes) print 'axes:', axes class DummyLayer(object): """ A layer that we build for the test that just uses a state as its downward message. """ def downward_state(self, state): return state def downward_message(self, state): return state vis = GaussianVisLayer(nvis=None, rows=rows, cols=cols, channels=channels, init_beta=beta, axes=axes) hid = DummyLayer() rng = np.random.RandomState([2012, 11, 1, 259]) mean = rng.uniform(1e-6, 1. - 1e-6, (rows, cols, channels)) ofs = rng.randn(rows, cols, channels) vis.set_biases(ofs.astype(config.floatX)) #z = inverse_sigmoid_numpy(mean) - ofs z = mean - ofs z_var = sharedX(np.zeros((num_samples, rows, cols, channels)) + z) theano_rng = MRG_RandomStreams(2012 + 11 + 1) sample = vis.sample(state_above=z_var, layer_above=hid, theano_rng=theano_rng) sample = sample.eval() check_gaussian_samples(sample, num_samples, n, rows, cols, channels, mean, tol)