예제 #1
0
파일: Node.cs 프로젝트: beno11224/SNNLib
 public Node(MessageHandling h, int layerIndex, int nodeIndex)
 {
     Inputs             = new List <SynapseObject>();
     Outputs            = new List <SynapseObject>();
     messageHandler     = h;
     LayerIndex         = layerIndex;
     NodeIndex          = nodeIndex;
     Bias               = 1;
     Delay              = 1;
     InputMessages      = new List <Message>();
     InputMesssageNodes = new List <Node>();
     OutputMessages     = new List <Message>();
 }
예제 #2
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
        }
예제 #3
0
파일: Node.cs 프로젝트: beno11224/SNNLib
 public LeakyIntegrateAndFireNode(MessageHandling h, int layerIndex, int nodeIndex, double lambda = 1) : base(h, layerIndex, nodeIndex)
 {
     Lambda = lambda;
 }
예제 #4
0
파일: Node.cs 프로젝트: beno11224/SNNLib
 public OutputNode(MessageHandling h, int layerIndex, int nodeIndex, double lambda = 1, int Excitatory = 1) : base(h, layerIndex, nodeIndex, lambda)
 {
 }