Beispiel #1
0
        /// <summary>
        /// Initialization Prior to receiving any inputs, the region is initialized by computing a list of initial potential
        /// synapses for each column. This consists of a random set of inputs selected from the input space. Each input is
        /// represented by a synapse and assigned a random permanence value. The random permanence values are chosen with two
        /// criteria. First, the values are chosen to be in a small range around connectedPerm (the minimum permanence value
        /// at which a synapse is considered "connected"). This enables potential synapses to become connected (or
        /// disconnected) after a small number of training iterations. Second, each column has a natural center over the
        /// input region, and the permanence values have a bias towards this center (they have higher values near the
        /// center).
        /// </summary>
        /// <param name="input"></param>
        public void Init(HtmInput input)
        {
            _input         = input;
            _columnList    = new List <HtmColumn>();
            _activeColumns = new List <HtmColumn>();

            var inputIndexList = new List <int>();


            for (int i = 0; i < input.Matrix.GetLength(0) * input.Matrix.GetLength(1); i++)
            {
                inputIndexList.Add(i);
            }

            IEnumerable <KMeansCluster> clusters = KMeansAlgorithm.FindMatrixClusters(input.Matrix.GetLength(0), input.Matrix.GetLength(1), HtmParameters.ColumnsCount);

            foreach (KMeansCluster cluster in clusters)
            {
                List <int> htmSynapses = inputIndexList.Shuffle(Ran).ToList();
                var        synapses    = new List <HtmForwardSynapse>();

                for (int j = 0; j < HtmParameters.AmountOfPotentialSynapses; j++)
                {
                    var newSynapse = new HtmForwardSynapse(HtmParameters.ConnectedPermanence)
                    {
                        Input      = input,
                        Y          = htmSynapses[j] / input.Matrix.GetLength(0),
                        X          = htmSynapses[j] % input.Matrix.GetLength(0),
                        Permanance = (Ran.Next(5)) / (double)10,
                    };

                    synapses.Add(newSynapse);
                }

                _columnList.Add(new HtmColumn
                {
                    Y = (int)Math.Round(cluster.Location.Y),
                    X = (int)Math.Round(cluster.Location.X),
                    PotentialSynapses = synapses
                });
            }


            _activeColumns = new List <HtmColumn>();
        }
Beispiel #2
0
 public HtmSpatialPooler(HtmInput input)
 {
     _inhibitionRadius = HtmParameters.InhibitionRatio;
     Init(input);
 }