本文整理汇总了Python中pybrain.structure.FeedForwardNetwork类的典型用法代码示例。如果您正苦于以下问题:Python FeedForwardNetwork类的具体用法?Python FeedForwardNetwork怎么用?Python FeedForwardNetwork使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FeedForwardNetwork类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
class MyNet:
def __init__(self, file='config.xml'):
self.net = FeedForwardNetwork()
self.file = file
def constructNet(self, input, hidden, output):
inputLayer = LinearLayer(input)
hiddenLayer = TanhLayer(hidden)
outputLayer = LinearLayer(output)
self.net.addInputModule(inputLayer)
self.net.addModule(hiddenLayer)
self.net.addOutputModule(outputLayer)
conn1 = FullConnection(inputLayer, hiddenLayer)
conn2 = FullConnection(hiddenLayer, outputLayer)
self.net.addConnection(conn1)
self.net.addConnection(conn2)
def setup(self):
self.net.sortModules()
def saveToFile(self,file='config.xml'):
NetworkWriter.writeToFile(self.net, file)
def loadFromFile(self, file='config.xml'):
self.net = NetworkReader.readFrom(file)
示例2: initMaxentNetwork
def initMaxentNetwork():
"""Builds a network with just a sigmoid output layer, i.e. a multi-class maximum entropy model."""
fnn = FeedForwardNetwork()
inLayer = LinearLayer(numFeatures)
fnn.addInputModule(inLayer)
outLayer = SigmoidLayer(3)
fnn.addOutputModule(outLayer)
fnn.addConnection(FullConnection(inLayer, outLayer))
fnn.sortModules()
return fnn
示例3: __init__
def __init__(self, num_input, num_hidden, num_output):
# self.net = buildNetwork(num_input, num_hidden, num_output, bias = True)
self.net = FeedForwardNetwork()
self.num_input = num_input
self.num_hidden = num_hidden
self.num_output = num_output
inLayer = LinearLayer(num_input, name='in')
hiddenLayer1 = SigmoidLayer(num_hidden, name='hidden1')
outLayer = LinearLayer(num_output, name='out')
self.net.addInputModule(inLayer)
self.net.addModule(hiddenLayer1)
self.net.addOutputModule(outLayer)
self.in_to_hidden = FullConnection(inLayer, hiddenLayer1)
self.hidden_to_out = FullConnection(hiddenLayer1, outLayer)
self.net.addConnection(self.in_to_hidden)
self.net.addConnection(self.hidden_to_out)
self.net.sortModules()
self.dataset = None
示例4: __init__
def __init__(self, train_data, hyper, n_targets=None, label_targets=None):
"""
------------
train_data: pandas DataFrame
Contains columns for features and for target variables. The names of the target variables ends
with the suffix "_tau"
hyper: dictionary
It contains the hyperparameters necessary to run all the functionalities of the model.
They are the following:
"structure" is a list of integers determining the number of neurons in each hidden layer
"epochs" an integer specifying the maximum number of epochs to run during every training session
"learning_rate" a float giving the learning rate of the gradient descend
"momentum" a float giving the value of the momentum for the algorithm
"batch" a bool. If True the method performs full batch learning, i.e. updates of the weights is done
using all the instances of the training set. Else, normal online method is performed
Other parameters regarding cross validation are explained in the base class
"""
Regression.__init__(self, train_data, hyper, n_targets=n_targets, label_targets=label_targets)
self.N = FeedForwardNetwork()
self.structure = [self.n_feature] + hyper['structure'] + [self.n_target]
self._build_net(self.structure)
self.res_params = [self.N.params[i] for i in range(len(self.N.params))]
self.train_fraction = hyper['train_fraction']
self.seed = hyper['seed']
self.epochs = hyper['epochs']
self.learning_rate = hyper['learning_rate']
self.momentum = hyper['momentum']
self.batch = bool(hyper['batch'])
示例5: __init__
def __init__(self, genes=None):
self.net = FeedForwardNetwork()
inLayer = LinearLayer(Brain.G_INPUTNODES, name='input')
hiddenLayer1 = SigmoidLayer(Brain.G_HIDDENNODES_L1, name='hidden1')
hiddenLayer2 = SigmoidLayer(Brain.G_HIDDENNODES_L2, name='hidden2')
outLayer = SigmoidLayer(Brain.G_OUTPUTNODES, name='out')
bias = BiasUnit(name='bias')
self.net.addInputModule(inLayer)
self.net.addModule(hiddenLayer1)
self.net.addModule(hiddenLayer2)
self.net.addModule(bias)
self.net.addOutputModule(outLayer)
in_to_hidden1 = FullConnection(inLayer, hiddenLayer1)
hidden1_to_hidden2 = FullConnection(hiddenLayer1, hiddenLayer2)
hidden2_to_out = FullConnection(hiddenLayer2, outLayer)
bias_to_hidden1 = FullConnection(bias, hiddenLayer1)
bias_to_hidden2 = FullConnection(bias, hiddenLayer2)
bias_to_out = FullConnection(bias, outLayer)
self.net.addConnection(in_to_hidden1)
self.net.addConnection(hidden1_to_hidden2)
self.net.addConnection(hidden2_to_out)
self.net.addConnection(bias_to_hidden1)
self.net.addConnection(bias_to_hidden2)
self.net.addConnection(bias_to_out)
self.net.sortModules()
if genes != None:
self.import_genes(genes)
示例6: PrepareModel
def PrepareModel(self, savedmodel = None):
if savedmodel != None:
self.trainer = savedmodel
else:
attributescount=len(self.traindata[0])
self.ds = SupervisedDataSet(attributescount, 1)
for i in range(len(self.traindata)):
self.ds.appendLinked(self.traindata[i], self.trainlabel[i])
self.net = FeedForwardNetwork()
inLayer = LinearLayer(len(self.traindata[0]))
self.net.addInputModule(inLayer)
hiddenLayers=[]
for i in range(self.hiddenlayerscount):
hiddenLayer=SigmoidLayer(self.hiddenlayernodescount)
hiddenLayers.append(hiddenLayer)
self.net.addModule(hiddenLayer)
outLayer = LinearLayer(1)
self.net.addOutputModule(outLayer)
layers_connections=[]
layers_connections.append(FullConnection(inLayer, hiddenLayers[0]))
for i in range(self.hiddenlayerscount-1):
layers_connections.append(FullConnection(hiddenLayers[i-1], hiddenLayers[i]))
layers_connections.append(FullConnection(hiddenLayers[-1], outLayer))
for layers_connection in layers_connections:
self.net.addConnection(layers_connection)
self.net.sortModules()
#training the self.network
self.trainer = BackpropTrainer(self.net, self.ds)
self.trainer.train()
示例7: __init__
def __init__(self, hidden_layers, data_index_size):
self.network = FeedForwardNetwork()
connect_queue = Queue.Queue()
for layer in xrange(0, hidden_layers):
connect_queue.put(TanhLayer(data_index_size, name = 'hidden_layer_{}'.format(layer)))
connect_queue.put(SigmoidLayer(1, name = 'output_layer'))
prev_layer = LinearLayer(data_index_size, name = 'input_layer')
self.network.addInputModule(prev_layer)
while not connect_queue.empty():
print 'layer'
current_layer = connect_queue.get()
if current_layer.name == 'output_layer':
self.network.addOutputModule(current_layer)
else:
self.network.addModule(current_layer)
bias = BiasUnit()
bias_connection = FullConnection(bias, current_layer, name = "bias_to_{}_connection".format(current_layer.name))
self.network.addModule(bias)
self.network.addConnection(bias_connection)
connection = FullConnection(prev_layer, current_layer, name = "{}_to_{}_connection".format(prev_layer.name, current_layer.name))
self.network.addConnection(connection)
prev_layer = current_layer
print 'sorting....'
self.network.sortModules()
示例8: __init__
def __init__(self, x, y, direction):
self.age = 0
# position
self.x = x
self.y = y
# number of going back and forth for different foods
self.backForth = 0
self.LastFood = None # the last food animat ate
# orientation (0 - 359 degrees)
self.direction = direction
# carrying food
self.food = None
# touching anything
self.touching = None
self.sees = None
# hunger sensor
self.fruit_hunger = 2000
self.veggie_hunger = 2000
self.avg_fruit_hunger = 0
self.avg_veggie_hunger = 0
# neural net
self.net = FeedForwardNetwork()
self.net.addInputModule(LinearLayer(12, name='in'))
self.net.addModule(SigmoidLayer(13, name='hidden'))
self.net.addOutputModule(LinearLayer(6, name='out'))
self.net.addConnection(FullConnection(self.net['in'], self.net['hidden']))
self.net.addConnection(FullConnection(self.net['hidden'], self.net['out']))
self.net.sortModules()
# thresholds for deciding an action
self.move_threshold = 0
self.pickup_threshold = 0
self.putdown_threshold = 0
self.eat_threshold = 0
示例9: __init__
def __init__(self, input_size, output_size, number_of_layers=3, size_of_hidden_layers=3, type_of_hidden_layer='sigmoid', net_bias=False, epochs=100):
self.net = FeedForwardNetwork()
self.num_epochs = epochs
# set up layers of the network
layers = []
for i in range(number_of_layers):
if i == 0:
layers.append(LinearLayer(input_size))
self.net.addInputModule(layers[i])
elif i == (number_of_layers-1):
layers.append(LinearLayer(output_size))
self.net.addOutputModule(layers[i])
self.net.addConnection(FullConnection(layers[i-1], layers[i]))
else:
if type_of_hidden_layer == 'linear':
layers.append(LinearLayer((input_size + output_size) / 2))
elif type_of_hidden_layer == 'sigmoid':
layers.append(SigmoidLayer((input_size + output_size) / 2))
elif type_of_hidden_layer == 'tanh':
layers.append(TanhLayer((input_size + output_size) / 2))
self.net.addModule(layers[i])
self.net.addConnection(FullConnection(layers[i-1], layers[i]))
self.net.sortModules()
self.input_size = input_size
self.output_size = output_size
示例10: __init__
def __init__(self, grid_size, hidden_list):
"""Sets up the neural network.
@param grid_size: the size of the grid, for specifying the input layer.
@param hidden_list: a list containing the number of nodes in each hidden layer.
"""
self.net = FeedForwardNetwork()
in_layer = LinearLayer(grid_size*grid_size)
self.net.addInputModule(in_layer)
out_layer = LinearLayer(4)
self.net.addOutputModule(out_layer)
hidden_layers = []
for i in hidden_list:
hidden_layer = SigmoidLayer(i)
hidden_layers.append(hidden_layer)
self.net.addModule(hidden_layer)
self.net.addConnection(FullConnection(in_layer, hidden_layers[0]))
if len(hidden_layers) > 1:
for i in range(1, len(hidden_layers) - 1):
self.net.addConnection(FullConnection(hidden_layers[i], hidden_layers[i+1]))
self.net.addConnection(FullConnection(hidden_layers[-1], out_layer))
self.net.sortModules()
示例11: _new_1h_net
def _new_1h_net(window):
net = FeedForwardNetwork()
inl = SigmoidLayer(window*window*2+1)
hidden1 = SigmoidLayer(window*window*2)
outl = SigmoidLayer(1)
net.addInputModule(inl)
net.addModule(hidden1)
net.addOutputModule(outl)
c1 = FullConnection(inl, hidden1)
c2 = FullConnection(hidden1, outl)
net.addConnection(c1)
net.addConnection(c2)
return net
示例12: simple_network
def simple_network(data, digit, train_ds, test_ds):
# n = buildNetwork(train_ds.indim, 1, train_ds.outdim, outclass=SoftmaxLayer)
n = FeedForwardNetwork()
inLayer = LinearLayer(64)
outLayer = SoftmaxLayer(10)
n.addInputModule(inLayer)
n.addOutputModule(outLayer)
n.addConnection(FullConnection(inLayer, outLayer))
n.sortModules()
trainer = BackpropTrainer(n, dataset=train_ds, momentum=0.1, verbose=True,
weightdecay=0.01)
trainer.trainUntilConvergence(maxEpochs=25)
result = percentError(trainer.testOnClassData(dataset=test_ds),
test_ds['class'])
# result = validate(trainer, train_ds, 5, 10)
print 'Simple network - Percent Error', result
return result
示例13: __init__
def __init__(self, hidden_neuron_num=1, hidden_type='sigmoid'):
self.hidden_neuron_num = hidden_neuron_num
self.hidden_type = hidden_type
self.net = FeedForwardNetwork()
self.samples = SupervisedDataSet(784, 784)
self.vectorizer = ImageVectorizer()
self.add_layers()
self.add_connections()
self.sort()
示例14: __init__
def __init__(self, num_features, num_hidden_neurons):
super(NNet,self).__init__(num_features)
self.ds = SupervisedDataSet(num_features, 1)
self.net = FeedForwardNetwork()
self.net.addInputModule(LinearLayer(num_features, name='in'))
self.net.addModule(LinearLayer(num_hidden_neurons, name='hidden'))
self.net.addOutputModule(LinearLayer(1, name='out'))
self.net.addConnection(FullConnection(self.net['in'], self.net['hidden'], name='c1'))
self.net.addConnection(FullConnection(self.net['hidden'], self.net['out'], name='c2'))
self.net.sortModules()
示例15: train
def train(self):
n = FeedForwardNetwork()
dataModel = SongFactory(self.major).getModels()
ds = SupervisedDataSet(static.NUM_OF_INPUTS, 1)
#adds samples from the data received from songfactory and the k
for data in dataModel:
for input, target in data.model:
print input, target
ds.addSample(input, target)
#instantiate the network
self.net = FeedForwardNetwork()
bias = BiasUnit()
self.net.addModule(bias)
#create the layers of the network
inLayer = LinearLayer(static.NUM_OF_INPUTS)
outLayer = LinearLayer(1)
hidden1 = SigmoidLayer(25)
hidden2 = SigmoidLayer(5)
#add the layers
self.net.addInputModule(inLayer)
self.net.addOutputModule(outLayer)
self.net.addModule(hidden1)
self.net.addModule(hidden2)
#create the connection
in_h1 = FullConnection(inLayer,hidden1)
h1_h2 = FullConnection(hidden1, hidden2)
h2_out = FullConnection(hidden2, outLayer)
b_h1 = FullConnection(bias, hidden1)
b_h2 = FullConnection(bias, hidden2)
#add the connection
self.net.addConnection(in_h1)
self.net.addConnection(h1_h2)
self.net.addConnection(h2_out)
self.net.addConnection(b_h1)
self.net.addConnection(b_h2)
self.net.sortModules()
#trainer to edit the network
trainer = BackpropTrainer(self.net, ds, learningrate = 0.003)
trainer.trainEpochs(25)