public void TestActivateCorrectlyPredictiveCells() { TemporalMemory tm = new TemporalMemory(); Connections cn = new Connections(); Parameters p = GetDefaultParameters(); p.Apply(cn); TemporalMemory.Init(cn); int[] previousActiveColumns = { 0 }; int[] activeColumns = { 1 }; Cell cell4 = cn.GetCell(4); HashSet <Cell> expectedActiveCells = new HashSet <Cell> { cell4 }; //Stream.of(cell4).collect(Collectors.toSet()); DistalDendrite activeSegment = cn.CreateSegment(cell4); cn.CreateSynapse(activeSegment, cn.GetCell(0), 0.5); cn.CreateSynapse(activeSegment, cn.GetCell(1), 0.5); cn.CreateSynapse(activeSegment, cn.GetCell(2), 0.5); cn.CreateSynapse(activeSegment, cn.GetCell(3), 0.5); ComputeCycle cc = tm.Compute(cn, previousActiveColumns, true); Assert.IsTrue(cc.PredictiveCells().SetEquals(expectedActiveCells)); ComputeCycle cc2 = tm.Compute(cn, activeColumns, true); Assert.IsTrue(cc2.ActiveCells().SetEquals(expectedActiveCells)); }
public void testZeroActiveColumns() { TemporalMemory tm = new TemporalMemory(); Connections cn = new Connections(); Parameters p = GetDefaultParameters(); p.Apply(cn); TemporalMemory.Init(cn); int[] previousActiveColumns = { 0 }; Cell cell4 = cn.GetCell(4); DistalDendrite activeSegment = cn.CreateSegment(cell4); cn.CreateSynapse(activeSegment, cn.GetCell(0), 0.5); cn.CreateSynapse(activeSegment, cn.GetCell(1), 0.5); cn.CreateSynapse(activeSegment, cn.GetCell(2), 0.5); cn.CreateSynapse(activeSegment, cn.GetCell(3), 0.5); ComputeCycle cc = tm.Compute(cn, previousActiveColumns, true); Assert.IsFalse(cc.ActiveCells().Count == 0); Assert.IsFalse(cc.WinnerCells().Count == 0); Assert.IsFalse(cc.PredictiveCells().Count == 0); int[] zeroColumns = new int[0]; ComputeCycle cc2 = tm.Compute(cn, zeroColumns, true); Assert.IsTrue(cc2.ActiveCells().Count == 0); Assert.IsTrue(cc2.WinnerCells().Count == 0); Assert.IsTrue(cc2.PredictiveCells().Count == 0); }
public void testNoChangeToMatchingSegmentsInPredictedActiveColumn() { TemporalMemory tm = new TemporalMemory(); Connections cn = new Connections(); Parameters p = GetDefaultParameters(); p.Apply(cn); TemporalMemory.Init(cn); int[] previousActiveColumns = { 0 }; int[] activeColumns = { 1 }; Cell[] previousActiveCells = { cn.GetCell(0), cn.GetCell(1), cn.GetCell(2), cn.GetCell(3) }; Cell expectedActiveCell = cn.GetCell(4); HashSet <Cell> expectedActiveCells = new HashSet <Cell> { expectedActiveCell }; // Stream.of(expectedActiveCell).collect(Collectors.toCollection(HashSet < Cell >::new)); Cell otherBurstingCell = cn.GetCell(5); DistalDendrite activeSegment = cn.CreateSegment(expectedActiveCell); cn.CreateSynapse(activeSegment, previousActiveCells[0], 0.5); cn.CreateSynapse(activeSegment, previousActiveCells[1], 0.5); cn.CreateSynapse(activeSegment, previousActiveCells[2], 0.5); cn.CreateSynapse(activeSegment, previousActiveCells[3], 0.5); DistalDendrite matchingSegmentOnSameCell = cn.CreateSegment(expectedActiveCell); Synapse s1 = cn.CreateSynapse(matchingSegmentOnSameCell, previousActiveCells[0], 0.3); Synapse s2 = cn.CreateSynapse(matchingSegmentOnSameCell, previousActiveCells[1], 0.3); DistalDendrite matchingSegmentOnOtherCell = cn.CreateSegment(otherBurstingCell); Synapse s3 = cn.CreateSynapse(matchingSegmentOnOtherCell, previousActiveCells[0], 0.3); Synapse s4 = cn.CreateSynapse(matchingSegmentOnOtherCell, previousActiveCells[1], 0.3); ComputeCycle cc = tm.Compute(cn, previousActiveColumns, true); Assert.IsTrue(cc.PredictiveCells().SetEquals(expectedActiveCells)); tm.Compute(cn, activeColumns, true); Assert.AreEqual(0.3, s1.GetPermanence(), 0.01); Assert.AreEqual(0.3, s2.GetPermanence(), 0.01); Assert.AreEqual(0.3, s3.GetPermanence(), 0.01); Assert.AreEqual(0.3, s4.GetPermanence(), 0.01); }