def show(title, a, b, c, d): n = Neuron(0.0, a, b, c, d) spike_train = [] for i in range(1000): n.current = 0.0 if i < 100 or i > 800 else 10.0 spike_train.append((1.0 * i, n.current, n.v, n.u)) print('{0:d}\t{1:f}\t{2:f}\t{3:f}'.format(i, n.current, n.v, n.u)) n.advance() visualize.plot_spikes(spike_train, view=False, title=title)
def show(title, a, b, c, d): n = Neuron(0.0, a, b, c, d) spike_train = [] for i in range(1000): n.current = 0.0 if i < 100 or i > 800 else 10.0 spike_train.append((1.0 * i, n.current, n.v, n.u)) print('%d\t%f\t%f\t%f' % (i, n.current, n.v, n.u)) n.advance() visualize.plot_spikes(spike_train, view=True, title=title)
self.__has_fired = False self.current = self.__bias potential = property(lambda self: self.__v, doc = 'Membrane potential') has_fired = property(lambda self: self.__has_fired, doc = 'Indicates whether the neuron has fired') class Synapse: """ A synapse indicates the connection strength between two neurons (or itself) """ def __init__(self, source, dest, weight): self.__weight = weight self.__source = source self.__dest = dest def advance(self): 'Advances time in 1 ms.' if self.__source.has_fired: self.__dest.current += self.__weight # dest.current or dest.__v ? if __name__ == '__main__': from neat import visualize n = Neuron(10) neuron_membrane = [] for i in range(1000): neuron_membrane.append(n.potential) #print '%d\t%f' % (i, n.potential) n.advance() visualize.plot_spikes(neuron_membrane)
def create_phenotype(chromosome): """ Receives a chromosome and returns its phenotype (a neural network) """ neurons = {} input_neurons = [] output_neurons = [] for ng in chromosome.node_genes: neurons[ng.id] = Neuron(ng.bias) if ng.type == 'INPUT': input_neurons.append(neurons[ng.id]) elif ng.type == 'OUTPUT': output_neurons.append(neurons[ng.id]) synapses = [Synapse(neurons[cg.innodeid], neurons[cg.outnodeid], cg.weight) \ for cg in chromosome.conn_genes if cg.enabled] return Network(neurons, input_neurons, output_neurons, synapses) if __name__ == '__main__': from neat import visualize 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)
neurons = property(lambda self: self.__neurons.values()) def create_phenotype(chromosome): """ Receives a chromosome and returns its phenotype (a neural network) """ neurons = {} input_neurons = [] output_neurons = [] for ng in chromosome.node_genes: neurons[ng.id] = Neuron(ng.bias) if ng.type == 'INPUT': input_neurons.append(neurons[ng.id]) elif ng.type == 'OUTPUT': output_neurons.append(neurons[ng.id]) synapses = [Synapse(neurons[cg.innodeid], neurons[cg.outnodeid], cg.weight) \ for cg in chromosome.conn_genes if cg.enabled] return Network(neurons, input_neurons, output_neurons, synapses) if __name__ == '__main__': from neat import visualize 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)