def create_simple(): neurons = [Neuron('INPUT', 1, 0.0, 5.0, 'sigmoid'), Neuron('HIDDEN', 2, 0.0, 5.0, 'sigmoid'), Neuron('OUTPUT', 3, 0.0, 5.0, 'sigmoid')] connections = [(1, 2, 0.5), (1, 3, 0.5), (2, 3, 0.5)] return Network(neurons, connections, 1)
def test_basic(): # create two output neurons (they won't receive any external inputs) n1 = CTNeuron('OUTPUT', 1, -2.75, 1.0, 'sigmoid', 0.5) n2 = CTNeuron('OUTPUT', 2, -1.75, 1.0, 'sigmoid', 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 = Network(neurons_list, conn_list, 0) # activates the network print("{0:.7f} {1:.7f}".format(n1.output, n2.output)) outputs = [] for i in range(1000): output = net.parallel_activate() outputs.append(output) print("{0:.7f} {1:.7f}".format(output[0], output[1]))
import numpy as np import matplotlib.pyplot as plt from neatsociety.ctrnn import CTNeuron, Network # create two output neurons (they won't receive any external inputs) N1 = CTNeuron('OUTPUT', 1, -2.75, 1.0, 'sigmoid', 0.5) N2 = CTNeuron('OUTPUT', 2, -1.75, 1.0, 'sigmoid', 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 = Network(neurons_list, conn_list, 0) # activates the network print("{0:.7f} {1:.7f}".format(N1.output, N2.output)) outputs = [] for i in range(1000): output = net.parallel_activate() outputs.append(output) print("{0:.7f} {1:.7f}".format(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")