public void testNoChangeToNonSelectedMatchingSegmentsInBurstingColumn() { TemporalMemory tm = new TemporalMemory(); Connections cn = new Connections(); Parameters p = GetDefaultParameters(null, Parameters.KEY.PERMANENCE_DECREMENT, 0.08); 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[] burstingCells = { cn.GetCell(4), cn.GetCell(5) }; DistalDendrite selectedMatchingSegment = cn.CreateSegment(burstingCells[0]); cn.CreateSynapse(selectedMatchingSegment, previousActiveCells[0], 0.3); cn.CreateSynapse(selectedMatchingSegment, previousActiveCells[1], 0.3); cn.CreateSynapse(selectedMatchingSegment, previousActiveCells[2], 0.3); cn.CreateSynapse(selectedMatchingSegment, cn.GetCell(81), 0.3); DistalDendrite otherMatchingSegment = cn.CreateSegment(burstingCells[1]); Synapse as1 = cn.CreateSynapse(otherMatchingSegment, previousActiveCells[0], 0.3); Synapse as2 = cn.CreateSynapse(otherMatchingSegment, previousActiveCells[1], 0.3); Synapse is1 = cn.CreateSynapse(otherMatchingSegment, cn.GetCell(81), 0.3); tm.Compute(cn, previousActiveColumns, true); tm.Compute(cn, activeColumns, true); Assert.AreEqual(0.3, as1.GetPermanence(), 0.01); Assert.AreEqual(0.3, as2.GetPermanence(), 0.01); Assert.AreEqual(0.3, is1.GetPermanence(), 0.01); }
public void testReinforcedCorrectlyActiveSegments() { TemporalMemory tm = new TemporalMemory(); Connections cn = new Connections(); Parameters p = GetDefaultParameters(null, Parameters.KEY.INITIAL_PERMANENCE, 0.2); p = GetDefaultParameters(p, Parameters.KEY.MAX_NEW_SYNAPSE_COUNT, 4); p = GetDefaultParameters(p, Parameters.KEY.PERMANENCE_DECREMENT, 0.08); p = GetDefaultParameters(p, Parameters.KEY.PREDICTED_SEGMENT_DECREMENT, 0.02); 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 activeCell = cn.GetCell(5); DistalDendrite activeSegment = cn.CreateSegment(activeCell); Synapse as1 = cn.CreateSynapse(activeSegment, previousActiveCells[0], 0.5); Synapse as2 = cn.CreateSynapse(activeSegment, previousActiveCells[1], 0.5); Synapse as3 = cn.CreateSynapse(activeSegment, previousActiveCells[2], 0.5); Synapse is1 = cn.CreateSynapse(activeSegment, cn.GetCell(81), 0.5); tm.Compute(cn, previousActiveColumns, true); tm.Compute(cn, activeColumns, true); Assert.AreEqual(0.6, as1.GetPermanence(), 0.1); Assert.AreEqual(0.6, as2.GetPermanence(), 0.1); Assert.AreEqual(0.6, as3.GetPermanence(), 0.1); Assert.AreEqual(0.42, is1.GetPermanence(), 0.001); }
public void testAdaptSegmentToMax() { TemporalMemory tm = new TemporalMemory(); Connections cn = new Connections(); Parameters p = Parameters.GetAllDefaultParameters(); p.Apply(cn); TemporalMemory.Init(cn); DistalDendrite dd = cn.CreateSegment(cn.GetCell(0)); Synapse s1 = cn.CreateSynapse(dd, cn.GetCell(23), 0.9); tm.AdaptSegment(cn, dd, cn.GetCellSet(23), cn.GetPermanenceIncrement(), cn.GetPermanenceDecrement()); Assert.AreEqual(1.0, s1.GetPermanence(), 0.1); // Now permanence should be at max tm.AdaptSegment(cn, dd, cn.GetCellSet(23), cn.GetPermanenceIncrement(), cn.GetPermanenceDecrement()); Assert.AreEqual(1.0, s1.GetPermanence(), 0.1); }
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); }
public void testAdaptSegment() { TemporalMemory tm = new TemporalMemory(); Connections cn = new Connections(); Parameters p = Parameters.GetAllDefaultParameters(); p.Apply(cn); TemporalMemory.Init(cn); DistalDendrite dd = cn.CreateSegment(cn.GetCell(0)); Synapse s1 = cn.CreateSynapse(dd, cn.GetCell(23), 0.6); Synapse s2 = cn.CreateSynapse(dd, cn.GetCell(37), 0.4); Synapse s3 = cn.CreateSynapse(dd, cn.GetCell(477), 0.9); tm.AdaptSegment(cn, dd, cn.GetCellSet(23, 37), cn.GetPermanenceIncrement(), cn.GetPermanenceDecrement()); Assert.AreEqual(0.7, s1.GetPermanence(), 0.01); Assert.AreEqual(0.5, s2.GetPermanence(), 0.01); Assert.AreEqual(0.8, s3.GetPermanence(), 0.01); }
public void testPunishMatchingSegmentsInInactiveColumns() { TemporalMemory tm = new TemporalMemory(); Connections cn = new Connections(); Parameters p = GetDefaultParameters(null, Parameters.KEY.MAX_NEW_SYNAPSE_COUNT, 4); p = GetDefaultParameters(p, Parameters.KEY.INITIAL_PERMANENCE, 0.2); p = GetDefaultParameters(p, Parameters.KEY.PREDICTED_SEGMENT_DECREMENT, 0.02); p.Apply(cn); TemporalMemory.Init(cn); int[] prevActiveColumns = { 0 }; Cell[] prevActiveCells = { cn.GetCell(0), cn.GetCell(1), cn.GetCell(2), cn.GetCell(3) }; int[] activeColumns = { 1 }; Cell previousInactiveCell = cn.GetCell(81); DistalDendrite activeSegment = cn.CreateSegment(cn.GetCell(42)); Synapse as1 = cn.CreateSynapse(activeSegment, prevActiveCells[0], .5); Synapse as2 = cn.CreateSynapse(activeSegment, prevActiveCells[1], .5); Synapse as3 = cn.CreateSynapse(activeSegment, prevActiveCells[2], .5); Synapse is1 = cn.CreateSynapse(activeSegment, previousInactiveCell, .5); DistalDendrite matchingSegment = cn.CreateSegment(cn.GetCell(43)); Synapse as4 = cn.CreateSynapse(matchingSegment, prevActiveCells[0], .5); Synapse as5 = cn.CreateSynapse(matchingSegment, prevActiveCells[1], .5); Synapse is2 = cn.CreateSynapse(matchingSegment, previousInactiveCell, .5); tm.Compute(cn, prevActiveColumns, true); tm.Compute(cn, activeColumns, true); Assert.AreEqual(0.48, as1.GetPermanence(), 0.01); Assert.AreEqual(0.48, as2.GetPermanence(), 0.01); Assert.AreEqual(0.48, as3.GetPermanence(), 0.01); Assert.AreEqual(0.48, as4.GetPermanence(), 0.01); Assert.AreEqual(0.48, as5.GetPermanence(), 0.01); Assert.AreEqual(0.50, is1.GetPermanence(), 0.01); Assert.AreEqual(0.50, is2.GetPermanence(), 0.01); }