Predictors#
The Predictor
uses a state estimate (type UncertainData
subclass, output of a StateEstimator
), information about expected future loading, and a PrognosticsModel
to predict both future states (also outputs, performance metrics, event_states) at predefined points and the time that an event will occur (Time of Event, ToE) with uncertainty.
Here’s an example of its use. In this example we use the ThrownObject
model and the MonteCarlo
predictor, and we save the state every 1s. We also use a scalar first state (i.e., no uncertainty).
>>> from progpy.models import ThrownObject
>>> from progpy.predictors import MonteCarlo
>>> from progpy.uncertain_data import ScalarData
>>>
>>> m = ThrownObject()
>>> pred = MonteCarlo(m)
>>> first_state = ScalarData({'x': 1.7, 'v': 20}) # Initial state for prediction
>>> def future_loading(t, x):
>>> return {} # ThrownObject doesn't have a way of loading it
>>>
>>> pred_results = pred.predict(first_state, future_loading, save_freq=1)
>>> pred_results.time_of_event.plot_hist(events='impact') # Plot a histogram of when the impact event occurred
See tutorial and examples for more information and additional features.
Included Predictors#
The following predictors are included with this package. A new predictor can be created by subclassing Predictor
. See also: predictor_template.py
- class progpy.predictors.MonteCarlo(model, **kwargs)#
Class for performing a monte-carlo model-based prediction.
A Predictor using the monte carlo algorithm. The provided initial states are simulated until either a specified time horizon is met, or the threshold for all simulated events is reached for all samples. A provided future loading equation is used to compute the inputs to the system at any given time point.
The following configuration parameters are supported (as kwargs in constructor or as parameters in predict method):
- n_samplesint, optional
Default number of samples to use. If not specified, a default value is used. If state is type UnweightedSamples and n_samples is not provided, the provided unweighted samples will be used directly.
- save_freqfloat, optional
Default frequency at which results are saved (s).
- class progpy.predictors.UnscentedTransformPredictor(model, **kwargs)#
Class for performing model-based prediction using an unscented transform.
This class defines logic for performing model-based state prediction using sigma points and an unscented transform. The Unscented Transform Predictor propagates the sigma-points in the state-space in time domain until the event threshold is met. The step at which the i-th sigma point reaches the threshold is the step at which the i-th sigma point will be placed along the time dimension. By repeating the procedure for all sigma-points, we obtain the sigma-points defining the distribution of the time of event (ToE); for example, the End Of Life (EOL) event. The provided future loading equation is used to compute the inputs to the system at any given time point.
The following configuration parameters are supported (as kwargs in constructor or as parameters in predict method):
- alpha, beta, kappa: float
UKF Scaling parameters. See: https://en.wikipedia.org/wiki/Kalman_filter#Unscented_Kalman_filter
- Q: np.array
Process noise covariance matrix [nStates x nStates]
- t0float
Initial time at which prediction begins, e.g., 0
- dtfloat
Simulation step size (s), e.g., 0.1
- eventslist[str]
Events to predict (subset of model.events) e.g., [‘event1’, ‘event2’]
- horizonfloat
Prediction horizon (s)
- save_freqfloat
Frequency at which results are saved (s)
- save_ptslist[float]
Any additional savepoints (s) e.g., [10.1, 22.5]
Note
The resulting sigma-points along the time dimension are used to compute mean and covariance of the event time (ToE), under the hypothesis that the ToE distribution would also be well represented by a Gaussian. This is a strong assumption that likely cannot be satisfied for real systems with strong non-linear state propagation or nonlinear ToE curves. Therefore, the user should be cautious and verify that modeling the event time using a Gaussian distribution is satisfactory.
Predictor Interface#
- class progpy.predictors.Predictor(model, **kwargs)#
Interface class for predictors
Abstract base class for creating predictors that perform prediction. Predictor subclasses must implement this interface. Equivilant to “Predictors” in NASA’s Matlab Prognostics Algorithm Library
- Parameters
model (PrognosticsModel) –
See:
progpy
packageA prognostics model to be used in prediction
kwargs (optional, keyword arguments) –
- abstract predict(state: progpy.uncertain_data.uncertain_data.UncertainData, future_loading_eqn: Callable, **kwargs) progpy.predictors.prediction.PredictionResults #
Perform a single prediction
- Parameters
state (UncertainData) – Distribution representing current state of the system
future_loading_eqn (function (t, x) -> z) – Function to generate an estimate of loading at future time t, and state x
(optional (options) –
kwargs) (configuration options) –
predictor (Any additional configuration values. Additional keyword arguments may be supported that are are specific to the) –
t0: Starting time (s)
dt : Step size (s)
horizon : Prediction horizon (s)
events : List of events to be predicted (subset of model.events, default is all events)
- event_strategy: str, optional
Strategy for stopping evaluation. Default is ‘first’. One of:
first: Will stop when first event in events list is reached.
all: Will stop when all events in events list have been reached
include (but) –
t0: Starting time (s)
dt : Step size (s)
horizon : Prediction horizon (s)
events : List of events to be predicted (subset of model.events, default is all events)
- event_strategy: str, optional
Strategy for stopping evaluation. Default is ‘first’. One of:
first: Will stop when first event in events list is reached.
all: Will stop when all events in events list have been reached
- Returns
result from prediction, including –
times (List[float]): Times for each savepoint such that inputs.snapshot(i), states.snapshot(i), outputs.snapshot(i), and event_states.snapshot(i) are all at times[i]
inputs (Prediction): Inputs at each savepoint such that inputs.snapshot(i) is the input distribution (type UncertainData) at times[i]
states (Prediction): States at each savepoint such that states.snapshot(i) is the state distribution (type UncertainData) at times[i]
outputs (Prediction): Outputs at each savepoint such that outputs.snapshot(i) is the output distribution (type UncertainData) at times[i]
event_states (Prediction): Event states at each savepoint such that event_states.snapshot(i) is the event state distribution (type UncertainData) at times[i]
time_of_event (UncertainData): Distribution of predicted Time of Event (ToE) for each predicted event, represented by some subclass of UncertaintData (e.g., MultivariateNormalDist)
- Return type
NameTuple