Ejemplo n.º 1
0
        public LeakyIntegrateFireNetwork(int[] layers, double lambda = 0.001)
        {
            Lambda = lambda;

            Nodes         = new List <LeakyIntegrateAndFireNode> [layers.Length];
            InputSynapses = new SynapseObject[layers[0]]; //input same size as input nodes

            OutputLayerIndex = layers.Length - 1;

            messageHandling = new MessageHandling(layers[OutputLayerIndex]);

            //setup of Network

            List <LeakyIntegrateAndFireNode> prev_layer = new List <LeakyIntegrateAndFireNode>();

            //setup (input and) hidden layers & connections to previous layers
            for (int layer_count = 0; layer_count < OutputLayerIndex; layer_count++)
            {
                List <LeakyIntegrateAndFireNode> temp_layer = new List <LeakyIntegrateAndFireNode>();

                for (int node_count = 0; node_count < layers[layer_count]; node_count++)
                {
                    LeakyIntegrateAndFireNode new_node = new LeakyIntegrateAndFireNode(messageHandling, layerIndex: layer_count, nodeIndex: node_count, lambda: Lambda);


                    foreach (LeakyIntegrateAndFireNode prev_node in prev_layer)
                    {
                        //setup the connections between the nodes
                        SynapseObject s = new SynapseObject(prev_node, new_node, 1);
                        prev_node.addTarget(s);
                        new_node.addSource(s);
                    }

                    if (layer_count == 0) // input layer
                    {
                        //setup the input synapses (one synapse going to first layer of nodes)
                        SynapseObject input_synapse = new SynapseObject(null, new_node, 1);
                        new_node.addSource(input_synapse);
                        InputSynapses[node_count] = input_synapse;
                    }

                    double input_norm  = Math.Sqrt(3.0 / (double)new_node.Inputs.Count);
                    double input_range = input_norm * 2;

                    new_node.Bias = input_norm;
                    if (layer_count != 0)
                    {
                        foreach (SynapseObject input in new_node.Inputs)
                        {
                            input.Weight = random.NextDouble() * input_norm;
                        }
                    }
                    temp_layer.Add(new_node);
                }

                prev_layer = new List <LeakyIntegrateAndFireNode>(temp_layer);

                Nodes[layer_count] = prev_layer;
            }

            List <LeakyIntegrateAndFireNode> outs = new List <LeakyIntegrateAndFireNode>();

            //setup output layer
            for (int node_count = 0; node_count < layers[OutputLayerIndex]; node_count++)
            {
                OutputNode outnode = new OutputNode(messageHandling, layerIndex: OutputLayerIndex, nodeIndex: node_count, Excitatory: 1, lambda: Lambda);
                foreach (LeakyIntegrateAndFireNode prev_node in prev_layer)
                {
                    //setup the connections between the nodes
                    SynapseObject s = new SynapseObject(prev_node, outnode, 1);
                    prev_node.addTarget(s);
                    outnode.addSource(s);
                }

                double input_norm  = Math.Sqrt(3.0 / (double)outnode.Inputs.Count);
                double input_range = input_norm * 2;

                outnode.Bias = input_norm;
                foreach (SynapseObject input in outnode.Inputs)
                {
                    input.Weight = random.NextDouble() * input_norm;;
                }

                outs.Add(outnode);
            }

            Nodes[OutputLayerIndex] = outs; //add the output nodes to the last layer
        }
Ejemplo n.º 2
0
 public OutputMessage(int time, SynapseObject synapse, double val = 1) : base(time, synapse, val)
 {
 }
Ejemplo n.º 3
0
 public void addSource(SynapseObject source)
 {
     Inputs.Add(source);
 }
Ejemplo n.º 4
0
        }                                       //passing different values to the nodes. set at one unless needed (e.g. for inhibitory)

        public Message(int time, SynapseObject synapse, double val = 1)
        {
            Time    = time;
            Synapse = synapse;
            Val     = val;
        }
Ejemplo n.º 5
0
 public void addTarget(SynapseObject target)
 {
     Outputs.Add(target);
 }