def train_example(dataset=None): model = GaussianBinaryRBM(nvis=1296, nhid=61, irange=0.5, energy_function_class=grbm_type_1(), learn_sigma=True, init_sigma=.4, init_bias_hid=2., mean_vis=False, sigma_lr_scale=1e-3) cost = SMD(corruptor=GaussianCorruptor(stdev=0.4)) algorithm = SGD(learning_rate=.1, batch_size=5, monitoring_batches=20, monitoring_dataset=dataset, cost=cost, termination_criterion=MonitorBased(prop_decrease=0.01, N=1)) train = Train(dataset=dataset, model=model, save_path="./experiment/training.pkl", save_freq=10, algorithm=algorithm, extensions=[]) train.main_loop()
def get_grbm(structure): n_input, n_output = structure config = { 'nvis': n_input, 'nhid': n_output, "irange": 0.05, "energy_function_class": GRBM_Type_1, "learn_sigma": True, "init_sigma": .4, "init_bias_hid": -2., "mean_vis": False, "sigma_lr_scale": 1e-3 } return GaussianBinaryRBM(**config)
required=False, help='Disable plotting of results.') args = parser.parse_args() data_rng = numpy.random.RandomState(seed=999) data = data_rng.normal(size=(500, 20)).astype(theano.config.floatX) conf = { 'nvis': 20, 'nhid': 30, 'rbm_seed': 1, 'batch_size': 100, 'base_lr': 1e-4, 'anneal_start': 1, 'pcd_steps': 1, } rbm = GaussianBinaryRBM(nvis=conf['nvis'], nhid=conf['nhid'], irange=0.5, energy_function_class = GRBM_Type_1) rng = numpy.random.RandomState(seed=conf.get('rbm_seed', 42)) sampler = BlockGibbsSampler(rbm, data[0:100], rng, steps=conf['pcd_steps']) minibatch = tensor.matrix() optimizer = SGDOptimizer(rbm, conf['base_lr'], conf['anneal_start']) updates = training_updates(visible_batch=minibatch, model=rbm, sampler=sampler, optimizer=optimizer) proxy_cost = rbm.reconstruction_error(minibatch, rng=sampler.s_rng) train_fn = theano.function([minibatch], proxy_cost, updates=updates) vis = tensor.matrix('vis') free_energy_fn = theano.function([vis], rbm.free_energy_given_v(vis))