Parameters

David Ray edited this page Jun 14, 2015 · 10 revisions

This page contains an in-depth discussion of Parameters.

Example of general usage:

Parameters p = Parameters.getAllDefaultParameters();
// Set a few of your desired parameters...
p.setParameterByKey(KEY.INPUT_DIMENSIONS, new int[] { 128, 128 });
p.setParameterByKey(KEY.COLUMN_DIMENSIONS, new int[] { 200 });
p.setParameterByKey(KEY.POTENTIAL_RADIUS, 3);
p.setParameterByKey(KEY.POTENTIAL_PCT, 0.5);

// To clear a parameter
p.clearParameter(KEY.POTENTIAL_PCT);

// To get an empty Parameters object
Parameters newCopy = Parameters.empty();

// To get a copy
Parameters copy = p.copy();

// To retrieve algorithm only parameters
Parameters spatial = Parameters.getSpatialDefaultParameters();
Parameters temporal = Parameters.getTemporalDefaultParameters();
Parameters encoder = Parameters.getEncoderDefaultParameters();

// To merge (union) one Parameters object into another
Parameters spatial = Parameters.getSpatialDefaultParameters();
Parameters temporal = Parameters.getTemporalDefaultParameters();
spatial.union(temporal); // Now contains only those params specific to the SP and TM

Configuring Encoder Parameters

Let's use the HotGym fields, "consumption" and "timestamp" as an example:

// This map contains keys which are field names or column names from csv files.
Map<String, Map<String, Object>> fieldEncodings = new HashMap<>();

Map<String, Object> inner = new HashMap<>();

// consumption
inner.put("n", 500);
inner.put("w", 21);
inner.put("minVal", 0.0); // Only needed for ScalarEncoder - otherwise can be left empty
inner.put("maxVal", 0.0); // S.A.A for ScalarEncoder
inner.put("radius", 0.0);
inner.put("resolution", 0.0);
inner.put("periodic", false);
inner.put("clipInput", false);
inner.put("forced", false); // Used to force a non-standard ratio of "n" and "w" values.
inner.put("fieldName", "consumption"); // We'll use "consumption" here
inner.put("fieldType", "float"); // others are "string","datetime","int","float","bool","list"
inner.put("encoderType", "RandomDistributedScalarEncoder"); // Use the class name of the encoder.

fieldEncodings.put("consumption", inner);

// Timestamp
inner = new HashMap<>();
inner.put("n", 0);
inner.put("w", 0);
inner.put("minVal", 0.0);
inner.put("maxVal", 0.0);
inner.put("radius", 0.0);
inner.put("resolution", 0.0);
inner.put("periodic", false);
inner.put("clipInput", false);
inner.put("forced", false); 
inner.put("fieldName", "timestamp");
inner.put("fieldType", "datetime");
inner.put("encoderType", "DateEncoder");
inner.put(KEY.DATEFIELD_TOFD.getFieldName(), new Tuple(21,9.5)); // Time of day
inner.put(KEY.DATEFIELD_PATTERN.getFieldName(), "MM/dd/YY HH:mm"); // Date Pattern to be expected

fieldEncodings.put("timestamp", inner);

// Finally add the encoding map to the Parameters
p.setParameterByKey(KEY.FIELD_ENCODING_MAP, fieldEncodings);

Note: There are other fields (other then TOFD [time of day]) within a DateEncoder which may be individually configured for encoding. For others please see the DateEncoder javadoc, and the Parameters.KEYS. The DateEncoder Parameters keys are (for convenience):

KEY.DATEFIELD_CUSTOM 
KEY.DATEFIELD_DOFW 
KEY.DATEFIELD_FORMATTER 
KEY.DATEFIELD_HOLIDAY 
KEY.DATEFIELD_PATTERN 
KEY.DATEFIELD_SEASON 
KEY.DATEFIELD_TOFD 
KEY.DATEFIELD_WKEND 
KEY.DUTY_CYCLE_PERIOD 

The line: inner.put(KEY.DATEFIELD_TOFD.getFieldName(), new Tuple(21,9.5)); // Time of day

Has an Tuple argument, which is a pair of settings, the first being the number of bits to use for the representation ("0" turns it off). And the second is the "radius" or duration in the parameter's units (for TOFD "time of day", the default radius is 4 (four hours)).

Anomaly Parameters

If you should need to customize an Anomaly computer's settings, it can be done like this:

Map<String, Object> params = new HashMap<>();
params.put(KEY_MODE, Mode.PURE);
params.put(KEY_WINDOW_SIZE, 3);
params.put(KEY_USE_MOVING_AVG, true);
Anomaly customAnomaly = Anomaly.create(params);

// Then insert into network:
Network.create("Network API Demo", p)
    .add(Network.createRegion("Region 1")
        .add(Network.createLayer("Layer 2/3", p)
            .add(customAnomaly)));
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.