示例#1
0
 def __init__(self, frame):
     self.frame = frame
     self.model = nets.NetEditor.newNet(100, 10, Neurons.Sigmoid(),
                                        nets.Net.leastSquaredDerivative,
                                        (Neurons.Sigmoid(), 55))
     self.buttons = list()
     self.font = pygame.font.SysFont("arial", 14)
示例#2
0
 def __init__(self, n, weight_lenght, type):
     neurons = []
     for i in range(n):
         weight = []
         bias = random.uniform(-2, 2)
         for w in range(weight_lenght):
             weight.append(random.uniform(-2, 2))
         if type == "sigmoid":
             neuron = Neurons.Sigmoid(weight, bias)
         else:
             neuron = Neurons.Perceptron(weight, bias)
         neurons.append(neuron)
     self.neurons = neurons
     self.next_layer = None
     self.previous_layer = None
示例#3
0
def createSimple(numInputs, numOutputs):
  
  synapse = Synapses.createRootSynapse()
  seed = Neurons.createRootNeuron([synapse], [synapse])
  
  inputSynapses = [Synapses.createRootSynapse() for i in range(numInputs)]
  outputSynapses = [Synapses.createRootSynapse() for i in range(numOutputs)]
  
  "Connect seed to inputs and outputs."
  inputNeurons = [InputNeuron(None, [], [inputSynapses[i]], zeros(Neurons.inputDivisionDataSize), \
                              inputTree()) for i in range(numInputs)]
  outputNeurons = [OutputNeuron(None, [outputSynapses[i]], [], zeros(Neurons.divisionDataSize)) \
                   for i in range(numOutputs)]
  
  inputNeuron = inputNeurons[-1]
  outputNeuron = outputNeurons[-1]
  inputSynapse = inputNeuron.getSynapse()
  outputSynapse = outputNeuron.getSynapse()
  
  "edit contents"
  inputNeuron.data[Neurons.fireRateFunEnd - 1] = -2
  inputNeuron.data[Neurons.fireRateFun] = 10
  inputNeuron.data[Neurons.evolveRateFunEnd - 1] = 4
  inputNeuron.data[Neurons.sensitivityFunEnd - 1] = 1
  inputNeuron.data[Neurons.inputEvolveTransform + Neurons.dataSize + Neurons.inputSize] = -2
  inputNeuron.data[Neurons.inputEvolveTransform] = 4
  inputNeuron.data[Neurons.inputEvolveTransform + \
                   Neurons.dataSize * (Neurons.dataSize + 2)] = 0.2
  
  seed.data[Neurons.fireRateFunEnd - 1] = -2
  seed.data[Neurons.fireRateFun] = 10
  seed.data[Neurons.evolveRateFunEnd - 1] = 4
  seed.data[Neurons.sensitivityFunEnd - 1] = 1
  seed.data[Neurons.evolveTransform + Neurons.dataSize] = -2
  seed.data[Neurons.evolveTransform + \
                   Neurons.dataSize * (Neurons.dataSize + 1)] = 0.2
  
  outputNeuron.data[Neurons.fireRateFunEnd - 1] = -2
  outputNeuron.data[Neurons.fireRateFun] = 10
  outputNeuron.data[Neurons.evolveRateFunEnd - 1] = 4
  outputNeuron.data[Neurons.sensitivityFunEnd - 1] = 1
  outputNeuron.data[Neurons.evolveTransform + Neurons.dataSize] = -2
  outputNeuron.data[Neurons.evolveTransform + \
                   Neurons.dataSize * (Neurons.dataSize + 1)] = 0.2
  
  inputSynapse.data[Synapses.weightFunEnd - 1] = 1
  inputSynapse.data[Synapses.activationFunEnd - 1] = 1
  
  outputSynapse.data[Synapses.weightFunEnd - 1] = 1
  outputSynapse.data[Synapses.activationFunEnd - 1] = 1
  "done editing contents"
  
  brain = Brain(seed, numInputs, numOutputs, inputNeurons, outputNeurons)
  brain._startTime()
  return brain
示例#4
0
 def build(self):
     # check if we have the legal dimension
     if self.x == 0:
         print('ERROR! You have to assign a cluster size.')
     # 1-dimensional
     elif self.y == 0:
         for i in range(self.x):
             self.cluster.append(Neurons.LIF())
         # check whether the cluster size is correct
         if len(self.cluster) != self.x:
             print('ERROR! Size of cluster is not correct.')
         self.dimension = 1
     # 2-dimensional
     else:
         for i in range(self.x):
             self.cluster.append([])
             for j in range(self.y):
                 self.cluster[i].append(Neurons.LIF())
         # check whether the cluster size is correct
         if len(self.cluster) * len(self.cluster[0]) != self.x * self.y:
             print('ERROR! Size of cluster is not correct.')
         self.dimension = 2
示例#5
0
def createEmpty(numInputs, numOutputs):
  "Create isolated seed."
  synapse = Synapses.createRootSynapse()
  seed = Neurons.createRootNeuron([synapse], [synapse])
  
  inputSynapses = [Synapses.createRootSynapse() for i in range(numInputs)]
  outputSynapses = [Synapses.createRootSynapse() for i in range(numOutputs)]
  
  "Connect seed to inputs and outputs."
  inputNeurons = [InputNeuron(None, [], [inputSynapses[i]], zeros(Neurons.inputDivisionDataSize), \
                              inputTree()) for i in range(numInputs)]
  outputNeurons = [OutputNeuron(None, [outputSynapses[i]], [], zeros(Neurons.divisionDataSize)) \
                   for i in range(numOutputs)]
  
  "Make and start brain."
  brain = Brain(seed, numInputs, numOutputs, inputNeurons, outputNeurons)
  brain._startTime()
  return brain
示例#6
0
 def __init__(self, previous_layer_size=1, size=1, values=[]):
     self.size = size
     self.previous_layer_size = previous_layer_size
     self.biases = []
     self.values = []
     self.neurons = []
     self.z = []
     self.weights = []
     self.error = []
     self.grad = {"W": None, "b": None}
     if len(values) != size and len(values) != 0:
         print("Input size mismatch")
     for i in range(self.size):
         self.neurons.append(
             Neurons.Neuron(previous_layer_size=self.previous_layer_size))
         if len(values) == size:
             self.neurons[i].value = values[i]
     if self.previous_layer_size != 0:
         self.initialize_parameters()
示例#7
0
 def populate_grid(self):
     self.currentcount = 1
     self.dictsize = self.xmax * self.ymax * self.zmax
     self.neuraldictionary = {}
     self.current_listpos = 1
     self.current_xpos  = 1
     self.current_ypos = 1
     self.current_zpos = 1
     for neuron in range(1,(self.dictsize + 1)):
         self.neuraldictionary.update({(self.current_xpos, self.current_ypos, self.current_zpos):
                                           neur.DigiNeuron(x=self.current_xpos,y=self.current_ypos,
                                                           z=self.current_zpos)})
         if self.current_ypos > self.ymax:
             self.current_xpos = 1
             self.current_ypos = 1
             self.current_zpos = self.current_zpos + 1
         elif self.current_xpos > self.xmax:
             self.current_xpos = 1
             self.current_ypos = self.current_ypos + 1
         elif self.current_xpos < self.xmax:
             self.current_xpos = self.current_xpos + 1
示例#8
0
 def testSoftmaxFire(self):
     neuron = n.SoftMax()
     arr = neuron.fire(self.arr)
     self.assertEquals(len(arr), len(self.arr))
示例#9
0
# @Email   : [email protected]
# @GitHub  : https://github.com/hello-roderickwang


import Neurons
import Synapse
import Cluster
import numpy as np
import matplotlib.pyplot as plt


if __name__ == '__main__':
    x = np.linspace(-np.pi, np.pi, 201)
    sin = (np.sin(x)+1)/2

    a = Neurons.LIF()
    b = Neurons.LIF()

    weight = 2

    connection = Synapse.Synapse(a, b)
    connection.set_weight(weight)

    v_a = []
    v_b = []

    for step in range(0, len(sin)):
        a.stimulate(sin[step])
        a.go()
        v_a.append(a.out)
        connection.go()
示例#10
0
 def onClick(self):
     layer = nets.Layer(Neurons.Sigmoid(), 3, nets.Layer.HIDDEN)
     nets.NetEditor.spliceIn(layer, self.upLayer, self.downLayer)