def get_trainer(trainer_name, net, ds, batchlearning): if trainer_name == "bp": return BackpropTrainer(net, ds, batchlearning=batchlearning, verbose=True) elif trainer_name == "dl": return DeepBeliefTrainer(net, ds)
net.addConnection(FullConnection(bias, h1)) net.addConnection(FullConnection(bias, h2)) net.addConnection(FullConnection(bias, out)) net.sortModules() return net if __name__ == "__main__": import GwData data = GwData.GwData() xs = get_binary_data(data) ys = data.labels_for("50") sdataset = SupervisedDataSet(xs.shape[1], 1) udataset = UnsupervisedDataSet(xs.shape[1]) for i, x in enumerate(xs): sdataset.addSample(x, ys[i]) udataset.addSample(x) epochs = 100 layerDims = [xs.shape[1], 300, 100, 2] #net = buildNetwork(*layerDims) net = custom_build_network(layerDims) trainer = DeepBeliefTrainer(net, dataset=udataset) #trainer = DeepBeliefTrainer(net, dataset=sdataset) trainer.trainEpochs(epochs)
tf = open('novelty_plant.txt','r') first = True for line in tf.readlines(): if (not first): data = [float(x) for x in line.strip().split('\t') if x != ''] # indata = tuple(data[:6]) # outdata = tuple(data[6:]) ds.addSample(data) first = False n = buildNetwork(ds.dim,8,8,1,recurrent=True) t = DeepBeliefTrainer(n,ds, epochs=50) t.trainEpochs(1) t.testOnData(ds, verbose= True) ds.addSample((0, 0), (0,)) ds.addSample((0, 1), (1,)) ds.addSample((1, 0), (1,)) ds.addSample((1, 1), (0,)) for input, target in ds: print(input, target) #net = buildNetwork(2, 3, 1, bias=True, hiddenclass=TanhLayer)#1000 # net = buildNetwork(2, 6, 1, bias=True) # 3000 net = buildNetwork(2, 3, 1, bias=True)
__author__ = 'Justin S Bayer, [email protected]' __version__ = '$Id$' import scipy from pybrain.datasets import UnsupervisedDataSet from pybrain.unsupervised.trainers.deepbelief import DeepBeliefTrainer from pybrain.tools.shortcuts import buildNetwork from pybrainexamples.datasets.mnist import makeMnistDataSets net = buildNetwork(784, 500, 500, 2000, bias=True) train, test = makeMnistDataSets('/Users/bayerj/Desktop/MNIST/') trainer = DeepBeliefTrainer(net, train) trainer.train() print "RBM Phase finished. Now backprop." softmaxer = SoftmaxLayer(10) con = FullConnection(net.outmodules[0], softmaxer) net.addModule(softmaxer) net.outmodules = [softmaxer] trainer = BackpropTrainer(trainer, ds) for i in xrange(sys.maxint): error = trainer.train() print "%i: %.2f" % (i, error)
#! /usr/bin/env python2.5 # -*- coding: utf-8 -*- # Miniscule deep belief net example __author__ = 'Justin S Bayer, [email protected]' __version__ = '$Id$' from pybrain.datasets import UnsupervisedDataSet from pybrain.unsupervised.trainers.deepbelief import DeepBeliefTrainer from pybrain.tools.shortcuts import buildNetwork ds = UnsupervisedDataSet(6) ds.addSample([0, 1] * 3) ds.addSample([1, 0] * 3) net = buildNetwork(6, 2, 2, 2, bias=True) params = net.params.copy() trainer = DeepBeliefTrainer(net, ds) trainer.train() print params == net.params
net.addConnection(FullConnection(bias, h1)) net.addConnection(FullConnection(bias, h2)) net.addConnection(FullConnection(bias, out)) net.sortModules() return net if __name__ == "__main__": import GwData data = GwData.GwData() xs = get_binary_data(data) ys = data.labels_for("50") sdataset = SupervisedDataSet(xs.shape[1], 1) udataset = UnsupervisedDataSet(xs.shape[1]) for i,x in enumerate(xs): sdataset.addSample(x, ys[i]) udataset.addSample(x) epochs = 100 layerDims = [xs.shape[1], 300, 100, 2] #net = buildNetwork(*layerDims) net = custom_build_network(layerDims) trainer = DeepBeliefTrainer(net, dataset=udataset) #trainer = DeepBeliefTrainer(net, dataset=sdataset) trainer.trainEpochs(epochs)