def test_one_node_updown(self): """Test flow updown phase with just one node.""" flow = dbn_binodes.get_DBN_flow(1, hidden_dims=[2]) N = 10000 x = mdp.numx.zeros((N, 4)) for i in range(N): r = mdp.numx.rand() if r>0.666: x[i,:] = [0.,1.,0.,1.] elif r>0.333: x[i,:] = [1.,0.,1.,0.] def data_gen(): for _ in range(100): # (data, learning rate, decay, momentum) yield (x, 0.5, 0., 0.5) flow.train([data_gen()]) print flow[0].w_gen flow.updown_phase([x], epsilon=0.5, decay=0., momentum=0.5, n_updates=3, max_iter=300, min_error=1e-2) print flow[0].w_gen error = flow.updown_phase([x], epsilon=0.1, decay=0., momentum=0.9, n_updates=3, max_iter=1000, min_error=0.05) assert error < 0.05
def test_one_node_updown(self): """Test flow updown phase with just one node.""" flow = dbn_binodes.get_DBN_flow(1, hidden_dims=[2]) N = 10000 x = mdp.numx.zeros((N, 4)) for i in range(N): r = mdp.numx.rand() if r > 0.666: x[i, :] = [0., 1., 0., 1.] elif r > 0.333: x[i, :] = [1., 0., 1., 0.] def data_gen(): for _ in range(100): # (data, learning rate, decay, momentum) yield (x, 0.5, 0., 0.5) flow.train([data_gen()]) print flow[0].w_gen flow.updown_phase([x], epsilon=0.5, decay=0., momentum=0.5, n_updates=3, max_iter=300, min_error=1e-2) print flow[0].w_gen error = flow.updown_phase([x], epsilon=0.1, decay=0., momentum=0.9, n_updates=3, max_iter=1000, min_error=0.05) assert error < 0.05
# -*- coding: utf-8 -*- # Generated by codesnippet sphinx extension on 2012-10-04 import mdp import numpy as np np.random.seed(0) import bimdp import dbn_binodes n_layers = 2 flow = dbn_binodes.get_DBN_flow(2, hidden_dims=[2, 2]) n_samples = 10000 # number of data points n_greedy_reps = 100 # repetitions in greedy phase x = mdp.numx.zeros((n_samples, 4)) for i in range(n_samples): r = mdp.numx.rand() if r > 0.666: x[i, :] = [0., 1., 0., 1.] elif r > 0.333: x[i, :] = [1., 0., 1., 0.] data_iterables = [None] + [[x] * n_greedy_reps] * n_layers + [[x]] msg_iterables = ([None] + [[{ "epsilon": 0.1, "decay": 0.0, "momentum": 0.0 }] * n_greedy_reps] * n_layers + [[{ "top_updates": 3, "epsilon": 0.1, "decay": 0.0,
# -*- coding: utf-8 -*- # Generated by codesnippet sphinx extension on 2012-10-04 import mdp import numpy as np np.random.seed(0) import bimdp import dbn_binodes n_layers = 2 flow = dbn_binodes.get_DBN_flow(2, hidden_dims=[2,2]) n_samples = 10000 # number of data points n_greedy_reps = 100 # repetitions in greedy phase x = mdp.numx.zeros((n_samples, 4)) for i in range(n_samples): r = mdp.numx.rand() if r>0.666: x[i,:] = [0.,1.,0.,1.] elif r>0.333: x[i,:] = [1.,0.,1.,0.] data_iterables = [None] + [[x] * n_greedy_reps] * n_layers + [[x]] msg_iterables = ([None] + [[{"epsilon": 0.1, "decay": 0.0, "momentum": 0.0}] * n_greedy_reps] * n_layers + [[{"top_updates": 3, "epsilon": 0.1, "decay": 0.0, "momentum": 0.0, "max_iter": 2, "min_error": -1.0}]]) bimdp.show_training(flow, data_iterables, msg_iterables, debug=True)