Java Code Examples for org.numenta.nupic.encoders.MultiEncoder#addEncoder()

The following examples show how to use org.numenta.nupic.encoders.MultiEncoder#addEncoder() . 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: RunLayer.java    From htm.java with GNU Affero General Public License v3.0 6 votes vote down vote up
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 2
Source File: LayerTest.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void TestMakeClassifiersWithInvalidInferredFieldsKey() {
     // Setup Parameters
    Parameters p = Parameters.getAllDefaultParameters();
    Map<String, Class<? extends Classifier>> inferredFieldsMap = new HashMap<>();
    inferredFieldsMap.put("field1", Classifier.class);
    p.set(KEY.INFERRED_FIELDS, inferredFieldsMap);

    // Create MultiEncoder and add the fields' encoders to it
    MultiEncoder me = MultiEncoder.builder().name("").build();
    me.addEncoder(
            "field1",
            RandomDistributedScalarEncoder.builder().resolution(1).build()
    );

    // Create a Layer with Parameters and MultiEncoder
    Layer<Map<String, Object>> l = new Layer<>(
            p,
            me,
            new SpatialPooler(),
            new TemporalMemory(),
            true,
            null
    );

    // Make sure the makeClassifiers() method throws exception due to
    // absence of KEY.INFERRED_FIELDS in the Parameters object
    try {
        NamedTuple nt = l.makeClassifiers(l.getEncoder());
    } catch (IllegalStateException e) {
        assertTrue(e.getMessage().contains("Invalid Classifier class token"));
    }
}
 
Example 3
Source File: LayerTest.java    From htm.java with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void testMakeClassifiers() {
    // Setup Parameters
    Parameters p = Parameters.getAllDefaultParameters();
    Map<String, Class<? extends Classifier>> inferredFieldsMap = new HashMap<>();
    inferredFieldsMap.put("field1", CLAClassifier.class);
    inferredFieldsMap.put("field2", SDRClassifier.class);
    inferredFieldsMap.put("field3", null);
    p.set(KEY.INFERRED_FIELDS, inferredFieldsMap);

    // Create MultiEncoder and add the fields' encoders to it
    MultiEncoder me = MultiEncoder.builder().name("").build();
    me.addEncoder(
            "field1",
            RandomDistributedScalarEncoder.builder().resolution(1).build()
    );
    me.addEncoder(
            "field2",
            RandomDistributedScalarEncoder.builder().resolution(1).build()
    );
    me.addEncoder(
            "field3",
            RandomDistributedScalarEncoder.builder().resolution(1).build()
    );

    // Create a Layer with Parameters and MultiEncoder
    Layer<Map<String, Object>> l = new Layer<>(
            p,
            me,
            new SpatialPooler(),
            new TemporalMemory(),
            true,
            null
    );

    // Make sure the makeClassifiers() method matches each
    // field to the specified Classifier type
    NamedTuple nt = l.makeClassifiers(l.getEncoder());
    assertEquals(nt.get("field1").getClass(), CLAClassifier.class);
    assertEquals(nt.get("field2").getClass(), SDRClassifier.class);
    assertEquals(nt.get("field3"), null);
}