Get anomaly likelihood with multiple inputs

anomaly-detection
multiple-inputs

#1

Hi,
I successfully obtained anomaly likelihood from an input composed by timestamp + value using the following code:

 multiInput.put("timestamp", new DateTime(record.getTimestamp()));
 			multiInput.put("consumption", record.getxValue());

Inference inference = network.computeImmediate(multiInput);
System.out.println(inference.getAnomalyScore());

Now I would like to perform same thing using a “record” composed in this way: timestamp + value1 + value2 + value3.
I would like obtaining three anomaly likelihoods. How is this possible?

I used getSensorFieldEncodingMap function as (from the examples):

public static Map<String, Map<String, Object>> getSensorFieldEncodingMap() {
	        Map<String, Map<String, Object>> fieldEncodings = setupMap(
	                null,
	                0, // n
	                0, // w
	                0, 0, 0, 0, null, null, null,
	                "timestamp", "datetime", "DateEncoder"); 
	        fieldEncodings = setupMap(
	                fieldEncodings,
	                25,
	                3,
	                0, 0, 0, 0.1, null, null, null,
	                "consumption", "float", "RandomDistributedScalarEncoder");

	        fieldEncodings.get("timestamp").put(Parameters.KEY.DATEFIELD_DOFW.getFieldName(), new Tuple(1, 1.0)); // Day of week
	        fieldEncodings.get("timestamp").put(Parameters.KEY.DATEFIELD_TOFD.getFieldName(), new Tuple(5, 4.0)); // Time of day
	        fieldEncodings.get("timestamp").put(Parameters.KEY.DATEFIELD_PATTERN.getFieldName(), "MM/dd/YY HH:mm");

	        return fieldEncodings;
	    }

I don’t know how to set the code to perform triple anomaly detection.


#2

I modified my code adding other two inputs in my “multiInput map”:

multiInput.put("timestamp", new DateTime(record.getTimestamp()));
		multiInput.put("xValue", record.getxValue());
		multiInput.put("yValue", record.getyValue());
		multiInput.put("zValue", record.getzValue());

and editing getSensorFieldEncodingMap function as:

public static Map<String, Map<String, Object>> getSensorFieldEncodingMap() {
        Map<String, Map<String, Object>> fieldEncodings = setupMap(
                null,
                0, // n
                0, // w
                0, 0, 0, 0, null, null, null,
                "timestamp", "datetime", "DateEncoder"); 
        fieldEncodings = setupMap(
                fieldEncodings,
                25,
                3,
                0, 0, 0, 0.1, null, null, null,
                "xValue", "float", "RandomDistributedScalarEncoder");
        fieldEncodings = setupMap(
	                fieldEncodings,
	                25,
	                3,
	                0, 0, 0, 0.1, null, null, null,
	                "yValue", "float", "RandomDistributedScalarEncoder");
        fieldEncodings = setupMap(
	                fieldEncodings,
	                25,
	                3,
	                0, 0, 0, 0.1, null, null, null,
	                "zValue", "float", "RandomDistributedScalarEncoder");



        fieldEncodings.get("timestamp").put(Parameters.KEY.DATEFIELD_DOFW.getFieldName(), new Tuple(1, 1.0)); // Day of week
        fieldEncodings.get("timestamp").put(Parameters.KEY.DATEFIELD_TOFD.getFieldName(), new Tuple(5, 4.0)); // Time of day
        fieldEncodings.get("timestamp").put(Parameters.KEY.DATEFIELD_PATTERN.getFieldName(), "MM/dd/YY HH:mm");

        return fieldEncodings;
    }

but now, when I call getInference method, I don’t know how to separate anomaly scores on value basis.


#3

Hi @Andrea_Giordano,

I’m out with my family right now, but I just wanted to write you quickly to let you know that I’ve seen your message and that anomalies are discovered across the entire input not for each field in the input. I’ll write back in more detail later if there’s more to say…


#4

You mean if I have a file like this

timestamp, x, y, z
T, float, float, float
01/01/2018 00:00, 1, 1, 1
01/01/2018 00:00, 2, 1, 1
01/01/2018 00:00, 3, 1, 1
01/01/2018 00:00, 4, 1, 1

My anomaly detection would take x, y and z fields as the input and generate a score based on all three values?
I thout that I would have to write a custom encoder to this task…