Ejemplo n.º 1
0
  ///////////////////////////////////////////
  //             HELPER METHODS            //
  ///////////////////////////////////////////
  private Network getLoadedDayOfWeekNetwork() {
    Parameters p = NetworkTestHarness.getParameters().copy();
    p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams());
    p.set(KEY.RANDOM, new FastRandom(42));

    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;
  }
Ejemplo n.º 2
0
 /**
  * Called internally to populate a {@link Parameters} object with the keys and values specified in
  * the passed in map.
  *
  * @return {@link Parameters} object
  */
 private static Parameters getParameters(Map<KEY, Object> map) {
   Parameters result = new Parameters();
   for (KEY key : map.keySet()) {
     result.setParameterByKey(key, map.get(key));
   }
   return result;
 }
 @Test
 public void testGetParameters() {
   Parameters params = QuickTest.getParameters();
   assertTrue(((int[]) params.getParameterByKey(KEY.INPUT_DIMENSIONS))[0] == 8);
   assertTrue(((int[]) params.getParameterByKey(KEY.COLUMN_DIMENSIONS))[0] == 20);
   assertTrue(((int) params.getParameterByKey(KEY.CELLS_PER_COLUMN)) == 6);
   assertEquals(
       ((double) params.getParameterByKey(KEY.PERMANENCE_INCREMENT)),
       ((double) params.getParameterByKey(KEY.PERMANENCE_DECREMENT)),
       0.0);
 }
Ejemplo n.º 4
0
  @Test
  public void testUnion() {
    Parameters params = Parameters.getAllDefaultParameters();
    Parameters arg = Parameters.getAllDefaultParameters();
    arg.setParameterByKey(KEY.CELLS_PER_COLUMN, 5);

    assertTrue((int) params.getParameterByKey(KEY.CELLS_PER_COLUMN) != 5);
    params.union(arg);
    assertTrue((int) params.getParameterByKey(KEY.CELLS_PER_COLUMN) == 5);
  }
Ejemplo n.º 5
0
  @Test
  public void testPrettyPrintDatum() {
    Parameters parameters = Parameters.getAllDefaultParameters();
    Connections connections = new Connections();
    parameters.apply(connections);

    TemporalMemory temporalMemory = new TemporalMemory();
    TemporalMemory.init(connections);
    MonitoredTemporalMemory monitoredTM = new MonitoredTemporalMemory(temporalMemory, connections);

    Metric metric = new Metric(monitoredTM, "Test", Arrays.asList(2.3, 3.4, 5.5, 6.6, 7.7));

    MetricsTrace trace = null;
    String traceData = null;
    try {
      trace = new MetricsTrace(monitoredTM, "Test");
      traceData = trace.prettyPrintDatum(metric);
    } catch (Exception e) {
      fail();
    }

    assertEquals("min: 2.30, max: 7.70, sum: 25.50, mean: 5.10, std dev: 1.99", traceData);
  }
Ejemplo n.º 6
0
  /**
   * Initializes this {@code HTMSensor}'s internal encoders if and only if the encoders have not
   * been previously initialized.
   */
  @SuppressWarnings("unchecked")
  public void initEncoder(Parameters p) {
    this.localParameters = p;

    Map<String, Map<String, Object>> encoderSettings;
    if ((encoderSettings =
                (Map<String, Map<String, Object>>) p.getParameterByKey(KEY.FIELD_ENCODING_MAP))
            != null
        && !encodersInitted) {

      initEncoders(encoderSettings);
      makeIndexEncoderMap();

      encodersInitted = true;
    }
  }
Ejemplo n.º 7
0
  /**
   * Called internally during construction to build the encoders needed to process the configured
   * field types.
   */
  @SuppressWarnings("unchecked")
  private void createEncoder() {
    encoder = MultiEncoder.builder().name("MultiEncoder").build();

    Map<String, Map<String, Object>> encoderSettings;
    if (localParameters != null
        && (encoderSettings =
                (Map<String, Map<String, Object>>)
                    localParameters.getParameterByKey(KEY.FIELD_ENCODING_MAP))
            != null
        && !encoderSettings.isEmpty()) {

      initEncoders(encoderSettings);
      makeIndexEncoderMap();
    }
  }
Ejemplo n.º 8
0
 @Test
 public void testApply() {
   DummyContainer dc = new DummyContainer();
   Parameters params = Parameters.getAllDefaultParameters();
   params.setParameterByKey(Parameters.KEY.COLUMN_DIMENSIONS, new int[] {2048});
   params.setParameterByKey(Parameters.KEY.POTENTIAL_PCT, 20.0);
   params.setParameterByKey(Parameters.KEY.CELLS_PER_COLUMN, null);
   params.apply(dc);
   assertTrue(Arrays.equals(new int[] {2048}, dc.getColumnDimensions()));
   assertEquals(20.0, dc.getPotentialPct(), 0);
 }
Ejemplo n.º 9
0
 /**
  * Copies the specified parameters into this {@code Parameters} object over writing the
  * intersecting keys and values.
  *
  * @param p the Parameters to perform a union with.
  * @return this Parameters object combined with the specified Parameters object.
  */
 public Parameters union(Parameters p) {
   for (KEY k : p.paramMap.keySet()) {
     setParameterByKey(k, p.getParameterByKey(k));
   }
   return this;
 }
Ejemplo n.º 10
0
 @Test
 public void testDefaultsAndUpdates() {
   Parameters params = Parameters.getAllDefaultParameters();
   assertEquals(params.getParameterByKey(Parameters.KEY.CELLS_PER_COLUMN), 32);
   assertEquals(params.getParameterByKey(Parameters.KEY.SEED), 42);
   assertEquals(
       true,
       ((Random) params.getParameterByKey(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.setParameterByKey(Parameters.KEY.INPUT_DIMENSIONS, new int[] {64, 64});
   parameters.setParameterByKey(Parameters.KEY.COLUMN_DIMENSIONS, new int[] {32, 32});
   parameters.setParameterByKey(Parameters.KEY.NUM_ACTIVE_COLUMNS_PER_INH_AREA, 0.02 * 64 * 64);
   System.out.println("Updated/Combined:\n" + parameters);
 }
Ejemplo n.º 11
0
  /**
   * Creates and returns a {@link Parameters} object configured for this demo.
   *
   * @return
   */
  org.numenta.nupic.Parameters createParameters() {
    org.numenta.nupic.Parameters tmParams =
        org.numenta.nupic.Parameters.getTemporalDefaultParameters();
    tmParams.setParameterByKey(KEY.COLUMN_DIMENSIONS, new int[] {16384});
    tmParams.setParameterByKey(KEY.INPUT_DIMENSIONS, new int[] {16384});
    tmParams.setParameterByKey(KEY.CELLS_PER_COLUMN, 8);
    tmParams.setParameterByKey(KEY.CONNECTED_PERMANENCE, 0.5);
    tmParams.setParameterByKey(KEY.INITIAL_PERMANENCE, 0.4);
    // tmParams.setParameterByKey(KEY.MIN_THRESHOLD, 164);
    // tmParams.setParameterByKey(KEY.MAX_NEW_SYNAPSE_COUNT, 164);
    // tmParams.setParameterByKey(KEY.ACTIVATION_THRESHOLD, 164);

    tmParams.setParameterByKey(KEY.MIN_THRESHOLD, 82);
    tmParams.setParameterByKey(KEY.MAX_NEW_SYNAPSE_COUNT, 82);
    tmParams.setParameterByKey(KEY.ACTIVATION_THRESHOLD, 82);

    tmParams.setParameterByKey(KEY.PERMANENCE_INCREMENT, 0.1);
    tmParams.setParameterByKey(KEY.PERMANENCE_DECREMENT, 0.01);

    tmParams.setParameterByKey(KEY.GLOBAL_INHIBITION, false);
    // tmParams.setParameterByKey(KEY.RADIUS, 4.0);
    tmParams.setParameterByKey(KEY.INHIBITION_RADIUS, 10);
    tmParams.setParameterByKey(KEY.POTENTIAL_RADIUS, 10);

    tmParams.setParameterByKey(KEY.SYN_PERM_CONNECTED, 0.1);
    tmParams.setParameterByKey(KEY.SYN_PERM_ACTIVE_INC, 0.9);
    tmParams.setParameterByKey(KEY.SYN_PERM_INACTIVE_DEC, 0.01);
    // tmParams.setParameterByKey(KEY., 1.0);
    tmParams.setParameterByKey(KEY.POTENTIAL_PCT, 1.0);
    tmParams.setParameterByKey(KEY.STIMULUS_THRESHOLD, 0.0);
    // tmParams.setParameterByKey(KEY.SP_ONE_TO_ONE, true);

    return tmParams;
  }
  /**
   * Creates and returns a {@link Parameters} object configured for this demo.
   *
   * @return
   */
  org.numenta.nupic.Parameters createParameters() {
    org.numenta.nupic.Parameters tmParams =
        org.numenta.nupic.Parameters.getTemporalDefaultParameters();
    tmParams.setParameterByKey(KEY.COLUMN_DIMENSIONS, new int[] {16384});
    tmParams.setParameterByKey(KEY.INPUT_DIMENSIONS, new int[] {16384});
    tmParams.setParameterByKey(KEY.CELLS_PER_COLUMN, 8);
    tmParams.setParameterByKey(KEY.CONNECTED_PERMANENCE, 0.5);
    tmParams.setParameterByKey(KEY.INITIAL_PERMANENCE, 0.4);
    tmParams.setParameterByKey(KEY.MIN_THRESHOLD, 164);
    tmParams.setParameterByKey(KEY.MAX_NEW_SYNAPSE_COUNT, 164);
    tmParams.setParameterByKey(KEY.PERMANENCE_INCREMENT, 0.1);
    tmParams.setParameterByKey(KEY.PERMANENCE_DECREMENT, 0.0);
    tmParams.setParameterByKey(KEY.ACTIVATION_THRESHOLD, 164);

    return tmParams;
  }