ToEPredictionProfile#

class progpy.predictors.ToEPredictionProfile(dict=None, /, **kwargs)#

Data structure for storing the result of multiple predictions, including time of prediction. This data structure can be treated as a dictionary of time of prediction to Time of Event (ToE) prediction. Iteration of this data structure is in order of increasing time of prediction

add_prediction(time_of_prediction: float, toe_prediction: progpy.uncertain_data.uncertain_data.UncertainData)#

Add a single prediction to the profile

Parameters
  • time_of_prediction (float) – Time that the prediction was made

  • toe_prediction (UncertainData) – Distribution of predicted ToEs

alpha_lambda(ground_truth: Dict[str, float], lambda_value: float, alpha: float, beta: float, **kwargs) Dict[str, bool]#

Calculate Alpha lambda metric for the prediction profile

Parameters
  • ground_truth (dict[str, float]) – Ground Truth time of event for each event (e.g., {‘event1’: 748, ‘event2’, 2233, …})

  • lambda_value (float) – Prediction time at or after which metric is evaluated. Evaluation occurs at this time (if a prediction exists) or the next prediction following.

  • alpha (float) – percentage bounds around time to event (where 0.2 allows 20% error TtE)

  • beta (float) – portion of prediction that must be within those bounds

Keyword Arguments
  • keys (list[str], optional) – list of keys to use. If not provided, all keys are used.

  • print (bool, optional) – If True, print the results to the screen. Default is False.

Returns

If alpha lambda was met for each key (e.g., {‘event1’: True, ‘event2’, False, …})

Return type

dict[str, bool]

clear() None.  Remove all items from D.#
cumulative_relative_accuracy(ground_truth, **kwargs) Dict[str, float]#

Compute cumulative relative accuracy for a given profile, defined as the normalized sum of relative prediction accuracies at specific time instances.

\(CRA = \Sigma \left( \dfrac{RA}{N} \right)\) for each event

Where \(\Sigma\) is summation of all relative accuracies for a given profile and N is the total count of profiles 0

Parameters

ground_truth (dict) – Dictionary containing ground truth; specified as key, value pairs for event and its value. E.g, {‘event1’: 47.3, ‘event2’: 52.1, ‘event3’: 46.1}

Returns

Dictionary containing cumulative relative accuracy (value) for each event (key). e.g., {‘event1’: 12.3, ‘event2’: 15.1}

Return type

dict

References

0(1,2)

Journal Prognostics Health Management, Saxena et al.

get(k[, d]) D[k] if k in D, else d.  d defaults to None.#
items()#

Get iterators for the items (time_of_prediction, toe_prediction) of the prediction profile

keys()#

Get iterator for the keys (i.e., time_of_prediction) of the prediction profile

monotonicity(**kwargs) Dict[str, float]#

Calculate monotonicty for a prediction profile. Given a prediction profile, for each prediction: go through all predicted states and compare those to the next one. Calculates monotonicity for each prediction key using its associated mean value in progpy.uncertain_data.UncertainData.

\(monotonoicity = \|\Sigma \left( \dfrac{sign(i+1 - i)}{N-1} \right) \|\)

Where N is number of measurements and sign indicates sign of calculation. 0 1

Parameters

toe_profile (ToEPredictionProfile) – A profile of predictions, the combination of multiple predictions

Returns

Dictionary where keys represent a profile and dict is a subdictionary representing an event and its respective monotonicitiy value between [0, 1].

Return type

dict (str, dict)

References

1

Coble, J., et. al. (2021). Identifying Optimal Prognostic Parameters from Data: A Genetic Algorithms Approach. Annual Conference of the PHM Society. http://www.papers.phmsociety.org/index.php/phmconf/article/view/1404

2

Baptistia, M., et. al. (2022). Relation between prognostics predictor evaluation metrics and local interpretability SHAP values. Aritifical Intelligence, Volume 306. https://www.sciencedirect.com/science/article/pii/S0004370222000078

plot(ground_truth: dict = None, alpha: float = None, show: bool = True) dict#

Produce an alpha-beta plot depicting the TtE distribution by time of prediction for each event.

Parameters
  • ground_truth (dict) – Optional dictionary argument containing event and its respective ground truth value; none by default and plotted if specified

  • alpha (float) – Optional alpha value; none by default and plotted if specified

  • show (bool) – Optional bool value; specify whether to display generated plots. Default is true

Returns

Collection of generated matplotlib figures for each event in profile

e.g., {‘event1’: Fig, ‘event2’: Fig}

Return type

dict[str, Figure]

Example

gt = {'event1': 3442, 'event2': 175} # Ground Truth
figs = profile.plot(gt) # Figure with ground truth line
figs = profile.plot(gt, alpha = 0.2) # Figure with ground truth line and 20% alpha bounds
figs = profile.plot(gt, alpha = 0.2, show=False) # Dont display figure
pop(k[, d]) v, remove specified key and return the corresponding value.#

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() (k, v), remove and return some (key, value) pair#

as a 2-tuple; but raise KeyError if D is empty.

prognostic_horizon(criteria_eqn, ground_truth, **kwargs) Dict[str, float]#

Compute prognostic horizon metric, defined as the difference between a time ti, when the predictions meet specified performance criteria, and the time corresponding to the true Time of Event (ToE), for each event.

\(PH = ToE - ti\)

Parameters
  • toe_profile (ToEPredictionProfile) – A profile of predictions, the combination of multiple predictions

  • criteria_eqn (Callable function) –

    A function (toe: UncertainData, ground_truth: dict[str, float]) -> dict[str, bool] calculating whether a prediction in ToEPredictionProfile meets some criteria.

    Args:
    * toe (UncertainData): A single prediction of Time of Event (ToE)
    * ground truth (dict[str, float]): Ground truth passed into prognostics_horizon
    Returns: Map of event names to boolean representing if the event has been met.
    e.g., {‘event1’: True, ‘event2’: False}

  • ground_truth (dict) – Dictionary containing ground truth; specified as key, value pairs for event and its value. E.g, {‘event1’: 47.3, ‘event2’: 52.1, ‘event3’: 46.1}

Keyword Arguments

print (bool) – Boolean specifying whether the prognostic horizon metric should be printed.

Returns

Dictionary containing prognostic horizon calculations (value) for each event (key). e.g., {‘event1’: 12.3, ‘event2’: 15.1}

Return type

dict

update([E, ]**F) None.  Update D from mapping/iterable E and F.#

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values()#

Get iterator for the values (i.e., toe_prediction) of the prediction profile