You can share a MATLAB® function with one colleague by simply emailing it, but that approach does not scale well to larger groups. For example, you can’t ensure that everyone is using the latest version of your function and you can’t restrict access to proprietary code. And if you install the function on enough machines to accommodate peak usage, you’re left with idle machines during slower periods. Architects of enterprise-scale application deployment projects address these problems by adopting a client-server software development model.
MATLAB Client for MATLAB Production Server™ brings the benefits of client-server computing to the MATLAB desktop. A central location for algorithms ensures that all clients are using the same version. Remote execution and encryption protect intellectual property (IP): end users can invoke the algorithms but cannot access the source code. To increase capacity, you can add on-premises workers or deploy MATLAB Production Server instances in cloud computing environments such as Microsoft® Azure™ and Amazon Web Services.
This article demonstrates these capabilities with a predictive maintenance application that estimates the health of an electric motor.
The Application: Estimating Motor Health with Predictive Maintenance
Predictive maintenance systems monitor equipment health to prevent unexpected failures. For example, they estimate a motor’s remaining useful life (RUL) to indicate when that motor should be replaced and detect anomalies in behavior to identify motors needing inspection.
Our application sends time-series data collected from motor sensors to predictive maintenance algorithms that use machine learning to estimate RUL and scan for anomalous behavior (Figure 1).
The application consists of two parts: a MATLAB Motor Health app that displays the status of a given motor and a MATLAB Production Server predictive maintenance analytics application containing the two predictive maintenance algorithms. This client-server architecture separates functional responsibilities: the client app manages data access and display, while the server algorithms analyze the data. The client depends on the application programming interface (API) provided by the server but neither needs, nor has access to, the implementation.
The Server: Algorithms and Interface
Each algorithm applies a different machine learning technique to the time-series data produced by each motor sensor. The RUL algorithm estimates time to failure using a linear regression model and the
predict function from Predictive Maintenance Toolbox™. The anomaly detection algorithm classifies sensor events as normal or anomalous using a custom one-class support vector machine (SVM) and a linear solver from Statistics and Machine Learning Toolbox™. Both algorithms use incremental learning to update their models continuously, accommodating drift in the sensor data caused by wear-related motor degradation. As a result, neither model needs to be trained before deployment.
Since the end user applies both algorithms to the same data stream, the server provides one entry point,
processMotorData. For each element in the time-series data,
processMotorData returns an RUL estimate and a flag indicating whether an anomaly occurred.
function [rul, anomaly] = processMotorData(data, initialize) c = mps.cache.connect('MotorData','Connection','LocalRedis'); if initialize c.AnomalyModel = initAnomalyData(); c.RULModel = initMotorRULData(); end [anomaly, c.AnomalyModel] = detectAnomaly(data, c.AnomalyModel); [rul, c.RULModel] = remainingMotorLife(data, c.RULModel); end
A client typically calls
processMotorData multiple times while processing a stream of data, breaking the stream into time-ordered windows and sending each window as it becomes available. MATLAB Production Server has a stateless architecture: it resets the execution state after each call to prevent data leaking between clients. Since the algorithms use incremental learning, they improve by updating their models after processing each window. But execution state resets will erase these changes from MATLAB Production Server memory. To preserve changes for the next call, we save them in an external data cache created by
mps.cache.connect. The deployed algorithm breaks the stream into groups based on motor ID and maintains a data cache and machine learning model for each motor.
The Client: Accessing Algorithms and Visualizing Data
processMotorData available to client developers by deploying it to an instance of MATLAB Production Server in an archive named
MotorAnalytics. To call
processMotorData from MATLAB, you install a MATLAB add-on from
MotorAnalytics, using MATLAB Client for MATLAB Production Server.
Installing the add-on places a
processMotorData function on the MATLAB path. Calling
processMotorData sends a request to the MATLAB Production Server hosted
processMotorData, which implements the predictive maintenance algorithms. Each client that installs the add-on accesses the same predictive maintenance algorithms, as shown in Figure 2.
With the add-on installed, the end user can interact with the
processMotorData function from the MATLAB desktop. The MATLAB
help command, for example, displays the help text from the original function and a postscript indicating that
processMotorData is running on MATLAB Production Server.
>> help processMotorData processMotorData Compute remaining useful life for a given motor, and scan the motor data for anomalies. [rul, anomaly] = processMotorData(data, initState) feeds DATA into motor-specific machine learning models and returns the remaining useful life (RUL) and any anomalies detected (ANOMALY). Function hosted by MATLAB Production Server. Server Host: localhost Server Port: 9910
That’s all the human-readable content in the add-on. Any IP in
processMotorData is secured by AES encryption on the MATLAB Production Server host machine.
We created a two-panel MATLAB app with MATLAB App Designer that lets you select a motor data set and view the results of passing that data through the predictive maintenance algorithms. The motor data set consists of 48 hours of sensor readings sampled once every minute. The RUL of the motor during that 48-hour period appears as a line graph of estimated minutes before failure. Anomalies appear as red dots on the line graph at the time they were detected.
Figure 3 displays the condition of motor number 8. The plot indicates several anomalies and a temporary reduction in estimated RUL before plunging to zero. The rapid rate of decline—from 72 hours to zero in roughly 12 hours—indicates the urgency of replacing the motor.
Algorithms deployed to MATLAB Production Server scale: MATLAB Production Server automatically adds capacity (within limits) in response to increased demand. A single instance of MATLAB Production Server may have up to 24 workers. Workers process requests independently—and simultaneously, if the host machine has enough CPU resources. We recommend one core per worker.
To demonstrate demand-driven scaling, we started the predictive analytics app from three separate MATLAB desktop sessions. We ran one copy of the app, waited for it to complete, and then ran all three simultaneously.
Figure 4 captures the results. Each copy of the app shown on the left graphs the analytic results. The MATLAB Production Server dashboard, shown on the right, displays the number of active worker processes and the request throughput. At the instant captured, the dashboard shows three active worker processes and a throughput of roughly 18 messages per second.
The bar graph in the dashboard displays throughput history. Each group of bars represents a period of activity. The shorter bar captures the period when only one app sent requests to MATLAB Production Server and displays a throughput of about six requests a second. The taller bars capture the period when three desktop apps sent requests. During this second period, MATLAB Production Server automatically activated two additional workers, scaling with demand and raising throughput to 18 messages a second.
Centralize, Protect, and Scale
Installed at one location on the network, protected by AES encryption, and dynamically scalable,
processMotorData is now an enterprise-level service. You can create deployable archives like
MotorAnalytics by using MATLAB Compiler SDK™ and MATLAB Production Server. To install and use functions like
processMotorData, however, all you need is MATLAB and the freely downloadable MATLAB Client for MATLAB Production Server support package.