forked from CodeReclaimers/neat-python
-
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.
Removed C++ implementations (they may be restored and cleaned up to m…
…atch the final implementation in a later version). Moved code in the library that looks like tests and/or demos into a "basic" examples directory. Added example script to produce animation of single-pole balancing output. Added "delete connection" as a mutation option. Updated CTRNN version of single-pole balancing to work with current code. Fix typos and PEP 8 complaints. Removed unused/commented code. Added numpy as an explicit dependency.
- Loading branch information
1 parent
8cf3000
commit bdd636e
Showing
48 changed files
with
852 additions
and
2,123 deletions.
There are no files selected for viewing
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,33 @@ | ||
from neat import visualize, genome | ||
from neat import chromosome | ||
from neat.config import Config | ||
|
||
|
||
# Example | ||
# define some attributes | ||
node_gene_type = genome.NodeGene # standard neuron model | ||
conn_gene_type = genome.ConnectionGene # and connection link | ||
Config.nn_activation = 'exp' # activation function | ||
Config.weight_stdev = 0.9 # weights distribution | ||
|
||
Config.input_nodes = 2 # number of inputs | ||
Config.output_nodes = 1 # number of outputs | ||
|
||
# creates a chromosome for recurrent networks | ||
# c1 = Chromosome.create_fully_connected() | ||
|
||
# creates a chromosome for feedforward networks | ||
chromosome.node_gene_type = genome.NodeGene | ||
|
||
c2 = chromosome.FFChromosome.create_fully_connected() | ||
# add two hidden nodes | ||
c2.add_hidden_nodes(2) | ||
# apply some mutations | ||
# c2._mutate_add_node() | ||
# c2._mutate_add_connection() | ||
|
||
# check the result | ||
# visualize.draw_net(c1) # for recurrent nets | ||
visualize.draw_net(c2, view=True) # for feedforward nets | ||
# print the chromosome | ||
print c2 |
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,38 @@ | ||
# This example follows from Beer's C++ source code available at: | ||
# http://mypage.iu.edu/~rdbeer/ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
from neat.nn import nn_pure as nn | ||
from neat.ctrnn import CTNeuron | ||
|
||
# create two output neurons (they won't receive any external inputs) | ||
N1 = CTNeuron('OUTPUT', 1, -2.75, 1.0, 'exp', 0.5) | ||
N2 = CTNeuron('OUTPUT', 2, -1.75, 1.0, 'exp', 0.5) | ||
N1.set_init_state(-0.084000643) | ||
N2.set_init_state(-0.408035109) | ||
|
||
neurons_list = [N1, N2] | ||
# create some synapses | ||
conn_list = [(1, 1, 4.5), (1, 2, -1.0), (2, 1, 1.0), (2, 2, 4.5)] | ||
# create the network | ||
net = nn.Network(neurons_list, conn_list) | ||
# activates the network | ||
print "%.17f %.17f" % (N1._output, N2._output) | ||
outputs = [] | ||
for i in xrange(1000): | ||
output = net.pactivate() | ||
outputs.append(output) | ||
print "%.17f %.17f" % (output[0], output[1]) | ||
|
||
outputs = np.array(outputs).T | ||
|
||
plt.title("CTRNN model") | ||
plt.ylabel("Outputs") | ||
plt.xlabel("Time") | ||
plt.grid() | ||
plt.plot(outputs[0], "g-", label="output 0") | ||
plt.plot(outputs[1], "r-", label="output 1") | ||
plt.legend(loc="best") | ||
plt.show() | ||
plt.close() |
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,11 @@ | ||
from neat import visualize | ||
from neat.iznn import Neuron | ||
|
||
n = Neuron(10) | ||
spike_train = [] | ||
for i in range(1000): | ||
spike_train.append(n.potential) | ||
print '%d\t%f' % (i, n.potential) | ||
n.advance() | ||
|
||
visualize.plot_spikes(spike_train, view=True, filename='spiking_neuron.svg') |
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,22 @@ | ||
# Example | ||
# from neat import visualize | ||
from neat.nn.nn_pure import FeedForward | ||
|
||
nn = FeedForward([2, 10, 3], use_bias=False, activation_type='exp') | ||
##visualize.draw_ff(nn) | ||
print 'Serial activation method: ' | ||
for t in range(3): | ||
print nn.sactivate([1, 1]) | ||
|
||
# print 'Parallel activation method: ' | ||
# for t in range(3): | ||
# print nn.pactivate([1,1]) | ||
|
||
# defining a neural network manually | ||
# neurons = [Neuron('INPUT', 1), Neuron('HIDDEN', 2), Neuron('OUTPUT', 3)] | ||
# connections = [(1, 2, 0.5), (1, 3, 0.5), (2, 3, 0.5)] | ||
|
||
# net = Network(neurons, connections) # constructs the neural network | ||
# visualize.draw_ff(net) | ||
# print net.pactivate([0.04]) # parallel activation method | ||
# print net # print how many neurons and synapses our network has |
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,18 @@ | ||
# TODO: fix this and turn it into a real test. | ||
from neat.population import Population | ||
from neat import config, chromosome, genome | ||
|
||
config.Config.pop_size = 100 | ||
chromosome.node_gene_type = genome.NodeGene | ||
|
||
|
||
# sample fitness function | ||
def eval_fitness(population): | ||
for individual in population: | ||
individual.fitness = 1.0 | ||
|
||
|
||
# creates the population | ||
pop = Population() | ||
# runs the simulation for 250 epochs | ||
pop.epoch(eval_fitness, 250) |
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
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
Oops, something went wrong.