Defining a Digital Twin Model
Define the properties of the model and specify the ones the algorithm should train on. The ScaleOut Machine Learning Training Tool will extract the properties from an existing model and match them with the training data.
Note
Only numerical properties stored as Single (or float) are supported by the ML.NET libraries.
In this tutorial, we will define a digital twin model named SensorsRTModel containing three Single properties representing the properties the model is tracking (temperature, friction, and RPM) and a String property representing the status of the mechanical parts.
Start by creating a Digital Twin solution by using the solution template provided by ScaleOut Software (for details, refer to Creating a Digital Twins Solution)
dotnet new dt-sln -n Sensors
This command creates a solution with a Messages project. In the solution’s Messages project, rename the ExampleMessage class to SensorsMessage and add three Single properties representing the sensor data: temperature, friction, and RPM.
public class SensorsMessage : DigitalTwinMessage
{
public Single Temperature { get; set; }
public Single Friction { get; set; }
public Single RPM { get; set; }
/// <summary>
/// Overridden property used by JsonSubtypes during deserialization.
/// </summary>
public override string MessageType => nameof(SensorsMessage);
}
In Visual Studio 2022, add a new project to your solution and look for the ScaleOut Real-Time Model template:
This will create a new project with your bare-bones digital model class and a message processor.
In the model, define the 4 properties we mentioned earlier.
public class SensorsRTModel : DigitalTwinBase
{
public Single Temperature { get; set; }
public Single Friction { get; set; }
public Single RPM { get; set; }
public String Status { get; set; }
}
In the template-generated MessageProcessor class, assign the properties from the incoming message to the digital twin instance.
public override ProcessingResult ProcessMessages(ProcessingContext context, SensorsRTModel digitalTwin, IEnumerable<DigitalTwinMessage> newMessages)
{
// assign the state variables
// Process incoming messages
foreach (var message in newMessages)
{
switch (message)
{
case SensorsMessage newReading:
// Assign new values
digitalTwin.Temperature = newReading.Temperature;
digitalTwin.RPM = newReading.RPM;
digitalTwin.Friction = newReading.Friction;
break;
default:
throw new NotImplementedException($"Message processor does not support message type {message.GetType()}");
}
}
}
Compile the digital twin model.
To deploy your model, you will need to publish it to a zip file. Right-click on the model project and select Publish.
Then in the list of choices, select the one that matches the platform you will be using the model on (Windows/Linux)