@@ -297,36 +297,27 @@ public void compute(int[] inputVector, int[] activeArray, bool learn)
297
297
// Gets overlap over every single column.
298
298
var overlaps = CalculateOverlap ( this . connections , inputVector ) ;
299
299
300
- //var overlapsStr = Helpers.StringifyVector(overlaps);
301
- //Debug.WriteLine("overlap: " + overlapsStr);
302
-
303
- //totalOverlap = overlapActive * weightActive + overlapPredictedActive * weightPredictedActive
304
-
305
300
this . connections . Overlaps = overlaps ;
306
301
307
302
double [ ] boostedOverlaps ;
308
303
309
304
//
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.
311
307
if ( learn )
312
308
{
313
- //Debug.WriteLine("Boosted Factor: " + c.BoostFactors);
314
309
boostedOverlaps = ArrayUtils . Multiply ( this . connections . BoostFactors , overlaps ) ;
315
310
}
316
311
else
317
312
{
318
313
boostedOverlaps = ArrayUtils . ToDoubleArray ( overlaps ) ;
319
314
}
320
315
321
- //Debug.WriteLine("BO: " + Helpers.StringifyVector(boostedOverlaps));
322
-
323
316
this . connections . BoostedOverlaps = boostedOverlaps ;
324
317
325
318
int [ ] activeColumns = InhibitColumns ( this . connections , boostedOverlaps ) ;
326
319
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
+
330
321
#if REPAIR_STABILITY
331
322
// REPAIR STABILITY FEATURE
332
323
var similarity = MathHelpers . CalcArraySimilarity ( prevActCols , activeColumns ) ;
@@ -461,19 +452,20 @@ public void UpdateMinDutyCycles(Connections c)
461
452
}
462
453
463
454
/// <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.
468
460
/// </summary>
469
461
/// <param name="c"></param>
470
462
public void UpdateMinDutyCyclesGlobal ( Connections c )
471
463
{
472
464
// 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 ) ) ) ;
474
466
475
467
// 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 ) ) ) ;
477
469
}
478
470
479
471
/// <summary>
@@ -508,8 +500,6 @@ public void UpdateMinDutyCyclesLocal(Connections c)
508
500
double [ ] overlapDutyCycles = c . HtmConfig . OverlapDutyCycles ;
509
501
double minPctOverlapDutyCycles = c . HtmConfig . MinPctOverlapDutyCycles ;
510
502
511
- //Console.WriteLine($"{inhibitionRadius: inhibitionRadius}");
512
-
513
503
Parallel . For ( 0 , len , ( i ) =>
514
504
{
515
505
int [ ] neighborhood = GetColumnNeighborhood ( c , i , inhibitionRadius ) ;
@@ -531,8 +521,6 @@ public void UpdateMinDutyCyclesLocal(Connections c)
531
521
//}
532
522
//sb.Append("]");
533
523
534
- //Console.WriteLine($"{i} - maxOverl: {maxOverlapDuty}\t - {sb.ToString()}");
535
-
536
524
c . HtmConfig . MinActiveDutyCycles [ i ] = maxActiveDuty * minPctActiveDutyCycles ;
537
525
538
526
c . HtmConfig . MinOverlapDutyCycles [ i ] = maxOverlapDuty * minPctOverlapDutyCycles ;
@@ -580,7 +568,7 @@ public void UpdateDutyCycles(Connections c, int[] overlaps, int[] activeColumns)
580
568
c . HtmConfig . ActiveDutyCycles = UpdateDutyCyclesHelper ( c , c . HtmConfig . ActiveDutyCycles , activeArray , period ) ;
581
569
}
582
570
583
- // TODO equation documentation
571
+
584
572
/// <summary>
585
573
/// Updates a duty cycle estimate with a new value. This is a helper function that is used to update several duty cycle variables in
586
574
/// the Column class, such as: overlapDutyCucle, activeDutyCycle, minPctDutyCycleBeforeInh, minPctDutyCycleAfterInh, etc. returns
@@ -595,6 +583,9 @@ public void UpdateDutyCycles(Connections c, int[] overlaps, int[] activeColumns)
595
583
/// <param name="dutyCycles">An array containing one or more duty cycle values that need to be updated</param>
596
584
/// <param name="newInput">A new numerical value used to update the duty cycle. Typically 1 or 0</param>
597
585
/// <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>
598
589
/// <returns></returns>
599
590
public double [ ] UpdateDutyCyclesHelper ( Connections c , double [ ] dutyCycles , double [ ] newInput , double period )
600
591
{
@@ -735,7 +726,7 @@ public virtual void AdaptSynapses(Connections c, int[] inputVector, int[] active
735
726
736
727
// First we initialize all permChanges to minimum decrement values,
737
728
// 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 ) ;
739
730
740
731
// Then we update all connected permChanges to increment values for connected values.
741
732
// Permanences are set in conencted input bits to default incremental value.
@@ -1342,7 +1333,9 @@ public virtual int[] InhibitColumnsLocalNew(Connections c, double[] overlaps, do
1342
1333
1343
1334
/// <summary>
1344
1335
/// 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:
1346
1339
/// y = mx + b
1347
1340
/// boost = (1-maxBoost)/minDuty * activeDutyCycle + maxBoost.
1348
1341
/// 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)
1367
1360
double [ ] activeDutyCycles = c . HtmConfig . ActiveDutyCycles ;
1368
1361
double [ ] minActiveDutyCycles = c . HtmConfig . MinActiveDutyCycles ;
1369
1362
1370
- List < int > mask = new List < int > ( ) ;
1363
+ // List<int> mask = new List<int>();
1371
1364
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
+ // }
1377
1370
1378
1371
double [ ] boostInterim ;
1379
1372
@@ -1386,26 +1379,26 @@ public void UpdateBoostFactors(Connections c)
1386
1379
else
1387
1380
{
1388
1381
double [ ] oneMinusMaxBoostFact = new double [ c . HtmConfig . NumColumns ] ;
1389
- ArrayUtils . FillArray ( oneMinusMaxBoostFact , 1 - c . HtmConfig . MaxBoost ) ;
1382
+ ArrayUtils . InitArray ( oneMinusMaxBoostFact , 1 - c . HtmConfig . MaxBoost ) ;
1390
1383
boostInterim = ArrayUtils . Divide ( oneMinusMaxBoostFact , minActiveDutyCycles , 0 , 0 ) ;
1391
1384
boostInterim = ArrayUtils . Multiply ( boostInterim , activeDutyCycles , 0 , 0 ) ;
1392
1385
boostInterim = ArrayUtils . AddAmount ( boostInterim , c . HtmConfig . MaxBoost ) ;
1393
1386
}
1394
1387
1395
1388
// 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 > ( ) ;
1397
1390
1398
1391
for ( int i = 0 ; i < activeDutyCycles . Length ; i ++ )
1399
1392
{
1400
- if ( activeDutyCycles [ i ] > minActiveDutyCycles [ i ] )
1393
+ if ( activeDutyCycles [ i ] >= minActiveDutyCycles [ i ] )
1401
1394
{
1402
- filteredIndexes . Add ( i ) ;
1395
+ idxOfActiveColumns . Add ( i ) ;
1403
1396
}
1404
1397
}
1405
1398
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
1407
1400
// will not be stimulated.
1408
- ArrayUtils . SetIndexesTo ( boostInterim , filteredIndexes . ToArray ( ) , 1.0d ) ;
1401
+ ArrayUtils . SetIndexesTo ( boostInterim , idxOfActiveColumns . ToArray ( ) , 1.0d ) ;
1409
1402
1410
1403
c . BoostFactors = boostInterim ;
1411
1404
}
0 commit comments