-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new file: class_pybrain.py modified: iris_dataset.py modified: neuralnets_functions.py
- Loading branch information
Showing
5 changed files
with
60 additions
and
5 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import pybrain | ||
|
||
from pybrain.tools.shortcuts import buildNetwork | ||
from pybrain.datasets import SupervisedDataSet | ||
from pybrain.supervised import BackpropTrainer | ||
from pybrain.structure.modules import SigmoidLayer | ||
|
||
network = buildNetwork(2,3,1,outclass = SigmoidLayer, bias = False) | ||
|
||
dataset = SupervisedDataSet(2,1) | ||
dataset.addSample((0,0),(0,)) | ||
dataset.addSample((0,1),(1,)) | ||
dataset.addSample((1,0),(1,)) | ||
dataset.addSample((1,1),(0,)) | ||
|
||
optimizer = BackpropTrainer(module=network, dataset = dataset, learningrate = 0.3) | ||
epochs = 5000 | ||
error = [] | ||
for epoch in range(epochs): | ||
error_average = optimizer.train() | ||
if epoch % 1000 == 0: | ||
print('Epoch: ' + str(epoch + 1) + ' Error: ' + str(error_average)) | ||
error.append(error_average) | ||
print('Epoch: ' + str(epoch + 1) + ' Error: ' + str(error_average)) | ||
|
||
import matplotlib.pyplot as plt | ||
plt.xlabel('Epoch') | ||
plt.ylabel('Error') | ||
plt.plot(error) | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pybrain | ||
|
||
from pybrain.structure import FeedForwardNetwork | ||
from pybrain.structure import SigmoidLayer, LinearLayer, BiasUnit | ||
from pybrain.structure import FullConnection | ||
|
||
network = FeedForwardNetwork() | ||
input_layer = LinearLayer(2) | ||
hidden_layer = SigmoidLayer(3) | ||
output_layer = SigmoidLayer(1) | ||
bias0 = BiasUnit() | ||
bias1 = BiasUnit() | ||
|
||
network.addModule(input_layer) | ||
network.addModule(hidden_layer) | ||
network.addModule(output_layer) | ||
network.addModule(bias0) | ||
network.addModule(bias1) | ||
|
||
input_to_hidden = FullConnection(input_layer, hidden_layer) | ||
hidden_to_output= FullConnection(hidden_layer, output_layer) | ||
bias_hidden = FullConnection(bias0, hidden_layer) | ||
bias_output = FullConnection(bias1, output_layer) | ||
|
||
network.sortModules() | ||
print(input_to_hidden.params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters