def test_weights_derivative(): ly = layers.Weights((num_vis, num_hid)) p = penalties.l2_penalty(0.37) ly.add_penalty({'matrix': p}) vis = be.randn((num_samples, num_vis)) hid = be.randn((num_samples, num_hid)) derivs = ly.derivatives(vis, hid)
def test_exponential_conditional_params(): ly = layers.ExponentialLayer(num_vis) w = layers.Weights((num_vis, num_hid)) scaled_units = [be.randn((num_samples, num_hid))] weights = [w.W_T()] beta = be.rand((num_samples, 1)) ly._conditional_params(scaled_units, weights, beta)
def test_bernoulli_derivatives(): ly = layers.BernoulliLayer(num_vis) w = layers.Weights((num_vis, num_hid)) vis = ly.random((num_samples, num_vis)) hid = [be.randn((num_samples, num_hid))] weights = [w.W_T()] ly.derivatives(vis, hid, weights)
def test_onehot_derivatives(): ly = layers.OneHotLayer(num_vis) w = layers.Weights((num_vis, num_hid)) vis = ly.random((num_samples, num_vis)) hid = [be.randn((num_samples, num_hid))] weights = [w.W_T()] ly.derivatives(vis, hid, weights)
def test_gaussian_derivatives(): ly = layers.GaussianLayer(num_vis) w = layers.Weights((num_vis, num_hid)) vis = ly.random((num_samples, num_vis)) hid = [be.randn((num_samples, num_hid))] weights = [w.W_T()] ly.derivatives(vis, hid, weights)
def test_onehot_conditional_params(): ly = layers.OneHotLayer(num_vis) w = layers.Weights((num_vis, num_hid)) scaled_units = [be.randn((num_samples, num_hid))] weights = [w.W(trans=True)] beta = be.rand((num_samples, 1)) ly.conditional_params(scaled_units, weights, beta)
def test_exponential_update(): ly = layers.BernoulliLayer(num_vis) w = layers.Weights((num_vis, num_hid)) scaled_units = [be.randn((num_samples, num_hid))] weights = [w.W_T()] beta = be.rand((num_samples, 1)) ly.update(scaled_units, weights, beta)
def test_weights_build_from_config(): ly = layers.Weights((num_vis, num_hid)) ly.add_constraint({'matrix': constraints.non_negative}) p = penalties.l2_penalty(0.37) ly.add_penalty({'matrix': p}) ly_new = layers.Layer.from_config(ly.get_config()) assert ly_new.get_config() == ly.get_config()
def test_ising_update(): ly = layers.IsingLayer(num_vis) w = layers.Weights((num_vis, num_hid)) scaled_units = [be.randn((num_samples, num_hid))] weights = [w.W_T()] beta = be.rand((num_samples, 1)) ly.update(scaled_units, weights, beta)
def test_ising_derivatives(): ly = layers.IsingLayer(num_vis) w = layers.Weights((num_vis, num_hid)) vis = ly.random((num_samples, num_vis)) hid = [be.randn((num_samples, num_hid))] weights = [w.W()] beta = be.rand((num_samples, 1)) ly.derivatives(vis, hid, weights, beta)
def test_exponential_derivatives(): ly = layers.ExponentialLayer(num_vis) w = layers.Weights((num_vis, num_hid)) vis = ly.random((num_samples, num_vis)) hid = [be.randn((num_samples, num_hid))] weights = [w.W_T()] beta = be.rand((num_samples, 1)) ly.derivatives(vis, hid, weights, beta)
def test_Weights_creation(): layers.Weights((num_vis, num_hid))
def test_weights_energy(): ly = layers.Weights((num_vis, num_hid)) vis = be.randn((num_samples, num_vis)) hid = be.randn((num_samples, num_hid)) ly.energy(vis, hid)
def test_enforce_constraints(): ly = layers.Weights((num_vis, num_hid)) ly.add_constraint({'matrix': constraints.non_negative}) ly.enforce_constraints()
def test_get_base_config(): ly = layers.Weights((num_vis, num_hid)) ly.add_constraint({'matrix': constraints.non_negative}) p = penalties.l2_penalty(0.37) ly.add_penalty({'matrix': p}) ly.get_base_config()
def test_parameter_step(): ly = layers.Weights((num_vis, num_hid)) deltas = layers.ParamsWeights(be.randn(ly.shape)) ly.parameter_step(deltas)
def test_get_penalty_grad(): ly = layers.Weights((num_vis, num_hid)) p = penalties.l2_penalty(0.37) ly.add_penalty({'matrix': p}) ly.get_penalty_grad(ly.W(), 'matrix')
def test_add_penalty(): ly = layers.Weights((num_vis, num_hid)) p = penalties.l2_penalty(0.37) ly.add_penalty({'matrix': p})