@@ -297,36 +297,27 @@ public void compute(int[] inputVector, int[] activeArray, bool learn)
297297 // Gets overlap over every single column.
298298 var overlaps = CalculateOverlap ( this . connections , inputVector ) ;
299299
300- //var overlapsStr = Helpers.StringifyVector(overlaps);
301- //Debug.WriteLine("overlap: " + overlapsStr);
302-
303- //totalOverlap = overlapActive * weightActive + overlapPredictedActive * weightPredictedActive
304-
305300 this . connections . Overlaps = overlaps ;
306301
307302 double [ ] boostedOverlaps ;
308303
309304 //
310- // We perform boosting here and right after that, we will recalculate bossted factors for next cycle.
305+ // Here we boost calculated overlaps. This is related to Homeostatic Plasticity Mechanism.
306+ // Boosting factors are calculated in the previous cycle.
311307 if ( learn )
312308 {
313- //Debug.WriteLine("Boosted Factor: " + c.BoostFactors);
314309 boostedOverlaps = ArrayUtils . Multiply ( this . connections . BoostFactors , overlaps ) ;
315310 }
316311 else
317312 {
318313 boostedOverlaps = ArrayUtils . ToDoubleArray ( overlaps ) ;
319314 }
320315
321- //Debug.WriteLine("BO: " + Helpers.StringifyVector(boostedOverlaps));
322-
323316 this . connections . BoostedOverlaps = boostedOverlaps ;
324317
325318 int [ ] activeColumns = InhibitColumns ( this . connections , boostedOverlaps ) ;
326319
327- //var indexes = ArrayUtils.IndexWhere(this.connections.BoostFactors.OrderBy(i => i).ToArray(), x => x > 1.0);
328- //Debug.WriteLine($"Boost factors: {indexes.Length} -" + Helpers.StringifyVector(indexes));
329-
320+
330321#if REPAIR_STABILITY
331322 // REPAIR STABILITY FEATURE
332323 var similarity = MathHelpers . CalcArraySimilarity ( prevActCols , activeColumns ) ;
@@ -461,19 +452,20 @@ public void UpdateMinDutyCycles(Connections c)
461452 }
462453
463454 /// <summary>
464- /// Updates the minimum duty cycles in a global fashion. Sets the minimum duty cycles for the overlap and activation of all columns to be a percent of
465- /// the maximum in the region, specified by {@link Connections#getMinOverlapDutyCycles()} and minPctActiveDutyCycle respectively. Functionality it is
466- /// equivalent to <see cref="UpdateMinDutyCyclesLocal(Connections)"/>, but this function exploits the globalness of the computation to perform it in a
467- /// straightforward, and more efficient manner.
455+ /// Updates the minimum duty cycles for SP that uses global inhibition.
456+ /// Sets the minimum duty cycles for the overlap and activation of all columns to be a percent of
457+ /// the maximum in the region, specified by MinOverlapDutyCycles and minPctActiveDutyCycle respectively.
458+ /// Functionality it is equivalent to <see cref="UpdateMinDutyCyclesLocal(Connections)"/>,
459+ /// but this function exploits the globalness of the computation to perform it in a straightforward, and more efficient manner.
468460 /// </summary>
469461 /// <param name="c"></param>
470462 public void UpdateMinDutyCyclesGlobal ( Connections c )
471463 {
472464 // Sets the minoverlaps to the MinPctOverlapDutyCycles * Maximal Overlap in the cortical column.
473- ArrayUtils . FillArray ( c . HtmConfig . MinOverlapDutyCycles , ( double ) ( c . HtmConfig . MinPctOverlapDutyCycles * ArrayUtils . Max ( c . HtmConfig . OverlapDutyCycles ) ) ) ;
465+ ArrayUtils . InitArray ( c . HtmConfig . MinOverlapDutyCycles , ( double ) ( c . HtmConfig . MinPctOverlapDutyCycles * ArrayUtils . Max ( c . HtmConfig . OverlapDutyCycles ) ) ) ;
474466
475467 // Sets the mindutycycles to the MinPctActiveDutyCycles * Maximal Active Duty Cycles in the cortical column.
476- ArrayUtils . FillArray ( c . HtmConfig . MinActiveDutyCycles , ( double ) ( c . HtmConfig . MinPctActiveDutyCycles * ArrayUtils . Max ( c . HtmConfig . ActiveDutyCycles ) ) ) ;
468+ ArrayUtils . InitArray ( c . HtmConfig . MinActiveDutyCycles , ( double ) ( c . HtmConfig . MinPctActiveDutyCycles * ArrayUtils . Max ( c . HtmConfig . ActiveDutyCycles ) ) ) ;
477469 }
478470
479471 /// <summary>
@@ -508,8 +500,6 @@ public void UpdateMinDutyCyclesLocal(Connections c)
508500 double [ ] overlapDutyCycles = c . HtmConfig . OverlapDutyCycles ;
509501 double minPctOverlapDutyCycles = c . HtmConfig . MinPctOverlapDutyCycles ;
510502
511- //Console.WriteLine($"{inhibitionRadius: inhibitionRadius}");
512-
513503 Parallel . For ( 0 , len , ( i ) =>
514504 {
515505 int [ ] neighborhood = GetColumnNeighborhood ( c , i , inhibitionRadius ) ;
@@ -531,8 +521,6 @@ public void UpdateMinDutyCyclesLocal(Connections c)
531521 //}
532522 //sb.Append("]");
533523
534- //Console.WriteLine($"{i} - maxOverl: {maxOverlapDuty}\t - {sb.ToString()}");
535-
536524 c . HtmConfig . MinActiveDutyCycles [ i ] = maxActiveDuty * minPctActiveDutyCycles ;
537525
538526 c . HtmConfig . MinOverlapDutyCycles [ i ] = maxOverlapDuty * minPctOverlapDutyCycles ;
@@ -580,7 +568,7 @@ public void UpdateDutyCycles(Connections c, int[] overlaps, int[] activeColumns)
580568 c . HtmConfig . ActiveDutyCycles = UpdateDutyCyclesHelper ( c , c . HtmConfig . ActiveDutyCycles , activeArray , period ) ;
581569 }
582570
583- // TODO equation documentation
571+
584572 /// <summary>
585573 /// Updates a duty cycle estimate with a new value. This is a helper function that is used to update several duty cycle variables in
586574 /// the Column class, such as: overlapDutyCucle, activeDutyCycle, minPctDutyCycleBeforeInh, minPctDutyCycleAfterInh, etc. returns
@@ -595,6 +583,9 @@ public void UpdateDutyCycles(Connections c, int[] overlaps, int[] activeColumns)
595583 /// <param name="dutyCycles">An array containing one or more duty cycle values that need to be updated</param>
596584 /// <param name="newInput">A new numerical value used to update the duty cycle. Typically 1 or 0</param>
597585 /// <param name="period">The period of the duty cycle</param>
586+ /// <remarks>
587+ /// This looks a bit complicate. But, simplified, dutycycle is simple counter that counts how many times the column was
588+ /// connected to the non-zero input bit (in a case of the overlapp) or how often the column was active.</remarks>
598589 /// <returns></returns>
599590 public double [ ] UpdateDutyCyclesHelper ( Connections c , double [ ] dutyCycles , double [ ] newInput , double period )
600591 {
@@ -735,7 +726,7 @@ public virtual void AdaptSynapses(Connections c, int[] inputVector, int[] active
735726
736727 // First we initialize all permChanges to minimum decrement values,
737728 // which are used in a case of none-connections to input.
738- ArrayUtils . FillArray ( permChanges , - 1 * c . HtmConfig . SynPermInactiveDec ) ;
729+ ArrayUtils . InitArray ( permChanges , - 1 * c . HtmConfig . SynPermInactiveDec ) ;
739730
740731 // Then we update all connected permChanges to increment values for connected values.
741732 // Permanences are set in conencted input bits to default incremental value.
@@ -1342,7 +1333,9 @@ public virtual int[] InhibitColumnsLocalNew(Connections c, double[] overlaps, do
13421333
13431334 /// <summary>
13441335 /// Update the boost factors for all columns. The boost factors are used to increase the overlap of inactive columns to improve
1345- /// their chances of becoming active. and hence encourage participation of more columns in the learning process. This is a line defined as:
1336+ /// their chances of becoming active. and hence encourage participation of more columns in the learning process.
1337+ /// This is known as Homeostatc Plasticity Mechanism.
1338+ /// This is a line defined as:
13461339 /// y = mx + b
13471340 /// boost = (1-maxBoost)/minDuty * activeDutyCycle + maxBoost.
13481341 /// Intuitively this means that columns that have been active enough have a boost factor of 1, meaning their overlap is not boosted.
@@ -1367,13 +1360,13 @@ public void UpdateBoostFactors(Connections c)
13671360 double [ ] activeDutyCycles = c . HtmConfig . ActiveDutyCycles ;
13681361 double [ ] minActiveDutyCycles = c . HtmConfig . MinActiveDutyCycles ;
13691362
1370- List < int > mask = new List < int > ( ) ;
1363+ // List<int> mask = new List<int>();
13711364
1372- for ( int i = 0 ; i < minActiveDutyCycles . Length ; i ++ )
1373- {
1374- if ( minActiveDutyCycles [ i ] > 0 )
1375- mask . Add ( i ) ;
1376- }
1365+ // for (int i = 0; i < minActiveDutyCycles.Length; i++)
1366+ // {
1367+ // if (minActiveDutyCycles[i] > 0)
1368+ // mask.Add(i);
1369+ // }
13771370
13781371 double [ ] boostInterim ;
13791372
@@ -1386,26 +1379,26 @@ public void UpdateBoostFactors(Connections c)
13861379 else
13871380 {
13881381 double [ ] oneMinusMaxBoostFact = new double [ c . HtmConfig . NumColumns ] ;
1389- ArrayUtils . FillArray ( oneMinusMaxBoostFact , 1 - c . HtmConfig . MaxBoost ) ;
1382+ ArrayUtils . InitArray ( oneMinusMaxBoostFact , 1 - c . HtmConfig . MaxBoost ) ;
13901383 boostInterim = ArrayUtils . Divide ( oneMinusMaxBoostFact , minActiveDutyCycles , 0 , 0 ) ;
13911384 boostInterim = ArrayUtils . Multiply ( boostInterim , activeDutyCycles , 0 , 0 ) ;
13921385 boostInterim = ArrayUtils . AddAmount ( boostInterim , c . HtmConfig . MaxBoost ) ;
13931386 }
13941387
13951388 // Filtered indexes are indexes of columns whose activeDutyCycles is larger than calculated minActiveDutyCycles of thet column.
1396- List < int > filteredIndexes = new List < int > ( ) ;
1389+ List < int > idxOfActiveColumns = new List < int > ( ) ;
13971390
13981391 for ( int i = 0 ; i < activeDutyCycles . Length ; i ++ )
13991392 {
1400- if ( activeDutyCycles [ i ] > minActiveDutyCycles [ i ] )
1393+ if ( activeDutyCycles [ i ] >= minActiveDutyCycles [ i ] )
14011394 {
1402- filteredIndexes . Add ( i ) ;
1395+ idxOfActiveColumns . Add ( i ) ;
14031396 }
14041397 }
14051398
1406- // Already very active columns will have boost factor 1.0. That mean their synapces on the proximal segment
1399+ // Already very active columns will have boost factor 1.0. That mean their synapses on the proximal segment
14071400 // will not be stimulated.
1408- ArrayUtils . SetIndexesTo ( boostInterim , filteredIndexes . ToArray ( ) , 1.0d ) ;
1401+ ArrayUtils . SetIndexesTo ( boostInterim , idxOfActiveColumns . ToArray ( ) , 1.0d ) ;
14091402
14101403 c . BoostFactors = boostInterim ;
14111404 }
0 commit comments