Пример #1
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);
  }
 @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);
 }
Пример #3
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);
 }
Пример #4
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;
    }
  }
Пример #5
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();
    }
  }
Пример #6
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;
 }