Java Code Examples for org.numenta.nupic.Parameters#getAllDefaultParameters()

The following examples show how to use org.numenta.nupic.Parameters#getAllDefaultParameters() . 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 vote down vote up
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: TemporalMemoryTest.java    From htm.java with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testAdaptSegment() {
    TemporalMemory tm = new TemporalMemory();
    Connections cn = new Connections();
    Parameters p = Parameters.getAllDefaultParameters();
    p.apply(cn);
    TemporalMemory.init(cn);
    
    DistalDendrite dd = cn.createSegment(cn.getCell(0));
    Synapse s1 = cn.createSynapse(dd, cn.getCell(23), 0.6);
    Synapse s2 = cn.createSynapse(dd, cn.getCell(37), 0.4);
    Synapse s3 = cn.createSynapse(dd, cn.getCell(477), 0.9);
    
    tm.adaptSegment(cn, dd, cn.getCellSet(23, 37), cn.getPermanenceIncrement(), cn.getPermanenceDecrement());
    
    assertEquals(0.7, s1.getPermanence(), 0.01);
    assertEquals(0.5, s2.getPermanence(), 0.01);
    assertEquals(0.8, s3.getPermanence(), 0.01);
}
 
Example 3
Source File: SpatialPoolerTest.java    From htm.java with GNU Affero General Public License v3.0 6 votes vote down vote up
public void setupParameters() {
    parameters = Parameters.getAllDefaultParameters();
    parameters.set(KEY.INPUT_DIMENSIONS, new int[] { 5 });
    parameters.set(KEY.COLUMN_DIMENSIONS, new int[] { 5 });
    parameters.set(KEY.POTENTIAL_RADIUS, 5);
    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, 3.0);
    parameters.set(KEY.STIMULUS_THRESHOLD, 0.0);
    parameters.set(KEY.SYN_PERM_INACTIVE_DEC, 0.01);
    parameters.set(KEY.SYN_PERM_ACTIVE_INC, 0.1);
    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.setRandom(new UniversalRandom(42));
}
 
Example 4
Source File: AbstractTemporalMemoryTest.java    From htm.java with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates {@link Parameters} for tests
 */
protected Parameters createTMParams(Parameters overrides) {
    parameters = Parameters.getAllDefaultParameters();
    parameters.set(KEY.COLUMN_DIMENSIONS, new int[] { 100 });
    parameters.set(KEY.CELLS_PER_COLUMN, 1);
    parameters.set(KEY.INITIAL_PERMANENCE, 0.8);
    parameters.set(KEY.CONNECTED_PERMANENCE, 0.7);
    parameters.set(KEY.MIN_THRESHOLD, 11);
    parameters.set(KEY.MAX_NEW_SYNAPSE_COUNT, 11);
    parameters.set(KEY.PERMANENCE_INCREMENT, 0.4);
    parameters.set(KEY.PERMANENCE_DECREMENT, 0.0);
    parameters.set(KEY.ACTIVATION_THRESHOLD, 11);
    
    if(overrides != null) {
        parameters.union(overrides);
    }
    
    return parameters;
}
 
Example 5
Source File: TemporalMemoryTest.java    From htm.java with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testAdaptSegmentToMax() {
    TemporalMemory tm = new TemporalMemory();
    Connections cn = new Connections();
    Parameters p = Parameters.getAllDefaultParameters();
    p.apply(cn);
    TemporalMemory.init(cn);
    
    DistalDendrite dd = cn.createSegment(cn.getCell(0));
    Synapse s1 = cn.createSynapse(dd, cn.getCell(23), 0.9);
    
    tm.adaptSegment(cn, dd, cn.getCellSet(23), cn.getPermanenceIncrement(), cn.getPermanenceDecrement());
    assertEquals(1.0, s1.getPermanence(), 0.1);
    
    // Now permanence should be at max
    tm.adaptSegment(cn, dd, cn.getCellSet(23), cn.getPermanenceIncrement(), cn.getPermanenceDecrement());
    assertEquals(1.0, s1.getPermanence(), 0.1);
}
 
Example 6
Source File: SparseBinaryMatrixTest.java    From htm.java with GNU Affero General Public License v3.0 6 votes vote down vote up
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 7
Source File: QuickTest.java    From htm.java-examples with GNU Affero General Public License v3.0 5 votes vote down vote up
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.0005);
    parameters.set(KEY.SYN_PERM_ACTIVE_INC, 0.0015);
    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.1);//0.05
    parameters.set(KEY.PERMANENCE_DECREMENT, 0.1);//0.05
    parameters.set(KEY.ACTIVATION_THRESHOLD, 4);
    
    parameters.set(KEY.RANDOM, new FastRandom());

    return parameters;
}
 
Example 8
Source File: TemporalMemoryTest.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testNumberOfCells() {
    Connections cn = new Connections();
    Parameters p = Parameters.getAllDefaultParameters();
    p.set(KEY.COLUMN_DIMENSIONS, new int[] { 64, 64 });
    p.set(KEY.CELLS_PER_COLUMN, 32);
    p.apply(cn);
    TemporalMemory.init(cn);
    
    assertEquals(64 * 64 * 32, cn.getCells().length);
}
 
Example 9
Source File: ConnectionsTest.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
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 10
Source File: PersistenceAPITest.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
public 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 FastRandom(42));
    
    return parameters;
}
 
Example 11
Source File: NetworkTestHarness.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns the default parameters used for the "dayOfWeek" encoder and algorithms.
 * @return
 */
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, -1);//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);
    
    return parameters;
}
 
Example 12
Source File: TemporalMemoryTest.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testNumberOfColumns() {
    Connections cn = new Connections();
    Parameters p = Parameters.getAllDefaultParameters();
    p.set(KEY.COLUMN_DIMENSIONS, new int[] { 64, 64 });
    p.set(KEY.CELLS_PER_COLUMN, 32);
    p.apply(cn);
    TemporalMemory.init(cn);
    
    assertEquals(64 * 64, cn.getNumColumns());
}
 
Example 13
Source File: LayerTest.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void TestMakeClassifiersWithNoInferredFieldsKey() {
    // Setup Parameters
    Parameters p = Parameters.getAllDefaultParameters();

    // Create MultiEncoder
    MultiEncoder me = MultiEncoder.builder().name("").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 {
        l.makeClassifiers(l.getEncoder());
    } catch (IllegalStateException e) {
        assertTrue(e.getMessage().contains("KEY.INFERRED_FIELDS"));
        assertTrue(e.getMessage().contains("null"));
        assertTrue(e.getMessage().contains("empty"));
    }
}
 
Example 14
Source File: LayerTest.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testInferInputDimensions() {
    Parameters p = Parameters.getAllDefaultParameters();
    Layer<Map<String, Object>> l = new Layer<>(p, null, new SpatialPooler(), new TemporalMemory(), Boolean.TRUE, null);
    
    int[] dims = l.inferInputDimensions(16384, 2);
    assertTrue(Arrays.equals(new int[] { 128, 128 }, dims));
    
    dims = l.inferInputDimensions(8000, 3);
    assertTrue(Arrays.equals(new int[] { 20, 20, 20 }, dims));
    
    // Now test non-square dimensions
    dims = l.inferInputDimensions(450, 2);
    assertTrue(Arrays.equals(new int[] { 1, 450 }, dims));
}
 
Example 15
Source File: LayerTest.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testEquality() {
    Parameters p = Parameters.getAllDefaultParameters();
    Layer<Map<String, Object>> l = new Layer<>(p, null, new SpatialPooler(), new TemporalMemory(), Boolean.TRUE, null);
    Layer<Map<String, Object>> l2 = new Layer<>(p, null, new SpatialPooler(), new TemporalMemory(), Boolean.TRUE, null);
    
    assertTrue(l.equals(l));
    assertFalse(l.equals(null));
    assertTrue(l.equals(l2));
   
    l2.name("I'm different");
    assertFalse(l.equals(l2));
    
    l2.name(null);
    assertTrue(l.equals(l2));
    
    Network n = new Network("TestNetwork", p);
    Region r = new Region("r1", n);
    l.setRegion(r);
    assertFalse(l.equals(l2));
    
    l2.setRegion(r);
    assertTrue(l.equals(l2));
    
    Region r2 = new Region("r2", n);
    l2.setRegion(r2);
    assertFalse(l.equals(l2));
}
 
Example 16
Source File: AlgorithmDeterminacyTest.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
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 17
Source File: NetworkConsistencyTest.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
private 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.0005);
    parameters.set(KEY.SYN_PERM_ACTIVE_INC, 0.0015);
    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.1);//0.05
    parameters.set(KEY.PERMANENCE_DECREMENT, 0.1);//0.05
    parameters.set(KEY.ACTIVATION_THRESHOLD, 4);
    
    parameters.set(KEY.RANDOM, new FastRandom(42));

    return parameters;
}
 
Example 18
Source File: NetworkDemoHarness.java    From htm.java-examples with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns the default parameters used for the "dayOfWeek" encoder and algorithms.
 * @return
 */
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);
    
    return parameters;
}
 
Example 19
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);
}
 
Example 20
Source File: LayerTest.java    From htm.java with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void testLayerWithObservableInputIntegerArray() {
    Publisher manual = Publisher.builder()
        .addHeader("sdr_in")
        .addHeader("darr")
        .addHeader("B")
        .build();

    Sensor<ObservableSensor<String[]>> sensor = Sensor.create(
        ObservableSensor::create, 
            SensorParams.create(
                Keys::obs, new Object[] {"name", manual}));

    Parameters p = Parameters.getAllDefaultParameters();
    p = p.union(getArrayTestParams());
    p.set(KEY.RANDOM, new MersenneTwister(42));

    HTMSensor<ObservableSensor<String[]>> htmSensor = (HTMSensor<ObservableSensor<String[]>>)sensor;

    Network n = Network.create("test network", p);
    final Layer<int[]> l = new Layer<>(n);
    l.add(htmSensor);

    String input = "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, "
                    + "1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, "
                    + "0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
                    + "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
                    + "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
                    + "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
                    + "1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, "
                    + "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, "
                    + "1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
                    + "0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, "
                    + "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, "
                    + "1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
                    + "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
                    + "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
                    + "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
                    + "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
                    + "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
                    + "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
                    + "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "
                    + "0, 0, 0, 0, 0, 0, 0, 0, 0, 0]";

    TestObserver<Inference> tester;
    l.subscribe(tester = new TestObserver<Inference>() {
        @Override public void onCompleted() {}
        @Override public void onNext(Inference output) {
            assertEquals(input, Arrays.toString((int[])output.getLayerInput()));
        }
    });
    
    l.start();

    try {
        String[] entries = { 
              input
        };

        // Send inputs through the observable
        for(String s : entries) {
            manual.onNext(s);
            manual.onComplete();
        }

        l.getLayerThread().join();
    }catch(Exception e) {
        e.printStackTrace();
        fail();
    }
    
    // Check for exception during the TestObserver's onNext() execution.
    checkObserver(tester);
}