예제 #1
0
        /// <summary>
        /// build the input connectivity matrix.
        /// </summary>
        public void setInputConnectivity()
        {
            System.Random rand = new System.Random();
            inputConnections.Clear();

            foreach (NeuronIzhikevich n in neurons)
            {
                n.inputsConnections.Clear();
            }

            foreach (string key in modalities.Keys)
            {
                inputConnections[key] = new List <NeuronIzhikevich.Connection> [modalities[key].Size];
                for (int m = 0; m < modalities[key].Size; m++)
                {
                    inputConnections[key][m] = new List <NeuronIzhikevich.Connection>();
                    //Create the connection with a random weight
                    //inputConnections[key][m].Add(new NeuronIzhikevich.Connection(ref neurons[x, y], 1.0, rand.NextDouble()));
                    for (int x = 0; x < width; x++)
                    {
                        for (int y = 0; y < height; y++)
                        {
                            NeuronIzhikevich.Connection c = new NeuronIzhikevich.Connection(neurons[x, y], 1.0, 0.5 /*rand.NextDouble()*/);
                            inputConnections[key][m].Add(c);
                            neurons[x, y].inputsConnections.Add(c);
                        }
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Reset the local connectivity of the map
        /// </summary>
        /// <param name="neighboorRadius"></param>
        protected void setLateralConnectivity(double neighboorRadius, double lateralW = 0.4)
        {
            //Reset the lateral connextivity the neurons
            lateralConnections.Clear();
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    neurons[x, y].lateralProjections.Clear();
                }
            }

            //Build the connections
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    //Go through all the connected neurons
                    for (int y2 = y - (int)neighboorRadius; y2 <= y + (int)neighboorRadius; y2++)
                    {
                        for (int x2 = x - (int)neighboorRadius; x2 <= x + (int)neighboorRadius; x2++)
                        {
                            //Calculate the right index for this connection (here we can go circular)
                            //For now we just check if the index is inbounds
                            if (y2 >= 0 && y2 < height &&
                                x2 >= 0 && x2 < width &&
                                (x != x2 || y != y2))
                            {
                                //if (x != x2 || y != y2)
                                {
                                    double distance = MathFunctions.EuclideanDistance(new float[] { x, y }, new float[] { x2, y2 });
                                    //Console.WriteLine("Distance = " + distance + " Neighbor = " + neighboorRadius);
                                    //If the neuron is in the neihboor range
                                    if (distance < neighboorRadius)
                                    {
                                        //We add a connection with strenght shaped by a mexican hat
                                        //We calculate sigma to so that the inhibition takes place on the border of the neighborhood
                                        float sigma    = (float)neighboorRadius / 4.0f;
                                        float strenght = (float)MathFunctions.MexicanHat((float)distance, sigma);
                                        //Console.Write(strenght);
                                        //float strenght = (float)lateralW;
                                        NeuronIzhikevich.Connection cnt = new NeuronIzhikevich.Connection(neurons[x2, y2], distance, strenght);
                                        lateralConnections.Add(cnt);
                                        neurons[x, y].lateralProjections.Add(cnt);
                                    }
                                }
                            }
                        }
                        //Console.WriteLine();
                    }
                }
            }
        }