Пример #1
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>
        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}");
        }
Пример #2
0
        void adaptSynapses(AdaptSynapsesMsg msg)
        {
            ParallelOptions opts = new ParallelOptions();

            opts.MaxDegreeOfParallelism = msg.ColumnKeys.Count;

            Parallel.ForEach(msg.ColumnKeys, opts, (colPair) =>
            {
                Column activeColumn = (Column)this.dict[colPair.Key];
                //Pool pool = c.getPotentialPools().get(activeColumns[i]);
                Pool pool     = activeColumn.ProximalDendrite.RFPool;
                double[] perm = pool.getDensePermanences(this.config.NumInputs);
                int[] indexes = pool.getSparsePotential();
                ArrayUtils.raiseValuesBy(msg.PermanenceChanges, perm);

                HtmCompute.UpdatePermanencesForColumn(this.config, perm, activeColumn, indexes, true);
            });

            // We send this to ensure reliable messaging. No other result is required here.
            Sender.Tell(0, Self);
        }
Пример #3
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);
        }