How-To Guides
Analytics Guides

Use the Anomaly Detection Function

7min

The Anomaly Detection function applies the three-sigma rule to identify outliers by comparing data points against a dynamic threshold of standard deviations from the mean, allowing for real-time adjustment to emerging patterns.

This function operates by maintaining a rolling window of data, calculating the average and standard deviation within this window, and flagging values that deviate beyond the user-defined standard deviation range as anomalies.

Video



User Scenario

Review the following scenario for the anomaly detection processor function. Then, using an input processor, you will simulate PLC data and detect anomalies from the window of generated values.

In a large-scale manufacturing factory, the Anomaly Detection function is used to monitor the machine's temperatures. It calculates a moving average and standard deviation of temperature readings, flagging any readings that significantly deviate as potential cooling system failures. By defining the number of standard deviations from the average as the threshold for normal operation, factory engineers can quickly identify and respond to overheating risks, ensuring site reliability and uptime.

Step 1: Add a Device

Follow the steps to Connect a Device and configure the following parameters:

  • Device Type: Simulator
  • Driver Name: Generator
  • Enable Alias Topics: Select the checkbox.

Step 2: Add Tags

After connecting the device, add the following tag. See Add Tags to learn more.

Tag 1: input1

  • Name: Select S - Random value generator
  • Value Type: Select float64
  • Polling Interval: Enter 1
  • Tag Name: Enter input1
  • Min_value: Enter 1
  • Max_value: Enter 50

Step 3: Create Analytics Flow

You can now create the analytics flows using data from the device and tag you previously created.

To create an analytics flow with the Anomaly Detection Processor function:

  1. In Litmus Edge, navigate to Analytics.
  2. On the analytics canvas, click Add processor. The Create a processor dialog box displays.

    The Add processor option
    The Add processor option
    
  3. Select DataHub Subscribe.
  4. In the Topic field, click the Search icon, select the device you previously created, and then select the alias topic for the input1 tag.

    Create a Processor dialog box
    Create a Processor dialog box
    
  5. Click Save.
  6. Click Add processor again and select the Anomaly Detection processor. The following information defines this function:
    • Window Size: Enter a value that represents the range to observe before making each prediction. For this example, we input a value of 100.
    • Deviations: Enter the number of standard deviations that would be considered normal, making everything outside that definition anomalous data. For this example, we input a value of 3.
    • Topic Reset: Enable this option to reset the function on topic change.
    • Control Chart Mode: If this option is enabled, there will be no modifications done to the moving window before calculation.
    • Click Save.

      Edit a Processor dialog box
      Edit a Processor dialog box
      
  7. Connect the DataHub Subscribe processor (tag: input1) to the Anomaly Detection processor with a wire and use the events connection.
  8. On the analytics canvas, click Save. The configured analytics flows should look like the following:
Completed Flows Canvas
Completed Flows Canvas


Step 4: View Output of Processor

Click the View icon in the Anomaly Detection processor to view the output values.

The output describes a situation where the current value of 38.31 is well above the lower limit of -35.38 and below the upper limit of approximately 138.40, suggesting no anomaly is detected at this timestamp within the moving average of 51.51 and a standard deviation of 28.96.

Output of Anomaly Detection Function
Output of Anomaly Detection Function