Skip to content

Commit ce245dc

Browse files
author
Damir Dobric
committed
Merge branch 'master' of https://github.com/ddobric/neocortexapi
2 parents 450e1dd + 334a084 commit ce245dc

File tree

8 files changed

+85
-23
lines changed

8 files changed

+85
-23
lines changed

NeoCortexApi/Documentation/experiments.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ The ability to recognize and predict temporal sequences of sensory inputs is vit
2323

2424
[Download student paper here](./Experiments/ML-19-20_20-5.4_CellsPerColumnExperiment_Paper.pdf)
2525

26-
[Check out implementation here](../../NeoCortexApi/UnitTestsProject/CortexNetworkTests/CellsPerColumnExperimentTest.cs)
26+
[Check out implementation here](../../NeoCortexApi/NeoCortexApi.Experiments/CortexNetworkTests/CellsPerColumnExperimentTest.cs)
2727

2828
#### **HTM Sparsity**
2929

3030
It is necessary for survival in natural environment to be able to identify and predict temporal sequence of sensory input. Based on numerous common properties of the cortical neurons, the theoretical framework for sequence learning in the neo cortex recently proposed hierarchical temporal memory (HTM). In this paper, we analyze the sequence learning behavior of spatial pooler and temporal memory layer in dependence on HTM Sparsity. We found the ideal value of HTM Sparsity that will have optimal learning for the given input sequence. We also showed the effect of changing Width and Input Bits on learning such that the value of HTM Sparsity remains constant. We devised a relation between HTM Sparsity and max for optimal learning of the given sequence.
3131

3232
[Download student paper here](./Experiments/ML-19-20_20-5.4_HtmSparsityExperiments_Paper.pdf)
3333

34-
[Check out implementation here](../../NeoCortexApi/UnitTestsProject/CortexNetworkTests/HtmSparsityTest.cs)
34+
[Check out implementation here](../../NeoCortexApi/NeoCortexApi.Experiments/CortexNetworkTests/HtmSparsityTest.cs)
3535

3636
#### **Parameter Change Experiment**
3737

3838
Hierarchical Temporal Memory (HTM) is based on the supposition that the world has a structure and is therefore predictable. The development of HTM for Artificial Neural Networks has led to an advancement in the field of artificial intelligence and leading the computing intelligence to a new age. In this paper, we studied various learning parameters like Width(W), Input Bits(N), Max,Min values and the number of columns, that majorly contribute to optimize the sequence learning behavior of spatial pooler and temporal memory layer. We also performed experiment to obtain stability of Spatial Pooler output by tuning the boost and duty cycles. We evaluated each of these parameters based on the theoretical and practical framework and summarized the results in graphical diagrams.
3939

4040
[Download student paper here](./Experiments/ML-19-20_20-5.4_ParameterChangeExperiment_Paper.pdf)
4141

42-
[Check out implementation here](../../NeoCortexApi/UnitTestsProject/CortexNetworkTests/InputBitsExperimentTest.cs)
42+
[Check out implementation here](../../NeoCortexApi/NeoCortexApi.Experiments/CortexNetworkTests/InputBitsExperimentTest.cs)
4343

4444
## Performance Spatial Pooler between Global and Local Inhibition
4545

@@ -59,7 +59,7 @@ Each region in the cortex receives input through millions of axons from sensory
5959

6060
[Download student paper here](./Experiments/ML-19-20_20-5.7_PerformanceSpatialPooler-between-Global-and-Local-Inhibition.pdf)
6161

62-
[Check out implementation here](../../NeoCortexApi/UnitTestsProject/SpatialPoolerInhibitionExperimentalTests.cs)
62+
[Check out implementation here](../../NeoCortexApi/NeoCortexApi.Experiments/SpatialPoolerInhibitionExperimentalTests.cs)
6363

6464
## Investigation of Hierarchical Temporal Memory Spatial Pooler's Noise Robustness against Gaussian noise
6565

@@ -79,7 +79,7 @@ The Thousand Brains Theory of Intelligence is a new and rising approach to under
7979

8080
[Download student paper here](./Experiments/ML-19-20_20-5.12_SpatialPooler_NoiseRobustness.pdf)
8181

82-
[Check out implementation here](../../NeoCortexApi/UnitTestsProject/CortexNetworkTests\GaussianNoiseExperiment.cs)
82+
[Check out implementation here](../../NeoCortexApi/NeoCortexApi.Experiments/CortexNetworkTests/GaussianNoiseExperiment.cs)
8383

8484
## Validate Memorizing capabilities of SpatialPooler
8585

@@ -100,7 +100,7 @@ The main objective of the project is to describe memorizing capabilites as the a
100100

101101
[Download student paper here](./Experiments/ML-19-20_20-5.10_ValdatingMemorizingCapabilitesOfSpatialPooler.pdf)
102102

103-
[Check out implementation here](../../NeoCortexApi/UnitTestsProject/SpatialPoolerMemorizingExperiment84.cs)
103+
[Check out implementation here](../../NeoCortexApi/NeoCortexApi.Experiments/SpatialPoolerMemorizingExperiment84.cs)
104104

105105
## ML19/20-5.2. Improving of implementation of the Scalar encoder in HTM
106106

@@ -137,7 +137,7 @@ The image classification is a classical problem of image processing; machine lea
137137

138138
[Download student paper here](./Experiments/ML-19-20_20-5.11_SchemaImageClassification.pdf)
139139

140-
[Check out implementation here](../../NeoCortexApi/UnitTestsProject/SchemaImageClassificationExperiment.cs)
140+
[Check out implementation here](../../NeoCortexApi/NeoCortexApi.Experiments/SchemaImageClassificationExperiment.cs)
141141

142142
## Sequence Learning - Music Notes Experiment
143143

@@ -152,7 +152,7 @@ To demonstrate learning of sequences, I have originally developed an experiment
152152
Every music note is represented as a scalar value, which appear in the sequence of notes. For example, notes C, D, E, F, G and H can be associated with the scalar values: C-0, D-1, E-2, F-3, G-4, H-5. By following that rule notes of some has been taken. In the very first experiment the song _twinkle, twinkle little star_ was used in the experiment: [here] (https://www.bethsnotesplus.com/2013/08/twinkle-twinkle-little-star.html).
153153
Over time, the experiment has grown, but we have kept the original name '_Music Notes Experiment_'. In this experiment various outputs are generated, which trace the state of active columns and active cells during the learning process. Today, we use this experiment to learn how HTM learns sequences.
154154

155-
[Check out implementation here](../../NeoCortexApi/UnitTestsProject/SequenceLearningExperiments/MuscNotesExperiment.cs)
155+
[Check out implementation here](../../NeoCortexApi/NeoCortexApi.Experiments/SequenceLearningExperiments/MuscNotesExperiment.cs)
156156

157157
## On the Relationship Between Input Sparsity and Noise Robustness in SP (Paper)
158158

@@ -234,7 +234,6 @@ Issue 70
234234

235235
HTM Feedforward network is a multilayer based artificial neural orchestrate which is a biologically propelled show of a single cortical column of the NeoCortex, is a set of six layers of the portion of mammalian cerebral cortex wherever the higher cognitive functioning is acknowledged to originate from. Previous findings in neurosciences show that there is the presence of two sets of Feedforward network in the single cortical column of the human brain among them layer L4-L2 Feedforward network plays the active role to learn new things from the environment. Within the L4-L2 Feedforward network arrange, the lower layer L4 takes the sensory data directly as input from the environment and passes the processed data to layer L2 to perform cognitive predicting & learning functions in the brain. In this paper, the idea to implement the layer L4-L2 based HTM Feed Forward network is demonstrated utilizing the most recent adaptation of NeocortexApi package, which is an open-source solution of the Hierarchical Temporal Memory Cortical Learning Algorithm. Besides, it is also examined how the implemented L4-L2 Feedforward network arrangement behaves at upper layer L2 in case of sequence learning and predicting using HTM Classifier. Aside from that, NuMenta's discoveries and guidelines are investigated as well. The results show that the proposed L4-L2 based HTM Feedforward network with NeocortexApi can learn and predict sequential data patterns with precision in the upper layer region.
236236

237+
[Download student paper here](./Experiments/ML-20-21_20-5.2_HTM%20FeedForward_Network.pdf)
237238

238-
[Download student paper here](./Experiments/ML-20-21_20-5.2_HTM FeedForward_Network.pdf)
239-
240-
[Check out implementation here](../../NeoCortexApi/NeoCortexApi.Experiments/FeedForwardExperiment_L4L2.cs)
239+
[Check out implementation here](../../NeoCortexApi/NeoCortexApi.Experiments/FeedForwardExperiment_L4L2.cs)

NeoCortexApi/NeoCortexApi.Experiments/SequenceLearningExperiments/MuscNotesExperiment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
using System.Threading.Tasks;
2121
using NeoCortexApi.Classifiers;
2222

23-
namespace NeoCortexApi.Experiments.SequenceLearningExperiments
23+
namespace NeoCortexApi.Experiments
2424
{
2525
[TestClass]
2626
public class MuscNotesExperiment

NeoCortexApi/NeoCortexApi.Experiments/SpatialSimilarityExperiment.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public void SpatialSimilarityExperimentTest()
4848
DutyCyclePeriod = 100,
4949
MinPctOverlapDutyCycles = minOctOverlapCycles,
5050
StimulusThreshold = 5,
51-
GlobalInhibition = true,
51+
GlobalInhibition = false,
5252
NumActiveColumnsPerInhArea = 0.02 * numColumns,
5353
PotentialRadius = (int)(0.15 * inputBits),
54-
LocalAreaDensity = -1,//0.5,
54+
LocalAreaDensity = 0.5,
5555
ActivationThreshold = 10,
5656
MaxSynapsesPerSegment = (int)(0.01 * numColumns),
5757
Random = new ThreadSafeRandom(42)

NeoCortexApi/NeoCortexApi/SpatialPooler.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,9 @@ public virtual int[] InhibitColumnsLocalOriginal(Connections mem, double[] overl
947947
int numActive = (int)(0.5 + density * neighborhood.Length);
948948

949949
//
950-
// Column is added as a winner one if the number of higher overlapped columns than the actual column
950+
// numActive is the number of maximal active columns in the neighborhood.
951+
// numHigherOverlap is the number of columns in the neighborhood that have higher overlap than the referencing column.
952+
// Column is added as a winner one if the number of higher overlapped columns
951953
// is less than number of active columns defined by density and radius.
952954
if (numHigherOverlap < numActive)
953955
{

NeoCortexApi/NeoCortexApi/TemporalMemory.cs

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ public void Init(Connections conn)
9090
/// <returns></returns>
9191
/// <remarks>Note: PredictiveCells are not calculated here. They are calculated on demand from active segments.</remarks>
9292
public ComputeCycle Compute(int[] activeColumns, bool learn)
93+
{
94+
return Compute(activeColumns, learn, null, null);
95+
}
96+
97+
98+
/// <summary>
99+
/// Performs the whole calculation of Temporal memory algorithm.
100+
/// Calculation takes two parts:
101+
/// <list type="number">
102+
/// <item>Calculation of the cells, which become active in the current cycle.</item>
103+
/// <item>Calculation of dendrite segments which becom active in the current cycle.</item>
104+
/// </list>
105+
/// </summary>
106+
/// <param name="activeColumns"></param>
107+
/// <param name="learn"></param>
108+
/// <param name="externalPredictiveInputsActive">Experimental.</param>
109+
/// <param name="externalPredictiveInputsWinners">Experimental.</param>
110+
/// <returns></returns>
111+
/// <remarks>Note: PredictiveCells are not calculated here. They are calculated on demand from active segments.</remarks>
112+
public ComputeCycle Compute(int[] activeColumns, bool learn, int[] externalPredictiveInputsActive = null, int[] externalPredictiveInputsWinners = null)
93113
{
94114
Stopwatch sw = new Stopwatch();
95115
sw.Start();
@@ -101,7 +121,7 @@ public ComputeCycle Compute(int[] activeColumns, bool learn)
101121

102122
sw.Restart();
103123

104-
ActivateDendrites(this.connections, cycle, learn);
124+
ActivateDendrites(this.connections, cycle, learn, externalPredictiveInputsActive, externalPredictiveInputsWinners);
105125

106126
sw.Stop();
107127

@@ -257,8 +277,15 @@ protected virtual ComputeCycle ActivateCells(Connections conn, int[] activeColum
257277
/// <param name="conn">the Connectivity</param>
258278
/// <param name="cycle">Stores current compute cycle results</param>
259279
/// <param name="learn">If true, segment activations will be recorded. This information is used during segment cleanup.</param>
260-
protected void ActivateDendrites(Connections conn, ComputeCycle cycle, bool learn)
280+
/// <seealso cref="">https://github.com/htm-community/htm.core/blob/master/src/htm/algorithms/TemporalMemory.cpp</seealso>
281+
protected void ActivateDendrites(Connections conn, ComputeCycle cycle, bool learn, int[] externalPredictiveInputsActive = null, int[] externalPredictiveInputsWinners = null)
261282
{
283+
//if (externalPredictiveInputsActive != null)
284+
// cycle.ActiveCells.AddRange(externalPredictiveInputsActive);
285+
286+
//if (externalPredictiveInputsWinners != null)
287+
// cycle.WinnerCells.AddRange(externalPredictiveInputsActive);
288+
262289
SegmentActivity activity = conn.ComputeActivity(cycle.ActiveCells, conn.HtmConfig.ConnectedPermanence);
263290

264291
var activeSegments = new List<DistalDendrite>();
@@ -355,8 +382,8 @@ public void Reset(Connections connections)
355382

356383

357384
/// <summary>
358-
/// TM acitivates segments on the column in the previous cycle. This method locates such segments and
359-
/// adapts them.
385+
/// TM activated segments on the column in the previous cycle. This method locates such segments and
386+
/// adapts them and return owner cells of active segments.
360387
/// </summary>
361388
/// <param name="conn"></param>
362389
/// <param name="columnActiveSegments">Active segments as calculated (activated) in the previous step.</param>
@@ -371,10 +398,10 @@ protected List<Cell> ActivatePredictedColumn(Connections conn, List<DistalDendri
371398
List<DistalDendrite> matchingSegments, ICollection<Cell> prevActiveCells, ICollection<Cell> prevWinnerCells,
372399
double permanenceIncrement, double permanenceDecrement, bool learn, IList<Synapse> activeSynapses)
373400
{
401+
// List of cells that owns active segments. These cells will be activated in this cycle.
402+
// In previous cycle they are depolarized.
374403
List<Cell> cellsOwnersOfActiveSegments = new List<Cell>();
375-
//Cell previousCell = null;
376-
//Cell segmOwnerCell;
377-
404+
378405
foreach (DistalDendrite segment in columnActiveSegments)
379406
{
380407
if (!cellsOwnersOfActiveSegments.Contains(segment.ParentCell))
@@ -413,6 +440,8 @@ protected List<Cell> ActivatePredictedColumn(Connections conn, List<DistalDendri
413440
{
414441
AdaptSegment(conn, segment, prevActiveCells, permanenceIncrement, permanenceDecrement);
415442

443+
//
444+
// Even if the segment is active, new synapses can be added that connect previously active cells with the segment.
416445
int numActive = conn.LastActivity.PotentialSynapses[segment.SegmentIndex];
417446
int nGrowDesired = conn.HtmConfig.MaxNewSynapseCount - numActive;
418447

NeoCortexApi/NeoCortexEntities/Entities/Connections.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ public SegmentActivity ComputeActivity(ICollection<Cell> activeCellsInCurrentCyc
838838
// This cell is the active in the current cycle.
839839
// We step through all receptor synapses and check the permanence value of related synapses.
840840
// Receptor synapses are synapses whose source cell (pre-synaptic cell) is the given cell.
841-
// Receptor synapses connect their axons to distal dendrite segments of other cells.
841+
// Receptor synapses connect the cell's axons to distal dendrite segments of other cells.
842842
// The permanence value of this connection indicates the the cell owner of connected distal dendrite is expected
843843
// to be activated in the next cycle.
844844
// The segment owner cell in other column pointed by synapse sourced by this 'cell' is depolirized (in predicting state).

Python/ColumnActivityDiagram/draw_figure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import os
1212

13+
# py -m ensurepip
1314
# pip install plotly
1415
# Without pip: py -m pip install plotly
1516
# py draw_figure.py -fn "C:\dev\devops-daenet\NeoCortexApi\NeoCortexApi\UnitTestsProject\bin\Debug\netcoreapp3.1\exp.csv" -gn Digit -mc 1000 -ht 15 -yt "column indicies" -xt cycle -st "Predicted/Expected/Predictive Cells" -fign CortialColumn

0 commit comments

Comments
 (0)