Java Code Examples for org.numenta.nupic.Parameters#getTemporalDefaultParameters()
The following examples show how to use
org.numenta.nupic.Parameters#getTemporalDefaultParameters() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MonitoredTemporalMemoryTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
private Parameters getDefaultParameters() { Parameters retVal = Parameters.getTemporalDefaultParameters(); retVal.set(KEY.COLUMN_DIMENSIONS, new int[] { 2 }); retVal.set(KEY.CELLS_PER_COLUMN, 4); retVal.set(KEY.ACTIVATION_THRESHOLD, 3); retVal.set(KEY.INITIAL_PERMANENCE, 0.21); retVal.set(KEY.CONNECTED_PERMANENCE, 0.5); retVal.set(KEY.MIN_THRESHOLD, 2); retVal.set(KEY.MAX_NEW_SYNAPSE_COUNT, 3); retVal.set(KEY.PERMANENCE_INCREMENT, 0.10); retVal.set(KEY.PERMANENCE_DECREMENT, 0.10); retVal.set(KEY.PREDICTED_SEGMENT_DECREMENT, 0.0); retVal.set(KEY.RANDOM, new UniversalRandom(42)); retVal.set(KEY.SEED, 42); return retVal; }
Example 2
Source File: TemporalMemoryTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
private Parameters getDefaultParameters() { Parameters retVal = Parameters.getTemporalDefaultParameters(); retVal.set(KEY.COLUMN_DIMENSIONS, new int[] { 32 }); retVal.set(KEY.CELLS_PER_COLUMN, 4); retVal.set(KEY.ACTIVATION_THRESHOLD, 3); retVal.set(KEY.INITIAL_PERMANENCE, 0.21); retVal.set(KEY.CONNECTED_PERMANENCE, 0.5); retVal.set(KEY.MIN_THRESHOLD, 2); retVal.set(KEY.MAX_NEW_SYNAPSE_COUNT, 3); retVal.set(KEY.PERMANENCE_INCREMENT, 0.10); retVal.set(KEY.PERMANENCE_DECREMENT, 0.10); retVal.set(KEY.PREDICTED_SEGMENT_DECREMENT, 0.0); retVal.set(KEY.RANDOM, new UniversalRandom(42)); retVal.set(KEY.SEED, 42); return retVal; }
Example 3
Source File: DistalDendriteTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
private Parameters getDefaultParameters() { Parameters retVal = Parameters.getTemporalDefaultParameters(); retVal.set(KEY.COLUMN_DIMENSIONS, new int[] { 32 }); retVal.set(KEY.CELLS_PER_COLUMN, 4); retVal.set(KEY.ACTIVATION_THRESHOLD, 3); retVal.set(KEY.INITIAL_PERMANENCE, 0.21); retVal.set(KEY.CONNECTED_PERMANENCE, 0.5); retVal.set(KEY.MIN_THRESHOLD, 2); retVal.set(KEY.MAX_NEW_SYNAPSE_COUNT, 3); retVal.set(KEY.PERMANENCE_INCREMENT, 0.10); retVal.set(KEY.PERMANENCE_DECREMENT, 0.10); retVal.set(KEY.PREDICTED_SEGMENT_DECREMENT, 0.0); retVal.set(KEY.RANDOM, new UniversalRandom(42)); retVal.set(KEY.SEED, 42); return retVal; }
Example 4
Source File: ConnectionsTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
/** * Hit the maxSynapsesPerSegment threshold multiple times. Make sure it * works more than once. */ @Test public void testReachSegmentLimitMultipleTimes() { Parameters p = Parameters.getTemporalDefaultParameters(); p.set(KEY.COLUMN_DIMENSIONS, new int[] { 32 }); p.set(KEY.CELLS_PER_COLUMN, 32); p.set(KEY.MAX_SEGMENTS_PER_CELL, 2); p.set(KEY.MAX_SYNAPSES_PER_SEGMENT, 2); Connections connections = new Connections(); p.apply(connections); TemporalMemory.init(connections); DistalDendrite segment = connections.createSegment(connections.getCell(10)); connections.createSynapse(segment, connections.getCell(201), .85); assertEquals(1, connections.numSynapses()); connections.createSynapse(segment, connections.getCell(202), .9); assertEquals(2, connections.numSynapses()); connections.createSynapse(segment, connections.getCell(203), .8); assertEquals(2, connections.numSynapses()); connections.createSynapse(segment, connections.getCell(204), .8); assertEquals(2, connections.numSynapses()); }
Example 5
Source File: ComputeCycleTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
private Parameters getDefaultParameters() { Parameters retVal = Parameters.getTemporalDefaultParameters(); retVal.set(KEY.COLUMN_DIMENSIONS, new int[] { 32 }); retVal.set(KEY.CELLS_PER_COLUMN, 4); retVal.set(KEY.ACTIVATION_THRESHOLD, 3); retVal.set(KEY.INITIAL_PERMANENCE, 0.21); retVal.set(KEY.CONNECTED_PERMANENCE, 0.5); retVal.set(KEY.MIN_THRESHOLD, 2); retVal.set(KEY.MAX_NEW_SYNAPSE_COUNT, 3); retVal.set(KEY.PERMANENCE_INCREMENT, 0.10); retVal.set(KEY.PERMANENCE_DECREMENT, 0.10); retVal.set(KEY.PREDICTED_SEGMENT_DECREMENT, 0.0); retVal.set(KEY.RANDOM, new UniversalRandom(42)); retVal.set(KEY.SEED, 42); return retVal; }
Example 6
Source File: ConnectionsTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
/** * Destroy a segment that has a destroyed synapse and a non-destroyed * synapse. Make sure nothing gets double-destroyed. */ @Test public void testDestroySegmentWithDestroyedSynapses() { Parameters p = Parameters.getTemporalDefaultParameters(); p.set(KEY.COLUMN_DIMENSIONS, new int[] { 32 }); p.set(KEY.CELLS_PER_COLUMN, 32); Connections connections = new Connections(); p.apply(connections); TemporalMemory.init(connections); DistalDendrite segment1 = connections.createSegment(connections.getCell(11)); DistalDendrite segment2 = connections.createSegment(connections.getCell(12)); connections.createSynapse(segment1, connections.getCell(101), .85); Synapse synapse2a = connections.createSynapse(segment2, connections.getCell(201), .85); connections.createSynapse(segment2, connections.getCell(202), .85); assertEquals(3, connections.numSynapses()); connections.destroySynapse(synapse2a); assertEquals(2, connections.numSegments()); assertEquals(2, connections.numSynapses()); connections.destroySegment(segment2); assertEquals(1, connections.numSegments()); assertEquals(1, connections.numSynapses()); }
Example 7
Source File: ConnectionsTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
/** * Destroy some synapses then verify that the maxSynapsesPerSegment is * still correctly applied. */ @Test public void testDestroySynapsesThenReachLimit() { Parameters p = Parameters.getTemporalDefaultParameters(); p.set(KEY.COLUMN_DIMENSIONS, new int[] { 32 }); p.set(KEY.CELLS_PER_COLUMN, 32); p.set(KEY.MAX_SEGMENTS_PER_CELL, 2); p.set(KEY.MAX_SYNAPSES_PER_SEGMENT, 2); Connections connections = new Connections(); p.apply(connections); TemporalMemory.init(connections); DistalDendrite segment = connections.createSegment(connections.getCell(10)); Synapse synapse1 = connections.createSynapse(segment, connections.getCell(201), .85); Synapse synapse2 = connections.createSynapse(segment, connections.getCell(202), .85); assertEquals(2, connections.numSynapses()); connections.destroySynapse(synapse1); connections.destroySynapse(synapse2); assertEquals(0, connections.numSynapses()); connections.createSynapse(segment, connections.getCell(201), .85); assertEquals(1, connections.numSynapses()); connections.createSynapse(segment, connections.getCell(202), .90); assertEquals(2, connections.numSynapses()); connections.createSynapse(segment, connections.getCell(203), .8); assertEquals(2, connections.numSynapses()); }
Example 8
Source File: ConnectionsTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
/** * Destroy some segments then verify that the maxSegmentsPerCell is still * correctly applied. */ @Test public void testDestroySegmentsThenReachLimit() { Parameters p = Parameters.getTemporalDefaultParameters(); p.set(KEY.COLUMN_DIMENSIONS, new int[] { 32 }); p.set(KEY.CELLS_PER_COLUMN, 32); p.set(KEY.MAX_SEGMENTS_PER_CELL, 2); p.set(KEY.MAX_SYNAPSES_PER_SEGMENT, 2); Connections connections = new Connections(); p.apply(connections); TemporalMemory.init(connections); DistalDendrite segment1 = connections.createSegment(connections.getCell(11)); DistalDendrite segment2 = connections.createSegment(connections.getCell(11)); assertEquals(2, connections.numSegments()); connections.destroySegment(segment1); connections.destroySegment(segment2); assertEquals(0, connections.numSegments()); connections.createSegment(connections.getCell(11)); assertEquals(1, connections.numSegments()); connections.createSegment(connections.getCell(11)); assertEquals(2, connections.numSegments()); connections.createSegment(connections.getCell(11)); assertEquals(2, connections.numSegments(connections.getCell(11))); assertEquals(2, connections.numSegments()); }
Example 9
Source File: ConnectionsTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
/** * Destroy a segment that has a destroyed synapse and a non-destroyed * synapse. Create a new segment in the same place. Make sure its synapse * count is correct. */ @Test public void testReuseSegmentWithDestroyedSynapses() { Parameters p = Parameters.getTemporalDefaultParameters(); p.set(KEY.COLUMN_DIMENSIONS, new int[] { 32 }); p.set(KEY.CELLS_PER_COLUMN, 32); Connections connections = new Connections(); p.apply(connections); TemporalMemory.init(connections); DistalDendrite segment = connections.createSegment(connections.getCell(11)); Synapse synapse1 = connections.createSynapse(segment, connections.getCell(201), .85); connections.createSynapse(segment, connections.getCell(202), .85); connections.destroySynapse(synapse1); assertEquals(1, connections.numSynapses(segment)); connections.destroySegment(segment); DistalDendrite reincarnated = connections.createSegment(connections.getCell(11)); assertEquals(0, connections.numSynapses(reincarnated)); assertEquals(0, connections.getSynapses(reincarnated).size()); }
Example 10
Source File: ConnectionsTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
/** * Creates segments and synapses, then destroys segments and synapses on * either side of them and verifies that existing Segment and Synapse * instances still point to the same segment / synapse as before. */ @Test public void testPathsNotInvalidatedByOtherDestroys() { Parameters p = Parameters.getTemporalDefaultParameters(); p.set(KEY.COLUMN_DIMENSIONS, new int[] { 32 }); p.set(KEY.CELLS_PER_COLUMN, 32); Connections connections = new Connections(); p.apply(connections); TemporalMemory.init(connections); DistalDendrite segment1 = connections.createSegment(connections.getCell(11)); connections.createSegment(connections.getCell(12)); DistalDendrite segment3 = connections.createSegment(connections.getCell(13)); connections.createSegment(connections.getCell(14)); DistalDendrite segment5 = connections.createSegment(connections.getCell(15)); Cell cell203 = connections.getCell(203); Synapse synapse1 = connections.createSynapse(segment3, connections.getCell(201), .85); Synapse synapse2 = connections.createSynapse(segment3, connections.getCell(202), .85); Synapse synapse3 = connections.createSynapse(segment3, cell203, .85); Synapse synapse4 = connections.createSynapse(segment3, connections.getCell(204), .85); Synapse synapse5 = connections.createSynapse(segment3, connections.getCell(205), .85); assertEquals(cell203, synapse3.getPresynapticCell()); connections.destroySynapse(synapse1); assertEquals(cell203, synapse3.getPresynapticCell()); connections.destroySynapse(synapse5); assertEquals(cell203, synapse3.getPresynapticCell()); connections.destroySegment(segment1); List<Synapse> l234 = Arrays.stream(new Synapse[] { synapse2, synapse3, synapse4 }).collect(Collectors.toList()); assertEquals(connections.getSynapses(segment3), l234); connections.destroySegment(segment5); assertEquals(connections.getSynapses(segment3), l234); assertEquals(cell203, synapse3.getPresynapticCell()); }
Example 11
Source File: ConnectionsTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
/** * Creates a segment, creates a number of synapses on it, destroys a * synapse, and makes sure it got destroyed. */ @Test public void testDestroySynapse() { Parameters retVal = Parameters.getTemporalDefaultParameters(); retVal.set(KEY.COLUMN_DIMENSIONS, new int[] { 32 }); retVal.set(KEY.CELLS_PER_COLUMN, 4); Connections connections = new Connections(); retVal.apply(connections); TemporalMemory.init(connections); Cell cell20 = connections.getCell(20); DistalDendrite segment = connections.createSegment(cell20); Synapse synapse1 = connections.createSynapse(segment, connections.getCell(80), 0.85); Synapse synapse2 = connections.createSynapse(segment, connections.getCell(81), 0.85); Synapse synapse3 = connections.createSynapse(segment, connections.getCell(82), 0.15); assertEquals(3, connections.numSynapses()); connections.destroySynapse(synapse2); assertEquals(2, connections.numSynapses()); assertEquals(Arrays.asList(synapse1, synapse3), connections.getSynapses(segment)); Activity activity = connections.computeActivity( IntStream.rangeClosed(80, 82).mapToObj(i -> connections.getCell(i)).collect(Collectors.toList()), 0.5D); assertEquals(1, activity.numActiveConnected[segment.getIndex()]); assertEquals(2, activity.numActivePotential[segment.getIndex()]); }
Example 12
Source File: ConnectionsTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testDestroySegment() { Parameters retVal = Parameters.getTemporalDefaultParameters(); retVal.set(KEY.COLUMN_DIMENSIONS, new int[] { 32 }); retVal.set(KEY.CELLS_PER_COLUMN, 4); Connections connections = new Connections(); retVal.apply(connections); TemporalMemory.init(connections); connections.createSegment(connections.getCell(10)); DistalDendrite segment2 = connections.createSegment(connections.getCell(20)); connections.createSegment(connections.getCell(30)); connections.createSegment(connections.getCell(40)); connections.createSynapse(segment2, connections.getCell(80), 0.85); connections.createSynapse(segment2, connections.getCell(81), 0.85); connections.createSynapse(segment2, connections.getCell(82), 0.15); assertEquals(4, connections.numSegments()); assertEquals(3, connections.numSynapses()); connections.destroySegment(segment2); assertEquals(3, connections.numSegments()); assertEquals(0, connections.numSynapses()); Activity activity = connections.computeActivity( IntStream.rangeClosed(80, 82) .mapToObj(i -> connections.getCell(i)).collect(Collectors.toList()), 0.5D); assertEquals(0, activity.numActiveConnected[segment2.getIndex()]); assertEquals(0, activity.numActivePotential[segment2.getIndex()]); }
Example 13
Source File: ConnectionsTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
/** * Creates a synapse over the synapses per segment limit, and verifies * that the lowest permanence synapse is removed to make room for the new * synapse. */ @Test public void testSynapseReuse() { Parameters retVal = Parameters.getTemporalDefaultParameters(); retVal.set(KEY.COLUMN_DIMENSIONS, new int[] { 32 }); retVal.set(KEY.CELLS_PER_COLUMN, 4); retVal.set(KEY.MAX_SYNAPSES_PER_SEGMENT, 2); Connections connections = new Connections(); retVal.apply(connections); TemporalMemory.init(connections); Cell cell10 = connections.getCell(10); DistalDendrite segment1 = connections.createSegment(cell10); Synapse synapse1 = connections.createSynapse(segment1, connections.getCell(50), 0.34); Synapse synapse2 = connections.createSynapse(segment1, connections.getCell(51), 0.48); assertTrue(DeepEquals.deepEquals( Arrays.asList(synapse1, synapse2), connections.getSynapses(segment1))); // Add an additional synapse to force it over the limit of num synapses // per segment. connections.createSynapse(segment1, connections.getCell(52), .52); // Ensure lower permanence synapse was removed. Set<Cell> expected = IntStream.range(51, 53).mapToObj(i -> connections.getCell(i)).collect(Collectors.toSet()); assertTrue(DeepEquals.deepEquals(expected, connections.getSynapses(segment1) .stream() .map(s -> s.getPresynapticCell()) .collect(Collectors.toSet()))); }
Example 14
Source File: ConnectionsTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testCreateSegment() { Parameters retVal = Parameters.getTemporalDefaultParameters(); retVal.set(KEY.COLUMN_DIMENSIONS, new int[] { 32 }); retVal.set(KEY.CELLS_PER_COLUMN, 4); Connections connections = new Connections(); retVal.apply(connections); TemporalMemory.init(connections); Cell cell10 = connections.getCell(10); List<DistalDendrite> segments = connections.getSegments(cell10); // Establish list is empty == no current segments assertEquals(0, segments.size()); DistalDendrite segment1 = connections.createSegment(cell10); assertEquals(0, segment1.getIndex()); assertEquals(10, segment1.getParentCell().getIndex()); DistalDendrite segment2 = connections.createSegment(cell10); assertEquals(1, segment2.getIndex()); assertEquals(10, segment2.getParentCell().getIndex()); List<DistalDendrite> expected = Arrays.asList(new DistalDendrite[] { segment1, segment2 }); assertEquals(expected, connections.getSegments(cell10)); assertEquals(2, connections.numSegments()); }
Example 15
Source File: ConnectionsTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testCopy() { Parameters retVal = Parameters.getTemporalDefaultParameters(); retVal.set(KEY.COLUMN_DIMENSIONS, new int[] { 32 }); retVal.set(KEY.CELLS_PER_COLUMN, 4); Connections connections = new Connections(); retVal.apply(connections); TemporalMemory.init(connections); assertTrue(DeepEquals.deepEquals(connections, connections.copy())); }
Example 16
Source File: ConnectionsTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testSegmentPositionForSortKey() { Parameters retVal = Parameters.getTemporalDefaultParameters(); retVal.set(KEY.COLUMN_DIMENSIONS, new int[] { 32 }); retVal.set(KEY.CELLS_PER_COLUMN, 4); Connections connections = new Connections(); retVal.apply(connections); TemporalMemory.init(connections); Cell cell10 = connections.getCell(10); DistalDendrite segment0 = connections.createSegment(cell10); Cell cell9 = connections.getCell(9); DistalDendrite segment1 = connections.createSegment(cell9); Cell cell11 = connections.getCell(11); DistalDendrite segment2 = connections.createSegment(cell11); DistalDendrite segment3 = connections.createSegment(cell11); DistalDendrite segment4 = connections.createSegment(cell11); List<DistalDendrite> expected = Arrays.asList(segment1, segment0, segment2, segment3, segment4); List<DistalDendrite> segments = Arrays.asList(segment3, segment2, segment0, segment4, segment1); assertFalse(DeepEquals.deepEquals(expected, segments)); Collections.sort(segments, connections.segmentPositionSortKey); assertTrue(DeepEquals.deepEquals(expected, segments)); }
Example 17
Source File: ConnectionsTest.java From htm.java with GNU Affero General Public License v3.0 | 4 votes |
@Test public void testCreateSegmentReuse() { Parameters retVal = Parameters.getTemporalDefaultParameters(); retVal.set(KEY.COLUMN_DIMENSIONS, new int[] { 32 }); retVal.set(KEY.CELLS_PER_COLUMN, 4); retVal.set(KEY.MAX_SEGMENTS_PER_CELL, 2); Connections connections = new Connections(); retVal.apply(connections); TemporalMemory.init(connections); Cell cell42 = connections.getCell(42); Cell cell1 = connections.getCell(1); Cell cell2 = connections.getCell(2); DistalDendrite segment1 = connections.createSegment(cell42); connections.createSynapse(segment1, cell1, 0.5); connections.createSynapse(segment1, cell2, 0.5); // Let some time pass connections.startNewIteration(); connections.startNewIteration(); connections.startNewIteration(); // Create a segment with 3 synapses. Cell cell3 = connections.getCell(3); DistalDendrite segment2 = connections.createSegment(cell42); connections.createSynapse(segment2, cell1, 0.5); connections.createSynapse(segment2, cell2, 0.5); connections.createSynapse(segment2, cell3, 0.5); connections.startNewIteration(); // Give the first segment some activity. connections.recordSegmentActivity(segment1); // Create a new segment with 1 synapse. DistalDendrite segment3 = connections.createSegment(cell42); connections.createSynapse(segment3, cell1, 0.5); List<DistalDendrite> segments = connections.getSegments(cell42); assertEquals(2, segments.size()); // Verify first segment is there with same synapses. Set<Cell> expected = IntStream.range(1, 3).mapToObj(i -> connections.getCell(i)).collect(Collectors.toSet()); assertTrue(DeepEquals.deepEquals(expected, connections.getSynapses(segments.get(0)) .stream() .map(s -> s.getPresynapticCell()) .collect(Collectors.toSet()))); // Verify second segment has been replaced. expected = IntStream.range(1, 2).mapToObj(i -> connections.getCell(i)).collect(Collectors.toSet()); System.out.println("expected = " + expected); System.out.println("actual = " + connections.getSynapses(segments.get(1)) .stream() .map(s -> s.getPresynapticCell()) .collect(Collectors.toSet())); assertTrue(DeepEquals.deepEquals(expected, connections.getSynapses(segments.get(1)) .stream() .map(s -> s.getPresynapticCell()) .collect(Collectors.toSet()))); // Verify the flatIdxs were properly reused. assertTrue(segment1.getIndex() < 2); assertTrue(segment3.getIndex() < 2); assertEquals(segment1, connections.segmentForFlatIdx(segment1.getIndex())); assertEquals(segment3, connections.segmentForFlatIdx(segment3.getIndex())); }
Example 18
Source File: ConnectionsTest.java From htm.java with GNU Affero General Public License v3.0 | 4 votes |
/** * Creates a sample set of connections, and makes sure that computing the * activity for a collection of cells with no activity returns the right * activity data. */ @Test public void testComputeActivity() { Parameters p = Parameters.getTemporalDefaultParameters(); p.set(KEY.COLUMN_DIMENSIONS, new int[] { 32 }); p.set(KEY.CELLS_PER_COLUMN, 32); Connections connections = new Connections(); p.apply(connections); TemporalMemory.init(connections); // Cell with 1 segment. // Segment with: // - 1 connected synapse: active // - 2 matching synapses DistalDendrite segment1a = connections.createSegment(connections.getCell(10)); connections.createSynapse(segment1a, connections.getCell(150), .85); connections.createSynapse(segment1a, connections.getCell(151), .15); // Cell with 1 segment. // Segment with: // - 2 connected synapse: 2 active // - 3 matching synapses: 3 active DistalDendrite segment2a = connections.createSegment(connections.getCell(20)); connections.createSynapse(segment2a, connections.getCell(80), .85); connections.createSynapse(segment2a, connections.getCell(81), .85); Synapse synapse = connections.createSynapse(segment2a, connections.getCell(82), .85); synapse.setPermanence(null, 0.15); Connections c = connections; List<Cell> inputVec = IntStream.of(50, 52, 53, 80, 81, 82, 150, 151) .mapToObj(i -> c.getCell(i)) .collect(Collectors.toList()); Activity activity = c.computeActivity(inputVec, .5); assertEquals(1, activity.numActiveConnected[segment1a.getIndex()]); assertEquals(2, activity.numActivePotential[segment1a.getIndex()]); assertEquals(2, activity.numActiveConnected[segment2a.getIndex()]); assertEquals(3, activity.numActivePotential[segment2a.getIndex()]); }