Model Samples

To help you get started developing real-time digital twin models with the ScaleOut Model Development Tool, this topic describes two sample models: a machine learning model and a rules-based model.

Machine Learning Model Sample

This sample shows how you can create a very simple yet powerful model without any code, rules, or even instance properties. The real-time digital twin model tracks telemetry from a hypothetical wind turbine and monitors three parameters: temperature, RPM (rotational speed) and friction. The model uses machine learning (ML) to detect spikes in temperature and anomalies in the combination of the three parameters.

The first step is to set the name of the model, which will be called WindTurbine:

sample01

The next step is to create the three expected message properties, which are named Temperature, RPM, and Friction in JSON-formatted messages from the data source:

sample02

To enable spike detection for the Temperature property, click on the property in the tree and click Configure in the Configure automatic spike and trend change detection section.

sample03

This displays the dialog for configuring spike and trend change detection. This model will use the default value for the number of historical data points that each real-time digital twin instance will keep. To configure spike detection and automatically send alerts to a previously configured Slack webhook named Slack, check the box Send alerts and select Slack as the alert provider. This model will set the severity level used by Slack as “Critical” to control how alerts will be reported:

sample04

After saving the configuration by clicking on Update model, the property view now shows that spike detection is configured to send alerts to the Slack alert provider:

sample05

Once the model has been deployed to ScaleOut Digital Twins™, each real-time digital twin instance will use ML and saved historical data to evaluate the Temperature property for spikes whenever a message is received from its data source.

The next step is to configure ML-based anomaly detection for all three message properties. This will help each real-time digital twin instance detect anomalous behavior in its wind turbine that could indicate an impending failure.

The first step is to create a data collection called Telemetry to group the three message properties:

sample06

Next, click on Configure in the Configure automatic anomaly detection section of the data collection’s dialog. This will start the configuration wizard. In the first step of the wizard, upload training data for the ML algorithms in the form of a CSV file (comma-separated values). This file contains historical data that indicates combinations of the three properties that are known to be either normal or anomalous. Here is an example of a training set:

anomaly07

By adding a header row to the CSV file, as shown in the above example, and checking the My file has headers check box in the configuration wizard, the ScaleOut Model Development Tool can automatically map the file’s data to the appropriate properties. The configuration wizard provides a preview of the first then rows in the file with the associated property names:

anomaly08

Note

Be sure to verify that the columns shown in the preview align with the actual data in the file to avoid improperly training the ML algorithm.

Once all column assignments have been verified, click Next to go to the next step in the configuration wizard. (This button is used in each step of the wizard to advance to the next step.)

The ScaleOut Model Development Tool includes ten binary classification ML algorithms from Microsoft’s Machine Learning library, ML.NET. One or more of these algorithms can be selected for training and evaluation. The following screenshot shows that all ten algorithms have been selected and that the default maximum allowed training time will be used:

anomaly04

After training completes, the next dialog in the configuration wizard displays a table with the metrics for all selected algorithms. In this dialog, select one ML algorithm for deployment based on the combination of metrics that represent the best fit for the application:

anomaly05

Note

Refer to the topic Machine Learning Metrics for more information on what the metrics mean.

The last step in the configuration wizard configures the actions to take when the trained ML algorithm detects an anomaly in the group of properties. By default, anomaly detection occurs whenever a new message is received by an instance, but the minimum interval of time between checks can be set using the slider control in the dialog.

The model can be configured to post events to an event list when an anomaly is detected. If this option is enabled, an event list is automatically created with the name Anomaly- followed by the data collection’s name. In this case, the model will be configured just to send alerts to the Slack alert provider in the same manner as was done for spike detection:

anomaly06

This completes the configuration of ML-based anomaly detection, and it fully defines the real-time digital twin model. Although no rules and no instance properties were needed, the model could be expanded to enhance its analysis by incorporating instance properties and rules, as illustrated in the next sample.

Rules-Based Model Sample

This sample rules-based model tracks temperature readings from a thermometer and updates a status property that indicates whether the temperature is acceptable, hot, or cold. After setting the name of the model to “Thermometer”, define two instance properties in the ScaleOut Model Development Tool:

  • Temp: tracks the current temperature of the thermometer using type Number with an initial value of 50

  • Status: tracks the current status using type String with inital value “Normal”

Note that clicking on Instance Properties in the tree view on the left presents a summary of the instance properties and shows their initial values:

PropertiesSummary

The next step is to create the message properties. Since the thermometer sends its real-time digital twin JSON-formatted messages with a single property called NewTemp to report the current temperature, create this property under Incoming message properties in the tree view:

MessageProperties

The last step is to define the rules that execute whenever a real-time digital twin instance receives a message from the thermometer. To keep track of the latest temperature, create a rule that assigns the incoming temperature to the instance property Temp:

AssignRule

Additional rules determine the thermometer’s status according to the following ranges:

  • Normal: temperatures between 50F and 100F

  • Hot: temperatures above 100F

  • Cold: temperatures below 50F

Tracking the status of these ranges requires three rules, one for each range of temperatures. The first rule sets the status for temperatures in the normal range:

NormalTemp

Two additional rules set the status for the other ranges. The Rules Summary shows all of the rules and can be viewed by selecting Rules in the tree view:

RuleSummary

This completes the sample model, which can now be tested by clicking on the Test model tab in the tool. Sending simulated messages to the model will validate that the rules execute properly and that they update the instance properties as expected.

Saving the real-time digital twin model prior to deployment creates a JSON-formatted text file of the model’s definition. The final definition should look like this:

{
     "ModelName": "Thermometer",
     "LanguageVersion": "2",
     "InstanceProperties": [
         {
         "Name": "Id",
         "Type": 2,
         "InitialValue": null
         },
         {
         "Name": "Model",
         "Type": 2,
         "InitialValue": "Thermometer"
         },
         {
         "Name": "Temp",
         "Type": 1,
         "InitialValue": 50
         },
         {
         "Name": "Status",
         "Type": 2,
         "InitialValue": "Normal range"
         }
     ],
     "MessageProperties": {
         "Incoming": [
         {
             "Name": "NewTemp",
             "Type": 1,
             "InitialValue": null
         }
         ]
     },
     "Rules": [
         {
         "Name": "Assign Temperature",
         "Text": "DO Temp = Incoming.NewTemp"
         },
         {
         "Name": "Running Hot",
         "Text": "IF Temp > 100 THEN Status = \"Running hot\""
         },
         {
         "Name": "Running cold",
         "Text": "IF Temp < 50 THEN Status = \"Running cold\""
         },
         {
         "Name": "Normal temperature",
         "Text": "IF (Temp >= 50 AND Temp <=100) THEN Status = \"Normal range\""
         }
     ],
     "EventListDefinitions": [],
     "AlertProviders": [],
     "DataCollectionDefinitions": [],
     "PropertyAnomalyDetectionDefinitions": [],
     "DataCollectionAnomalyDetectionDefinitions": []
 }

To deploy the model to the ScaleOut Digital Twins service, create a zip file from the File menu. This zip file will include the JSON model definition and any other dependencies, such as ML algorithm libraries, required for deployment.