org.numenta.nupic.Parameters Java Examples
The following examples show how to use
org.numenta.nupic.Parameters.
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: SpatialPoolerTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
public void setupDefaultParameters() { parameters = Parameters.getAllDefaultParameters(); parameters.set(KEY.INPUT_DIMENSIONS, new int[] { 32, 32 }); parameters.set(KEY.COLUMN_DIMENSIONS, new int[] { 64, 64 }); parameters.set(KEY.POTENTIAL_RADIUS, 16); parameters.set(KEY.POTENTIAL_PCT, 0.5); parameters.set(KEY.GLOBAL_INHIBITION, false); parameters.set(KEY.LOCAL_AREA_DENSITY, -1.0); parameters.set(KEY.NUM_ACTIVE_COLUMNS_PER_INH_AREA, 10.0); parameters.set(KEY.STIMULUS_THRESHOLD, 0.0); parameters.set(KEY.SYN_PERM_INACTIVE_DEC, 0.008); parameters.set(KEY.SYN_PERM_ACTIVE_INC, 0.05); parameters.set(KEY.SYN_PERM_CONNECTED, 0.10); parameters.set(KEY.MIN_PCT_OVERLAP_DUTY_CYCLES, 0.001); parameters.set(KEY.MIN_PCT_ACTIVE_DUTY_CYCLES, 0.001); parameters.set(KEY.DUTY_CYCLE_PERIOD, 1000); parameters.set(KEY.MAX_BOOST, 10.0); parameters.set(KEY.SEED, 42); parameters.setRandom(new UniversalRandom(42)); }
Example #2
Source File: SpatialPoolerTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
/** * When stimulusThreshold is 0, allow columns without any overlap to become * active. This test focuses on the global inhibition code path. */ @Test public void testZeroOverlap_NoStimulusThreshold_GlobalInhibition() { int inputSize = 10; int nColumns = 20; parameters = Parameters.getSpatialDefaultParameters(); parameters.set(KEY.INPUT_DIMENSIONS, new int[] { inputSize }); parameters.set(KEY.COLUMN_DIMENSIONS, new int[] { nColumns }); parameters.set(KEY.POTENTIAL_RADIUS, 10); parameters.set(KEY.GLOBAL_INHIBITION, true); parameters.set(KEY.NUM_ACTIVE_COLUMNS_PER_INH_AREA, 3.0); parameters.set(KEY.STIMULUS_THRESHOLD, 0.0); parameters.set(KEY.RANDOM, new UniversalRandom(42)); parameters.set(KEY.SEED, 42); SpatialPooler sp = new SpatialPooler(); Connections cn = new Connections(); parameters.apply(cn); sp.init(cn); int[] activeArray = new int[nColumns]; sp.compute(cn, new int[inputSize], activeArray, true); assertEquals(3, ArrayUtils.where(activeArray, ArrayUtils.INT_GREATER_THAN_0).length); }
Example #3
Source File: RegionTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testClose() { Parameters p = NetworkTestHarness.getParameters(); p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams()); p.set(KEY.RANDOM, new MersenneTwister(42)); Network n = Network.create("test network", p) .add(Network.createRegion("r1") .add(Network.createLayer("4", p) .add(MultiEncoder.builder().name("").build())) .close()); assertTrue(n.lookup("r1").isClosed()); try { n.lookup("r1").add(Network.createLayer("5", p)); fail(); }catch(Exception e) { assertTrue(e.getClass().isAssignableFrom(IllegalStateException.class)); assertEquals("Cannot add Layers when Region has already been closed.", e.getMessage()); } }
Example #4
Source File: NetworkAPIDemo.java From htm.java-examples with GNU Affero General Public License v3.0 | 6 votes |
/** * Creates a {@link Network} containing one {@link Region} with multiple * {@link Layer}s. This demonstrates the method by which multiple layers * are added and connected; and the flexibility of the fluent style api. * * @return a multi-layer Network */ Network createMultiLayerNetwork() { Parameters p = NetworkDemoHarness.getParameters(); p = p.union(NetworkDemoHarness.getNetworkDemoTestEncoderParams()); return Network.create("Network API Demo", p) .add(Network.createRegion("Region 1") .add(Network.createLayer("Layer 2/3", p) .alterParameter(KEY.AUTO_CLASSIFY, Boolean.TRUE) .add(Anomaly.create()) .add(new TemporalMemory())) .add(Network.createLayer("Layer 4", p) .add(new SpatialPooler())) .add(Network.createLayer("Layer 5", p) .add(Sensor.create(FileSensor::create, SensorParams.create( Keys::path, "", ResourceLocator.path("rec-center-hourly.csv"))))) .connect("Layer 2/3", "Layer 4") .connect("Layer 4", "Layer 5")); }
Example #5
Source File: LayerTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testNullSubscriber() { Parameters p = NetworkTestHarness.getParameters(); p = p.union(NetworkTestHarness.getNetworkDemoTestEncoderParams()); p.set(KEY.RANDOM, new MersenneTwister(42)); Layer<?> l = Network.createLayer("l", p); try { l.subscribe(null); fail(); }catch(Exception e) { assertEquals(IllegalArgumentException.class, e.getClass()); assertEquals("Subscriber cannot be null.", e.getMessage()); } }
Example #6
Source File: SpatialPoolerTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
/** * When stimulusThreshold is > 0, don't allow columns without any overlap to * become active. This test focuses on the global inhibition code path. */ @Test public void testZeroOverlap_StimulusThreshold_GlobalInhibition() { int inputSize = 10; int nColumns = 20; parameters = Parameters.getSpatialDefaultParameters(); parameters.set(KEY.INPUT_DIMENSIONS, new int[] { inputSize }); parameters.set(KEY.COLUMN_DIMENSIONS, new int[] { nColumns }); parameters.set(KEY.POTENTIAL_RADIUS, 10); parameters.set(KEY.GLOBAL_INHIBITION, true); parameters.set(KEY.NUM_ACTIVE_COLUMNS_PER_INH_AREA, 3.0); parameters.set(KEY.STIMULUS_THRESHOLD, 1.0); parameters.set(KEY.RANDOM, new UniversalRandom(42)); parameters.set(KEY.SEED, 42); SpatialPooler sp = new SpatialPooler(); Connections cn = new Connections(); parameters.apply(cn); sp.init(cn); int[] activeArray = new int[nColumns]; sp.compute(cn, new int[inputSize], activeArray, true); assertEquals(0, ArrayUtils.where(activeArray, ArrayUtils.INT_GREATER_THAN_0).length); }
Example #7
Source File: RegionTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testResetRecordNum() { Parameters p = NetworkTestHarness.getParameters(); Region r1 = Network.createRegion("r1"); r1.add(Network.createLayer("l1", p).add(new TemporalMemory())); r1.observe().subscribe(new Observer<Inference>() { @Override public void onCompleted() {} @Override public void onError(Throwable e) { e.printStackTrace(); } @Override public void onNext(Inference output) { System.out.println("output = " + Arrays.toString(output.getSDR())); } }); r1.compute(new int[] { 2,3,4 }); r1.compute(new int[] { 2,3,4 }); assertEquals(1, r1.lookup("l1").getRecordNum()); r1.resetRecordNum(); assertEquals(0, r1.lookup("l1").getRecordNum()); }
Example #8
Source File: RegionTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testAutomaticClose() { Parameters p = NetworkTestHarness.getParameters(); p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams()); p.set(KEY.RANDOM, new MersenneTwister(42)); Network n = Network.create("test network", p) .add(Network.createRegion("r1") .add(Network.createLayer("4", p) .add(MultiEncoder.builder().name("").build()))); //.close(); // Not necessary due to implicit call during start() or compute() Region r1 = n.lookup("r1"); r1.start(); assertTrue(r1.isClosed()); try { r1.add(Network.createLayer("5", p)); fail(); }catch(Exception e) { assertTrue(e.getClass().isAssignableFrom(IllegalStateException.class)); assertEquals("Cannot add Layers when Region has already been closed.", e.getMessage()); } }
Example #9
Source File: RegionTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testAdd() { Parameters p = NetworkTestHarness.getParameters(); p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams()); p.set(KEY.RANDOM, new MersenneTwister(42)); Network n = Network.create("test network", p) .add(Network.createRegion("r1") .add(Network.createLayer("4", p) .add(MultiEncoder.builder().name("").build()))); Region r1 = n.lookup("r1"); Layer<?>layer4 = r1.lookup("4"); assertNotNull(layer4); assertEquals("r1:4", layer4.getName()); try { r1.add(Network.createLayer("4", p)); fail(); }catch(Exception e) { assertTrue(e.getClass().isAssignableFrom(IllegalArgumentException.class)); assertEquals("A Layer with the name: 4 has already been added to this Region.", e.getMessage()); } }
Example #10
Source File: AbstractHTMInferenceOperator.java From flink-htm with GNU Affero General Public License v3.0 | 6 votes |
/** * Initialize the input function to map input elements to HTM encoder input. * @throws Exception */ protected void initInputFunction() throws Exception { // it is premature to call getInputNetwork, because no 'key' is available // when the operator is first opened. Network network = networkFactory.createNetwork(null); MultiEncoder encoder = network.getEncoder(); if(encoder == null) throw new IllegalArgumentException("a network encoder must be provided"); // handle the situation where an encoder parameter map was supplied rather than a fully-baked encoder. if(encoder.getEncoders(encoder) == null || encoder.getEncoders(encoder).size() < 1) { Map<String, Map<String, Object>> encoderParams = (Map<String, Map<String, Object>>) network.getParameters().get(Parameters.KEY.FIELD_ENCODING_MAP); if(encoderParams == null || encoderParams.size() < 1) { throw new IllegalStateException("No field encoding map found for MultiEncoder"); } encoder.addMultipleEncoders(encoderParams); } // generate the encoder input function final GenerateEncoderInputFunction<IN> generator = new GenerateEncoderInputFunction<>((CompositeType<IN>) inputType, encoder, executionConfig); inputFunction = generator.generate(); }
Example #11
Source File: MonitoredTemporalMemoryTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
public void prepConstructs(TemporalMemory tm, Connections cn) { Parameters p = getDefaultParameters(); p.apply(cn); TemporalMemory.init(cn); int[] previousActiveColumns = { 0 }; int[] activeColumns = { 1 }; Cell cell4 = cn.getCell(4); Set<Cell> expectedActiveCells = 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); assertTrue(cc.predictiveCells().equals(expectedActiveCells)); ComputeCycle cc2 = tm.compute(cn, activeColumns, true); assertTrue(cc2.activeCells().equals(expectedActiveCells)); }
Example #12
Source File: NetworkTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
private Network getLoadedDayOfWeekNetwork() { Parameters p = NetworkTestHarness.getParameters().copy(); p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams()); p.set(KEY.RANDOM, new FastRandom(42)); p.set(KEY.INFERRED_FIELDS, getInferredFieldsMap("dayOfWeek", CLAClassifier.class)); Sensor<ObservableSensor<String[]>> sensor = Sensor.create( ObservableSensor::create, SensorParams.create(Keys::obs, new Object[] {"name", PublisherSupplier.builder() .addHeader("dayOfWeek") .addHeader("number") .addHeader("B").build() })); Network network = Network.create("test network", p).add(Network.createRegion("r1") .add(Network.createLayer("1", p) .alterParameter(KEY.AUTO_CLASSIFY, true) .add(Anomaly.create()) .add(new TemporalMemory()) .add(new SpatialPooler()) .add(sensor))); return network; }
Example #13
Source File: PersistenceAPITest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
private Parameters getTestEncoderParams() { Map<String, Map<String, Object>> fieldEncodings = setupMap( null, 0, // n 0, // w 0, 0, 0, 0, null, null, null, "timestamp", "datetime", "DateEncoder"); fieldEncodings = setupMap( fieldEncodings, 25, 3, 0, 0, 0, 0.1, null, null, null, "consumption", "float", "RandomDistributedScalarEncoder"); fieldEncodings.get("timestamp").put(KEY.DATEFIELD_DOFW.getFieldName(), new Tuple(1, 1.0)); // Day of week fieldEncodings.get("timestamp").put(KEY.DATEFIELD_TOFD.getFieldName(), new Tuple(5, 4.0)); // Time of day fieldEncodings.get("timestamp").put(KEY.DATEFIELD_PATTERN.getFieldName(), "MM/dd/YY HH:mm"); Parameters p = Parameters.getEncoderDefaultParameters(); p.set(KEY.FIELD_ENCODING_MAP, fieldEncodings); return p; }
Example #14
Source File: NetworkTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testCalculateInputWidth_WithPrevLayer_NoTM() { Parameters p = NetworkTestHarness.getParameters(); p = p.union(NetworkTestHarness.getNetworkDemoTestEncoderParams()); p.set(KEY.RANDOM, new MersenneTwister(42)); Network network = Network.create("test network", p) .add(Network.createRegion("r1") .add(Network.createLayer("1", p) .add(Anomaly.create()) .add(new SpatialPooler())) .add(Network.createLayer("2", p) .add(new SpatialPooler())) .connect("1", "2")); Region r1 = network.lookup("r1"); Layer<?> layer1 = r1.lookup("1"); int width = layer1.calculateInputWidth(); assertEquals(2048, width); }
Example #15
Source File: DistalDendriteTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testGetActiveSynapses() { Connections cn = new Connections(); Parameters p = getDefaultParameters(null, KEY.CELLS_PER_COLUMN, 1); p = getDefaultParameters(p, KEY.MIN_THRESHOLD, 1); p.apply(cn); TemporalMemory.init(cn); Set<Cell> prevWinnerCells = cn.getCellSet(new int[] { 0, 1, 2, 3 }); DistalDendrite matchingSegment = cn.createSegment(cn.getCell(4)); cn.createSynapse(matchingSegment, cn.getCell(0), 0.5); Set<Synapse> syns = matchingSegment.getActiveSynapses(cn, prevWinnerCells); assertTrue(syns.size() == 1); assertTrue(syns.iterator().next().getPresynapticCell().equals(cn.getCell(0))); }
Example #16
Source File: TemporalMemoryTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
@Test 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); Set<Cell> expectedActiveCells = 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); assertTrue(cc.predictiveCells().equals(expectedActiveCells)); ComputeCycle cc2 = tm.compute(cn, activeColumns, true); assertTrue(cc2.activeCells().equals(expectedActiveCells)); }
Example #17
Source File: PersistenceAPITest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
private Network getLoadedDayOfWeekNetwork() { Parameters p = NetworkTestHarness.getParameters().copy(); p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams()); p.set(KEY.RANDOM, new FastRandom(42)); p.set(KEY.INFERRED_FIELDS, getInferredFieldsMap("dayOfWeek", CLAClassifier.class)); Sensor<ObservableSensor<String[]>> sensor = Sensor.create( ObservableSensor::create, SensorParams.create(Keys::obs, new Object[] {"name", PublisherSupplier.builder() .addHeader("dayOfWeek") .addHeader("number") .addHeader("B").build() })); Network network = Network.create("test network", p).add(Network.createRegion("r1") .add(Network.createLayer("1", p) .alterParameter(KEY.AUTO_CLASSIFY, true) .add(Anomaly.create()) .add(new TemporalMemory()) .add(new SpatialPooler()) .add(sensor))); return network; }
Example #18
Source File: SparseBinaryMatrixTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
public void setupParameters() { parameters = Parameters.getAllDefaultParameters(); parameters.set(KEY.INPUT_DIMENSIONS, new int[] { 5 });//5 parameters.set(KEY.COLUMN_DIMENSIONS, new int[] { 5 });//5 parameters.set(KEY.POTENTIAL_RADIUS, 3);//3 parameters.set(KEY.POTENTIAL_PCT, 0.5);//0.5 parameters.set(KEY.GLOBAL_INHIBITION, false); parameters.set(KEY.LOCAL_AREA_DENSITY, -1.0); parameters.set(KEY.NUM_ACTIVE_COLUMNS_PER_INH_AREA, 3.0); parameters.set(KEY.STIMULUS_THRESHOLD, 1.0); parameters.set(KEY.SYN_PERM_INACTIVE_DEC, 0.01); parameters.set(KEY.SYN_PERM_ACTIVE_INC, 0.1); parameters.set(KEY.SYN_PERM_TRIM_THRESHOLD, 0.05); parameters.set(KEY.SYN_PERM_CONNECTED, 0.1); parameters.set(KEY.MIN_PCT_OVERLAP_DUTY_CYCLES, 0.1); parameters.set(KEY.MIN_PCT_ACTIVE_DUTY_CYCLES, 0.1); parameters.set(KEY.DUTY_CYCLE_PERIOD, 10); parameters.set(KEY.MAX_BOOST, 10.0); parameters.set(KEY.SEED, 42); }
Example #19
Source File: HTMSensorTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
/** * Tests that a meaningful exception is thrown when no string category encoder configuration was provided */ @Test(expected = IllegalArgumentException.class) public void testStringCategoryEncoderNotInitialized() { Publisher manual = Publisher.builder() .addHeader("foo") .addHeader("string") .addHeader("C") .build(); Sensor<File> sensor = Sensor.create(ObservableSensor::create, SensorParams.create( Keys::obs, "", manual)); Map<String, Map<String, Object>> fieldEncodings = setupMap( null, 0, // n 0, // w 0, 0, 0, 0, null, null, null, "timestamp", "datetime", "DateEncoder"); Parameters params = Parameters.getEncoderDefaultParameters(); params.set(KEY.FIELD_ENCODING_MAP, fieldEncodings); HTMSensor<File> htmSensor = (HTMSensor<File>) sensor; htmSensor.initEncoder(params); }
Example #20
Source File: NetworkTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testCalculateInputWidth_NoPrevLayer_NoPrevRegion_andTM() { Parameters p = NetworkTestHarness.getParameters(); p = p.union(NetworkTestHarness.getNetworkDemoTestEncoderParams()); p.set(KEY.RANDOM, new MersenneTwister(42)); Network network = Network.create("test network", p) .add(Network.createRegion("r1") .add(Network.createLayer("2", p) .add(Anomaly.create()) .add(new TemporalMemory()) .close())); Region r1 = network.lookup("r1"); Layer<?> layer2 = r1.lookup("2"); int width = layer2.calculateInputWidth(); assertEquals(65536, width); }
Example #21
Source File: NetworkTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testCalculateInputWidth_NoPrevLayer_NoPrevRegion_andSPTM() { Parameters p = NetworkTestHarness.getParameters(); p = p.union(NetworkTestHarness.getNetworkDemoTestEncoderParams()); p.set(KEY.RANDOM, new MersenneTwister(42)); Network network = Network.create("test network", p) .add(Network.createRegion("r1") .add(Network.createLayer("2", p) .add(Anomaly.create()) .add(new TemporalMemory()) .add(new SpatialPooler()) .close())); Region r1 = network.lookup("r1"); Layer<?> layer2 = r1.lookup("2"); int width = layer2.calculateInputWidth(); assertEquals(8, width); assertEquals(8, layer2.getConnections().getPotentialRadius()); }
Example #22
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 #23
Source File: TemporalMemoryTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testLeastUsedCell() { TemporalMemory tm = new TemporalMemory(); Connections cn = new Connections(); Parameters p = getDefaultParameters(null, KEY.COLUMN_DIMENSIONS, new int[] { 2 }); p = getDefaultParameters(p, KEY.CELLS_PER_COLUMN, 2); p.apply(cn); TemporalMemory.init(cn); DistalDendrite dd = cn.createSegment(cn.getCell(0)); cn.createSynapse(dd, cn.getCell(3), 0.3); for(int i = 0;i < 100;i++) { assertEquals(1, tm.leastUsedCell(cn, cn.getColumn(0).getCells(), cn.getRandom()).getIndex()); } }
Example #24
Source File: NetworkTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testCalculateInputWidth_WithPrevLayer_WithTM() { Parameters p = NetworkTestHarness.getParameters(); p = p.union(NetworkTestHarness.getNetworkDemoTestEncoderParams()); p.set(KEY.RANDOM, new MersenneTwister(42)); Network network = Network.create("test network", p) .add(Network.createRegion("r1") .add(Network.createLayer("1", p) .add(Anomaly.create()) .add(new SpatialPooler())) .add(Network.createLayer("2", p) .add(Anomaly.create()) .add(new TemporalMemory()) .add(new SpatialPooler())) .connect("1", "2")); Region r1 = network.lookup("r1"); Layer<?> layer1 = r1.lookup("1"); int width = layer1.calculateInputWidth(); assertEquals(65536, width); }
Example #25
Source File: PersistenceAPITest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testHTMSensor_DaysOfWeek() { Object[] n = { "some name", ResourceLocator.path("days-of-week.csv") }; HTMSensor<File> sensor = (HTMSensor<File>)Sensor.create( FileSensor::create, SensorParams.create(Keys::path, n)); Parameters p = getParameters(); p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams()); sensor.initEncoder(p); SerialConfig config = new SerialConfig("testHTMSensor_DaysOfWeek", SerialConfig.SERIAL_TEST_DIR); PersistenceAPI api = Persistence.get(config); byte[] bytes = api.write(sensor); HTMSensor<File> serializedSensor = api.read(bytes); boolean b = DeepEquals.deepEquals(serializedSensor, sensor); deepCompare(serializedSensor, sensor); assertTrue(b); }
Example #26
Source File: NetworkConsistencyTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
public SimpleLayer(Parameters p, ScalarEncoder e, SpatialPooler s, TemporalMemory t, Anomaly a) { this.params = p; this.encoder = e; this.spatialPooler = s; this.temporalMemory = t; this.anomaly = a; configure(); }
Example #27
Source File: PersistenceAPITest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
private Network getLoadedDayOfWeekStreamHierarchy() { Parameters p = NetworkTestHarness.getParameters(); p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams()); p.set(KEY.RANDOM, new FastRandom(42)); p.set(KEY.INFERRED_FIELDS, getInferredFieldsMap("dayOfWeek", CLAClassifier.class)); Layer<?> l2 = null; Network network = Network.create("test network", p) .add(Network.createRegion("r1") .add(l2 = Network.createLayer("2", p) .add(Anomaly.create()) .add(new TemporalMemory())) .add(Network.createLayer("3", p) .add(new SpatialPooler()) .using(l2.getConnections())) .connect("2", "3")) .add(Network.createRegion("r2") .add(Network.createLayer("1", p) .alterParameter(KEY.AUTO_CLASSIFY, Boolean.TRUE) .add(new TemporalMemory()) .add(new SpatialPooler()) .add(Sensor.create(FileSensor::create, SensorParams.create( Keys::path, "", ResourceLocator.path("days-of-week-stream.csv")))))) .connect("r1", "r2"); return network; }
Example #28
Source File: NetworkTestHarness.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
/** * Returns Encoder parameters for the "dayOfWeek" test encoder. * @return */ public static Parameters getDayDemoTestEncoderParams() { Map<String, Map<String, Object>> fieldEncodings = getDayDemoFieldEncodingMap(); Parameters p = Parameters.getEncoderDefaultParameters(); p.set(KEY.FIELD_ENCODING_MAP, fieldEncodings); return p; }
Example #29
Source File: AbstractTemporalMemoryTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
public void init(Parameters overrides, PatternMachine pm) { this.parameters = createTMParams(overrides); this.connections = new Connections(); parameters.apply(connections); temporalMemory = new TemporalMemory(); TemporalMemory.init(connections); tm = new MonitoredTemporalMemory(temporalMemory, connections); this.patternMachine = pm; this.sequenceMachine = new SequenceMachine(patternMachine); }
Example #30
Source File: TemporalMemoryTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
@Test 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); assertFalse(cc.activeCells().size() == 0); assertFalse(cc.winnerCells().size() == 0); assertFalse(cc.predictiveCells().size() == 0); int[] zeroColumns = new int[0]; ComputeCycle cc2 = tm.compute(cn, zeroColumns, true); assertTrue(cc2.activeCells().size() == 0); assertTrue(cc2.winnerCells().size() == 0); assertTrue(cc2.predictiveCells().size() == 0); }