Configure an ML Model as a Perceptor

In this tutorial, we will walk through how to integrate a trained machine learning (ML) model into your AMESA agent system as a Perceptor. A perceptor allows your agent system to interpret data from sensors, process it using a machine learning model, and output new variables that will help the agent system make better decisions.

The goal is to publish a pre-trained ML model as a perceptor that adds a new layer of perception to your agent system, enabling it to process sensor data in a more advanced way. This could be useful in a variety of scenarios, such as predictive maintenance, anomaly detection, or autonomous decision-making.


Step 1: Understanding the Perceptor

A Perceptor in AMESA is a module in the perception layer that inputs sensor data, processes it (potentially using an ML model), and outputs new variables that are automatically added to the list of available sensors.

For this example, let’s assume we are building a perceptor that uses a trained machine learning model to predict thermal runaway in a system.


Step 2: Setting Up the Trained Model

We will use a pre-trained ML model stored as a pickle file to predict thermal runaway based on certain temperature and chemical sensor readings. Here’s how to set up the trained ML model for use as a perceptor.

  1. Store the ML Model: Assume the ML model has been trained and saved as a .pkl file. For this example, the model is stored in the path: ml_models/ml_predict_temperature.pkl.

  2. Load the ML Model in the Perceptor: In the perceptor class, we will load the model and define how it processes the sensor data.


Step 3: Creating the Perceptor

Now, we’ll create the perceptor using the trained ML model to process the sensor data and predict thermal runaway events. The perceptor will be responsible for calling the model and returning the prediction as a new sensor variable.

We can start by creating the preceptor by using the AMESAe CLI with the following command:

composable preceptor new

The new preceptor will have the following file structure:

3.1. Configuring your pyproject.toml file

3.2. Implementing the Perceptor in the perceptor.py file

Here’s the Python code to create the perceptor:

In this perceptor:

  • We load the trained machine learning model from a pickle file.

  • The compute() method takes in sensor data (e.g., temperature, chemical concentrations), processes it, and uses the ML model to predict whether a thermal runaway event will occur.

  • The perceptor outputs the prediction as a new sensor variable, thermal_runaway_predict.

3.2. Adding the Perceptor to Your Agent System

Once the perceptor is defined, you can login to the AMESA editor and add it to your agent system.


Conclusion

In this tutorial, we covered how to publish a trained ML model as a perceptor in AMESA. This allows the agent system to integrate more advanced decision-making by processing raw sensor data through a machine learning model and outputting predictions as new sensor variables. This method can be applied in various domains, such as predictive maintenance, anomaly detection, and control systems.

Last updated