org.numenta.nupic.util.MersenneTwister Java Examples
The following examples show how to use
org.numenta.nupic.util.MersenneTwister.
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: TestHarness.java From flink-htm with GNU Affero General Public License v3.0 | 6 votes |
@Override public Network createNetwork(Object key) { Parameters p = getParameters(); p = p.union(getEncoderParams()); p.set(Parameters.KEY.COLUMN_DIMENSIONS, new int[] { 30 }); p.set(Parameters.KEY.SYN_PERM_INACTIVE_DEC, 0.1); p.set(Parameters.KEY.SYN_PERM_ACTIVE_INC, 0.1); p.set(Parameters.KEY.SYN_PERM_TRIM_THRESHOLD, 0.05); p.set(Parameters.KEY.SYN_PERM_CONNECTED, 0.4); p.set(Parameters.KEY.MAX_BOOST, 10.0); p.set(Parameters.KEY.DUTY_CYCLE_PERIOD, 7); p.set(Parameters.KEY.RANDOM, new MersenneTwister(42)); Map<String, Object> params = new HashMap<>(); params.put(KEY_MODE, Anomaly.Mode.PURE); Network n = Network.create("DayDemoNetwork", p) .add(Network.createRegion("r1") .add(Network.createLayer("1", p) .alterParameter(Parameters.KEY.AUTO_CLASSIFY, Boolean.TRUE) .alterParameter(Parameters.KEY.INFERRED_FIELDS, getInferredFieldsMaps()) .add(new TemporalMemory()) .add(new SpatialPooler()) .add(MultiEncoder.builder().name("").build()))); return n; }
Example #2
Source File: RegionTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
/** * Test that we automatically calculate the input dimensions despite * there being an improper Parameter setting. */ @Test public void testInputDimensionsAutomaticallyInferredFromEncoderWidth() { Parameters p = NetworkTestHarness.getParameters(); p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams()); p.set(KEY.RANDOM, new MersenneTwister(42)); // Purposefully set this to be wrong p.set(KEY.INPUT_DIMENSIONS, new int[] { 40, 40 }); Network.create("test network", p) .add(Network.createRegion("r1") .add(Network.createLayer("4", p) .add(MultiEncoder.builder().name("").build())) .close()); // Should correct the above ( {40,40} ) to have only one dimension whose width is 8 ( {8} ) assertTrue(Arrays.equals(new int[] { 8 }, (int[])p.get(KEY.INPUT_DIMENSIONS))); }
Example #3
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 #4
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 #5
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 #6
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 #7
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 #8
Source File: NetworkTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testCalculateInputWidth_NoPrevLayer_NoPrevRegion_andNoTM() { 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 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 #9
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 #10
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 #11
Source File: NetworkTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testPotentialRadiusFollowsInputWidth() { Parameters p = NetworkTestHarness.getParameters(); p = p.union(NetworkTestHarness.getNetworkDemoTestEncoderParams()); p.set(KEY.INPUT_DIMENSIONS, new int[] { 200 }); 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(200, width); assertEquals(200, layer2.getConnections().getPotentialRadius()); }
Example #12
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 #13
Source File: PersistenceAPITest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
private Network getLoadedHotGymHierarchy() { Parameters p = NetworkTestHarness.getParameters(); p = p.union(NetworkTestHarness.getNetworkDemoTestEncoderParams()); p.set(KEY.RANDOM, new MersenneTwister(42)); p.set(KEY.INFERRED_FIELDS, getInferredFieldsMap("consumption", CLAClassifier.class)); Network network = Network.create("test network", p) .add(Network.createRegion("r1") .add(Network.createLayer("2", p) .add(Anomaly.create()) .add(new TemporalMemory())) .add(Network.createLayer("3", p) .add(new SpatialPooler())) .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("rec-center-hourly.csv")))))) .connect("r1", "r2"); return network; }
Example #14
Source File: ParametersTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testDefaultsAndUpdates() { Parameters params = Parameters.getAllDefaultParameters(); assertEquals(params.get(Parameters.KEY.CELLS_PER_COLUMN), 32); assertEquals(params.get(Parameters.KEY.SEED), 42); assertEquals(true, ((Random)params.get(Parameters.KEY.RANDOM)).getClass().equals(MersenneTwister.class)); System.out.println("All Defaults:\n" + Parameters.getAllDefaultParameters()); System.out.println("Spatial Defaults:\n" + Parameters.getSpatialDefaultParameters()); System.out.println("Temporal Defaults:\n" + Parameters.getTemporalDefaultParameters()); parameters = Parameters.getSpatialDefaultParameters(); parameters.set(Parameters.KEY.INPUT_DIMENSIONS, new int[]{64, 64}); parameters.set(Parameters.KEY.COLUMN_DIMENSIONS, new int[]{32, 32}); parameters.set(Parameters.KEY.NUM_ACTIVE_COLUMNS_PER_INH_AREA, 0.02*64*64); System.out.println("Updated/Combined:\n" + parameters); }
Example #15
Source File: AnomalyLikelihoodTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
/** * Generate 1440 samples of fake metrics data with a particular distribution * of anomaly scores and metric values. Here we generate values every minute. * * @param mean * @param variance * @param metricMean * @param metricVariance * @return */ public static List<Sample> generateSampleData(double mean, double variance, double metricMean, double metricVariance) { List<Sample> retVal = new ArrayList<>(); Random random = new MersenneTwister(42); double[] samples = sampleDistribution(random, mean, variance, 1440); double[] metricValues = sampleDistribution(random, metricMean, metricVariance, 1440); for(int hour : ArrayUtils.range(0, 24)) { for(int minute : ArrayUtils.range(0, 60)) { retVal.add( new Sample( new DateTime(2013, 2, 2, hour, minute), metricValues[hour * 60 + minute], samples[hour * 60 + minute] ) ); } } return retVal; }
Example #16
Source File: LayerTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testBasicSetup_SPandTM() { Parameters p = NetworkTestHarness.getParameters().copy(); p.set(KEY.RANDOM, new MersenneTwister(42)); int[][] inputs = new int[7][8]; inputs[0] = new int[] { 1, 1, 0, 0, 0, 0, 0, 1 }; inputs[1] = new int[] { 1, 1, 1, 0, 0, 0, 0, 0 }; inputs[2] = new int[] { 0, 1, 1, 1, 0, 0, 0, 0 }; inputs[3] = new int[] { 0, 0, 1, 1, 1, 0, 0, 0 }; inputs[4] = new int[] { 0, 0, 0, 1, 1, 1, 0, 0 }; inputs[5] = new int[] { 0, 0, 0, 0, 1, 1, 1, 0 }; inputs[6] = new int[] { 0, 0, 0, 0, 0, 1, 1, 1 }; Layer<int[]> l = new Layer<>(p, null, new SpatialPooler(), new TemporalMemory(), null, null); TestObserver<Inference> tester; l.subscribe(tester = new TestObserver<Inference>() { @Override public void onCompleted() {} @Override public void onNext(Inference i) { assertNotNull(i); assertTrue(i.getSDR().length > 0); } }); // Now push some fake data through so that "onNext" is called above l.compute(inputs[0]); l.compute(inputs[1]); // Check for exception during the TestObserver's onNext() execution. checkObserver(tester); }
Example #17
Source File: LayerTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testBasicSetupEncoder_UsingObserve() { Parameters p = NetworkTestHarness.getParameters().copy(); p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams()); p.set(KEY.RANDOM, new MersenneTwister(42)); MultiEncoder me = MultiEncoder.builder().name("").build(); Layer<Map<String, Object>> l = new Layer<>(p, me, null, null, null, null); final int[][] expected = new int[7][8]; expected[0] = new int[] { 1, 1, 0, 0, 0, 0, 0, 1 }; expected[1] = new int[] { 1, 1, 1, 0, 0, 0, 0, 0 }; expected[2] = new int[] { 0, 1, 1, 1, 0, 0, 0, 0 }; expected[3] = new int[] { 0, 0, 1, 1, 1, 0, 0, 0 }; expected[4] = new int[] { 0, 0, 0, 1, 1, 1, 0, 0 }; expected[5] = new int[] { 0, 0, 0, 0, 1, 1, 1, 0 }; expected[6] = new int[] { 0, 0, 0, 0, 0, 1, 1, 1 }; Observable<Inference> o = l.observe(); TestObserver<Inference> tester; o.subscribe(tester = new TestObserver<Inference>() { int seq = 0; @Override public void onCompleted() {} @Override public void onNext(Inference output) { assertTrue(Arrays.equals(expected[seq++], output.getSDR())); } }); Map<String, Object> inputs = new HashMap<String, Object>(); for(double i = 0;i < 7;i++) { inputs.put("dayOfWeek", i); l.compute(inputs); } // Check for exception during the TestObserver's onNext() execution. checkObserver(tester); }
Example #18
Source File: LayerTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
@Test(expected = IllegalStateException.class) public void isClosedAddSensorTest() { Parameters p = NetworkTestHarness.getParameters(); p = p.union(NetworkTestHarness.getNetworkDemoTestEncoderParams()); p.set(KEY.RANDOM, new MersenneTwister(42)); Layer<?> l = Network.createLayer("l", p); l.close(); Sensor<File> sensor = Sensor.create( FileSensor::create, SensorParams.create( Keys::path, "", ResourceLocator.path("rec-center-hourly-small.csv"))); l.add(sensor); }
Example #19
Source File: LayerTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
@Test(expected = IllegalStateException.class) public void isClosedAddMultiEncoderTest() { Parameters p = NetworkTestHarness.getParameters(); p = p.union(NetworkTestHarness.getNetworkDemoTestEncoderParams()); p.set(KEY.RANDOM, new MersenneTwister(42)); Layer<?> l = Network.createLayer("l", p); l.close(); l.add(MultiEncoder.builder().name("").build()); }
Example #20
Source File: LayerTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
@Test(expected = IllegalStateException.class) public void isClosedAddSpatialPoolerTest() { Parameters p = NetworkTestHarness.getParameters(); p = p.union(NetworkTestHarness.getNetworkDemoTestEncoderParams()); p.set(KEY.RANDOM, new MersenneTwister(42)); Layer<?> l = Network.createLayer("l", p); l.close(); l.add(new SpatialPooler()); }
Example #21
Source File: LayerTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testBasicSetupEncoder_UsingSubscribe() { Parameters p = NetworkTestHarness.getParameters().copy(); p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams()); p.set(KEY.RANDOM, new MersenneTwister(42)); MultiEncoder me = MultiEncoder.builder().name("").build(); Layer<Map<String, Object>> l = new Layer<>(p, me, null, null, null, null); final int[][] expected = new int[7][8]; expected[0] = new int[] { 1, 1, 0, 0, 0, 0, 0, 1 }; expected[1] = new int[] { 1, 1, 1, 0, 0, 0, 0, 0 }; expected[2] = new int[] { 0, 1, 1, 1, 0, 0, 0, 0 }; expected[3] = new int[] { 0, 0, 1, 1, 1, 0, 0, 0 }; expected[4] = new int[] { 0, 0, 0, 1, 1, 1, 0, 0 }; expected[5] = new int[] { 0, 0, 0, 0, 1, 1, 1, 0 }; expected[6] = new int[] { 0, 0, 0, 0, 0, 1, 1, 1 }; TestObserver<Inference> tester; l.subscribe(tester = new TestObserver<Inference>() { int seq = 0; @Override public void onCompleted() {} @Override public void onNext(Inference output) { assertTrue(Arrays.equals(expected[seq++], output.getSDR())); } }); Map<String, Object> inputs = new HashMap<String, Object>(); for(double i = 0;i < 7;i++) { inputs.put("dayOfWeek", i); l.compute(inputs); } // Check for exception during the TestObserver's onNext() execution. checkObserver(tester); }
Example #22
Source File: RegionTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
/** * Test encoder bubbles up to L1 */ @Test public void testEncoderPassesUpToTopLayer() { Parameters p = NetworkTestHarness.getParameters(); p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams()); p.set(KEY.RANDOM, new MersenneTwister(42)); Map<String, Object> params = new HashMap<>(); params.put(KEY_MODE, Mode.PURE); Network n = Network.create("test network", p) .add(Network.createRegion("r1") .add(Network.createLayer("1", p) .alterParameter(KEY.AUTO_CLASSIFY, Boolean.TRUE)) .add(Network.createLayer("2", p) .add(Anomaly.create(params))) .add(Network.createLayer("3", p) .add(new TemporalMemory())) .add(Network.createLayer("4", p) .add(new SpatialPooler()) .add(MultiEncoder.builder().name("").build()))); Region r1 = n.lookup("r1"); r1.connect("1", "2").connect("2", "3").connect("3", "4"); assertNotNull(r1.lookup("1").getEncoder()); }
Example #23
Source File: ConnectionsTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
public static Parameters getParameters() { Parameters parameters = Parameters.getAllDefaultParameters(); parameters.set(KEY.INPUT_DIMENSIONS, new int[] { 8 }); parameters.set(KEY.COLUMN_DIMENSIONS, new int[] { 20 }); parameters.set(KEY.CELLS_PER_COLUMN, 6); //SpatialPooler specific parameters.set(KEY.POTENTIAL_RADIUS, 12);//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, 5.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); //Temporal Memory specific parameters.set(KEY.INITIAL_PERMANENCE, 0.2); parameters.set(KEY.CONNECTED_PERMANENCE, 0.8); parameters.set(KEY.MIN_THRESHOLD, 5); parameters.set(KEY.MAX_NEW_SYNAPSE_COUNT, 6); parameters.set(KEY.PERMANENCE_INCREMENT, 0.05); parameters.set(KEY.PERMANENCE_DECREMENT, 0.05); parameters.set(KEY.ACTIVATION_THRESHOLD, 4); parameters.set(KEY.RANDOM, new MersenneTwister(42)); return parameters; }
Example #24
Source File: AnomalyLikelihoodTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
/** * Test that sampleDistribution from a generated distribution returns roughly * the same parameters. */ @Test public void testSampleDistribution() { TObjectDoubleMap<String> p = new TObjectDoubleHashMap<>(); p.put(KEY_MEAN, 0.5); p.put(KEY_STDEV, Math.sqrt(0.1)); p.put(KEY_VARIANCE, 0.1); double[] samples = sampleDistribution(new MersenneTwister(), 0.5, 0.1, 1000); Statistic np = an.estimateNormal(samples, true); assertTrue(assertWithinEpsilon(p.get(KEY_MEAN), np.mean, 0.1)); assertTrue(assertWithinEpsilon(p.get(KEY_VARIANCE), np.variance, 0.1)); assertTrue(assertWithinEpsilon(p.get(KEY_STDEV), np.stdev, 0.1)); }
Example #25
Source File: PatternMachine.java From htm.java-examples with GNU Affero General Public License v3.0 | 5 votes |
/** * @param n Number of available bits in pattern * @param w Number of on bits in pattern * @param num Number of available patterns * @param seed Random seed * * Constructs a new {@code PatternMachine} */ public PatternMachine(int n, int w, int num, int seed) { this.n = n; this.w = w; this.numPatterns = num; random = new MersenneTwister(new int[] { seed }); patterns = new LinkedHashMap<Integer, LinkedHashSet<Integer>>(); generate(); }
Example #26
Source File: PatternMachine.java From htm.java-examples with GNU Affero General Public License v3.0 | 5 votes |
/** * @param n Number of available bits in pattern * @param w Number of on bits in pattern, each pattern * will have a `w` randomly selected from the list. * @param num Number of available patterns * @param seed Random seed * * Constructs a new {@code PatternMachine} */ public PatternMachine(int n, TIntList w, int num, int seed) { this.n = n; this.wList = w; random = new MersenneTwister(new int[] { seed }); patterns = new LinkedHashMap<Integer, LinkedHashSet<Integer>>(); this.numPatterns = num; generate(); }
Example #27
Source File: PatternMachine.java From htm.java-examples with GNU Affero General Public License v3.0 | 5 votes |
/** * Generates a canned set of sequences * * @param n * @param w * @param num * @param canned */ public PatternMachine(int n, int w, int num, boolean canned) { this.n = n; this.w = w; random = new MersenneTwister(new int[] { SEED }); patterns = new LinkedHashMap<Integer, LinkedHashSet<Integer>>(); this.numPatterns = num; generateCanned(); }
Example #28
Source File: PatternMachine.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
/** * @param n Number of available bits in pattern * @param w Number of on bits in pattern * @param num Number of available patterns * @param seed Random seed * * Constructs a new {@code PatternMachine} */ public PatternMachine(int n, int w, int num, int seed) { this.n = n; this.w = w; this.numPatterns = num; random = new MersenneTwister(new int[] { seed }); patterns = new LinkedHashMap<Integer, LinkedHashSet<Integer>>(); generate(); }
Example #29
Source File: NetworkTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
@Test public void closeTest() { Parameters p = NetworkTestHarness.getParameters(); p = p.union(NetworkTestHarness.getNetworkDemoTestEncoderParams()); p.set(KEY.RANDOM, new MersenneTwister(42)); Region region1 = Network.createRegion("region1"); Layer<?> layer1 = Network.createLayer("layer1", p); region1.add(layer1); Region region2 = Network.createRegion("region2"); Layer<?> layer2 = Network.createLayer("layer2", p); region2.add(layer2); Network network = Network.create("test network", p); // Calling close on an empty Network should not throw any Exceptions network.close(); // Calling close on a Network with a single unclosed Region network.add(region1); network.close(); assertTrue("Region 1 did not close, after closing Network", region1.isClosed()); assertTrue("Layer 1 did not close, after closing Network", layer1.isClosed()); // Calling close on a Network with two regions, one of which is closed network.add(region2); network.close(); assertTrue("Region 1 did not close, after closing Network with 2 Regions", region1.isClosed()); assertTrue("Layer 1 did not close, after closing Network with 2 Regions", layer1.isClosed()); assertTrue("Region 2 did not close, after closing Network with 2 Regions", region2.isClosed()); assertTrue("Layer 2 did not close, after closing Network with 2 Regions", layer2.isClosed()); }
Example #30
Source File: NetworkTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testCalculateInputWidth_NoPrevLayer_UpstreamRegion_without_TM() { Parameters p = NetworkTestHarness.getParameters(); p = p.union(NetworkTestHarness.getNetworkDemoTestEncoderParams()); p.set(KEY.RANDOM, new MersenneTwister(42)); p.set(KEY.INFERRED_FIELDS, getInferredFieldsMap("consumption", CLAClassifier.class)); 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()))) .add(Network.createRegion("r2") .add(Network.createLayer("1", p) .alterParameter(KEY.AUTO_CLASSIFY, Boolean.TRUE) .add(new SpatialPooler()) .add(Sensor.create(FileSensor::create, SensorParams.create( Keys::path, "", ResourceLocator.path("rec-center-hourly.csv")))))) .connect("r1", "r2"); Region r1 = network.lookup("r1"); Layer<?> layer2 = r1.lookup("2"); int width = layer2.calculateInputWidth(); assertEquals(2048, width); }