org.numenta.nupic.encoders.ScalarEncoder Java Examples
The following examples show how to use
org.numenta.nupic.encoders.ScalarEncoder.
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: NetworkConsistencyTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
public SimpleLayer() { params = getParameters(); ScalarEncoder.Builder dayBuilder = ScalarEncoder.builder() .n(8) .w(3) .radius(1.0) .minVal(1.0) .maxVal(8) .periodic(true) .forced(true) .resolution(1); encoder = dayBuilder.build(); spatialPooler = new SpatialPooler(); temporalMemory = new TemporalMemory(); Map<String, Object> anomalyParams = new HashMap<>(); anomalyParams.put(KEY_MODE, Mode.PURE); anomaly = Anomaly.create(anomalyParams); configure(); }
Example #2
Source File: RunLayer.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
public static MultiEncoder createEncoder() { MultiEncoder encoder = MultiEncoder.builder().name("").build(); ScalarEncoder se = ScalarEncoder.builder() .n(50) .w(21) .minVal(0) .maxVal(100) .periodic(false) .clipInput(true) .name("value") .build(); encoder.addEncoder("value", se); DateEncoder de = DateEncoder.builder() .timeOfDay(21, 9.5) .name("timestamp") .build(); encoder.addEncoder("timestamp", de); return encoder; }
Example #3
Source File: QuickTest.java From htm.java-examples with GNU Affero General Public License v3.0 | 5 votes |
/** * @param args the command line arguments */ public static void main(String[] args) { Parameters params = getParameters(); System.out.println(params); // Toggle this to switch between resetting on every week start day isResetting = true; //Layer components ScalarEncoder.Builder dayBuilder = ScalarEncoder.builder() .n(8) .w(3) .radius(1.0) .minVal(1.0) .maxVal(8) .periodic(true) .forced(true) .resolution(1); ScalarEncoder encoder = dayBuilder.build(); SpatialPooler sp = new SpatialPooler(); TemporalMemory tm = new TemporalMemory(); CLAClassifier classifier = new CLAClassifier(new TIntArrayList(new int[] { 1 }), 0.1, 0.3, 0); Layer<Double> layer = getLayer(params, encoder, sp, tm, classifier); for(double i = 0, x = 0, j = 0;j < 1500;j = (i == 6 ? j + 1: j), i = (i == 6 ? 0 : i + 1), x++) { // USE "X" here to control run length if (i == 0 && isResetting) { System.out.println("reset:"); tm.reset(layer.getMemory()); } // For 3rd argument: Use "i" for record num if re-cycling records (isResetting == true) - otherwise use "x" (the sequence number) runThroughLayer(layer, i + 1, isResetting ? (int)i : (int)x, (int)x); } }
Example #4
Source File: QuickTest.java From htm.java-examples with GNU Affero General Public License v3.0 | 5 votes |
public LayerImpl(Parameters p, ScalarEncoder e, SpatialPooler s, TemporalMemory t, CLAClassifier c) { this.params = p; this.encoder = e; this.spatialPooler = s; this.temporalMemory = t; this.classifier = c; params.apply(memory); spatialPooler.init(memory); TemporalMemory.init(memory); columnCount = memory.getPotentialPools().getMaxIndex() + 1; //If necessary, flatten multi-dimensional index cellsPerColumn = memory.getCellsPerColumn(); }
Example #5
Source File: QuickTestTest.java From htm.java-examples with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testRunThroughLayer() { Layer<Double> layer = null; try { Parameters params = QuickTest.getParameters(); //Layer components ScalarEncoder.Builder dayBuilder = ScalarEncoder.builder() .n(8) .w(3) .radius(1.0) .minVal(1.0) .maxVal(8) .periodic(true) .forced(true) .resolution(1); ScalarEncoder encoder = dayBuilder.build(); SpatialPooler sp = new SpatialPooler(); TemporalMemory tm = new TemporalMemory(); CLAClassifier classifier = new CLAClassifier(new TIntArrayList(new int[] { 1 }), 0.1, 0.3, 0); layer = QuickTest.getLayer(params, encoder, sp, tm, classifier); for(double i = 1, x = 0;x < 10000;i = (i == 7 ? 1 : i + 1), x++) {// USE "X" here to control run length if (i == 1) tm.reset(layer.getMemory()); QuickTest.runThroughLayer(layer, i, (int)i, (int)x); } }catch(Exception e) { e.printStackTrace(); fail(); } System.out.println("actual = " + Arrays.toString(layer.getActual()) + ", predicted = " + Arrays.toString(layer.getPredicted())); //assertArrayEquals(layer.getActual(), layer.getPredicted()); }
Example #6
Source File: HTMSensor.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
/** * Searches through the specified {@link MultiEncoder}'s previously configured * encoders to find and return one that is of type {@link ScalarEncoder}, * {@link RandomDistributedScalarEncoder}, {@link AdaptiveScalarEncoder}, * {@link LogEncoder} or {@link DeltaEncoder}. * * @param enc the containing {@code MultiEncoder} * @return */ private Optional<Encoder<?>> getNumberEncoder(MultiEncoder enc) { for(EncoderTuple t : enc.getEncoders(enc)) { if((t.getEncoder() instanceof RandomDistributedScalarEncoder) || (t.getEncoder() instanceof ScalarEncoder) || (t.getEncoder() instanceof AdaptiveScalarEncoder) || (t.getEncoder() instanceof LogEncoder) || (t.getEncoder() instanceof DeltaEncoder)) { return Optional.of(t.getEncoder()); } } return Optional.empty(); }
Example #7
Source File: AbstractAlgorithmBenchmark.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
@Setup public void init() { SDR = new int[2048]; //Layer components ScalarEncoder.Builder dayBuilder = ScalarEncoder.builder() .n(8) .w(3) .radius(1.0) .minVal(1.0) .maxVal(8) .periodic(true) .forced(true) .resolution(1); encoder = dayBuilder.build(); pooler = new SpatialPooler(); memory = new Connections(); Parameters params = getParameters(); params.apply(memory); pooler = new SpatialPooler(); pooler.init(memory); temporalMemory = new TemporalMemory(); TemporalMemory.init(memory); }
Example #8
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 #9
Source File: QuickDayTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
/** * @param args the command line arguments */ public static void main(String[] args) { Parameters params = getParameters(); System.out.println(params); // Toggle this to switch between resetting on every week start day isResetting = true; //Layer components ScalarEncoder.Builder dayBuilder = ScalarEncoder.builder() .n(8) .w(3) .radius(1.0) .minVal(1.0) .maxVal(8) .periodic(true) .forced(true) .resolution(1); ScalarEncoder encoder = dayBuilder.build(); SpatialPooler sp = new SpatialPooler(); TemporalMemory tm = new TemporalMemory(); CLAClassifier classifier = new CLAClassifier(new TIntArrayList(new int[] { 1 }), 0.1, 0.3, 0); Layer<Double> layer = getLayer(params, encoder, sp, tm, classifier); for(double i = 0, x = 0, j = 0;j < 1500;j = (i == 6 ? j + 1: j), i = (i == 6 ? 0 : i + 1), x++) { // USE "X" here to control run length if (i == 0 && isResetting) { System.out.println("reset:"); tm.reset(layer.getMemory()); } // For 3rd argument: Use "i" for record num if re-cycling records (isResetting == true) - otherwise use "x" (the sequence number) runThroughLayer(layer, i + 1, isResetting ? (int)i : (int)x, (int)x); } }
Example #10
Source File: QuickDayTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
public LayerImpl(Parameters p, ScalarEncoder e, SpatialPooler s, TemporalMemory t, CLAClassifier c) { this.params = p; this.encoder = e; this.spatialPooler = s; this.temporalMemory = t; this.classifier = c; params.apply(memory); spatialPooler.init(memory); TemporalMemory.init(memory); columnCount = memory.getPotentialPools().getMaxIndex() + 1; //If necessary, flatten multi-dimensional index cellsPerColumn = memory.getCellsPerColumn(); }
Example #11
Source File: QuickTest.java From htm.java-examples with GNU Affero General Public License v3.0 | 4 votes |
public static Layer<Double> getLayer(Parameters p, ScalarEncoder e, SpatialPooler s, TemporalMemory t, CLAClassifier c) { Layer<Double> l = new LayerImpl(p, e, s, t, c); return l; }
Example #12
Source File: MultiEncoderTest.java From htm.java with GNU Affero General Public License v3.0 | 4 votes |
/** * Test addition of encoders one-by-one. */ @Test public void testSerialAdditions() { setUp(); initME(); ScalarEncoder dow = ScalarEncoder.builder() .w(3) .resolution(1) .minVal(1) .maxVal(8) .periodic(true) .name("day of week") .forced(true) .build(); me.addEncoder("dow", dow); ScalarEncoder myval = ScalarEncoder.builder() .w(5) .resolution(1) .minVal(1) .maxVal(10) .periodic(false) .name("aux") .forced(true) .build(); me.addEncoder("myval", myval); runScalarTests(me); List<String> categoryList = new ArrayList<String>(); categoryList.add("run"); categoryList.add("pass"); categoryList.add("kick"); CategoryEncoder myCat = CategoryEncoder.builder() .radius(2) .w(3) .categoryList(categoryList) .forced(true) .build(); me.addEncoder("myCat", myCat); runMixedTests(me); }
Example #13
Source File: QuickDayTest.java From htm.java with GNU Affero General Public License v3.0 | 4 votes |
public static Layer<Double> getLayer(Parameters p, ScalarEncoder e, SpatialPooler s, TemporalMemory t, CLAClassifier c) { Layer<Double> l = new LayerImpl(p, e, s, t, c); return l; }