/// <summary>
        /// Initialize all columns inside of partition and connect them to sensory input.
        /// It returns the average connected span of the partition.
        /// </summary>
        /// <param name="msg"></param>
        private void createAndConnectColumns(ConnectAndConfigureColumnsMsg msg)
        {
            DateTime startTime = DateTime.Now;

            Log(msg, Self, "Entered.");

            List <double> avgConnections = new List <double>();

            Random rnd;

            if (this.config.RandomGenSeed > 0)
            {
                rnd = new Random(this.config.RandomGenSeed);
            }
            else
            {
                rnd = new Random();
            }

            if (this.dict.Count == 0)
            {
            }

            foreach (var element in this.dict)
            {
                if (this.config == null)
                {
                    throw new ArgumentException($"HtmConfig must be set in the message.");
                }

                int colIndx = (int)element.Key;

                // Gets RF
                var potential = HtmCompute.MapPotential(this.config, colIndx, rnd);
                var column    = (Column)this.dict[colIndx];

                // This line initializes all synases in the potential pool of synapses.
                // It creates the pool on proximal dendrite segment of the column.
                // After initialization permancences are set to zero.
                //connectColumnToInputRF(c.HtmConfig, data.Potential, data.Column);
                column.CreatePotentialPool(this.config, potential, -1);

                var perms = HtmCompute.InitSynapsePermanences(this.config, potential, rnd);

                avgConnections.Add(HtmCompute.CalcAvgSpanOfConnectedSynapses(column, this.config));

                //Log(msg, Self, $".:). {dict.Count}/{dict.Keys.Min()}/{dict.Keys.Min()} - duration: {(DateTime.Now - startTime).TotalSeconds}");

                HtmCompute.UpdatePermanencesForColumn(this.config, perms, column, potential, true);
            }

            double avgConnectedSpan = ArrayUtils.average(avgConnections.ToArray());

            Log(msg, Self, "Completed.");
            Sender.Tell(avgConnectedSpan, Self);
            Log(msg, Self, $"Response sent. {(DateTime.Now - startTime).TotalSeconds}");
        }
Example #2
0
        /// <summary>
        /// Initialize all columns inside of partition and connect them to sensory input.
        /// It returns the average connected span of the partition.
        /// </summary>
        /// <param name="msg"></param>
        //TODO remove unnecessary argument
        private double CreateAndConnectColumns(ConnectAndConfigureColumnsMsg msg)
        {
            Debug.Write(".");
            List <double> avgConnections = new List <double>();

            Random rnd;

            if (this.HtmConfig.RandomGenSeed > 0)
            {
                rnd = new Random(this.HtmConfig.RandomGenSeed);
            }
            else
            {
                rnd = new Random();
            }

            foreach (var element in this.Dict)
            {
                if (this.HtmConfig == null)
                {
                    throw new ArgumentException($"HtmConfig must be set in the message.");
                }

                int colIndx = -1;

                Column column;

                if (element.Key is string)
                {
                    if (!int.TryParse(element.Key as string, out colIndx))
                    {
                        throw new ArgumentException($"The key must be of type 'int' or string convertable to 'int");
                    }

                    column = (Column)this.Dict[element.Key];
                }
                else
                {
                    colIndx = (int)element.Key;
                    column  = (Column)this.Dict[colIndx];
                }

                // Gets RF
                var potential = HtmCompute.MapPotential(this.HtmConfig, colIndx, rnd);


                // This line initializes all synases in the potential pool of synapses.
                // It creates the pool on proximal dendrite segment of the column.
                // After initialization permancences are set to zero.
                //connectColumnToInputRF(c.HtmConfig, data.Potential, data.Column);
                column.CreatePotentialPool(this.HtmConfig, potential, -1);

                var perms = HtmCompute.InitSynapsePermanences(this.HtmConfig, potential, rnd);

                avgConnections.Add(HtmCompute.CalcAvgSpanOfConnectedSynapses(column, this.HtmConfig));

                HtmCompute.UpdatePermanencesForColumn(this.HtmConfig, perms, column, potential, true);
            }

            Debug.Write(".");

            double avgConnectedSpan = ArrayUtils.Average(avgConnections.ToArray());

            Debug.Write(".");
            return(avgConnectedSpan);
        }