results module

Results module.

This module is intended to provide a set of functions for computing the Remaining Useful Lifetime (RUL) given the estimated Health Index, and an overview of the errors performances.

results.compute_results(true: ndarray, pred: ndarray, time: ndarray, adapt_length: float = None, method: str = 'lr', verbose: bool = False) dict

compute_results.

This function computes the results of a HI prediction and plots the true and predicted values. The function takes the true and predicted HI values and the time values as numpy arrays. The function also takes an optional adapt_length parameter in case of a test experiment, which is the length of the test experiment until it is interrupted.

Two methods are available for forecasting the HI values: a linear fit and by using a non-linear Prophet model.

In case of a test experiment (i.e., adapt_length is not None),the function then computes the remaining useful life (RUL) of the bearing based on the adapt_length and the method. The function uses the forecast_hi_lr or the forecast_hi_prophet functions to forecast the HI values and find the zero point of the HI. The function also handles the cases when the forecast does not converge to zero or converges too early, by setting the RUL to 0. The RUL is computed by checking the distance between adapt_length and the time instant in which the forecasted HI reaches zero.

The function then computes the error and the score of the prediction using the compute_score function. The function also provides a set of figures to visualize the results.

Parameters:
  • true (np.ndarray) – array of the true HI values

  • pred (np.ndarray) – array of the predicted HI values

  • time (np.ndarray) – array of the time values

  • adapt_length (float) – length of the test experiment. Default is None

  • method (str) – forecasting method to use for the HI prediction. Possible values are: * ‘lr’: for linear fit forcing pass from (0,1) * ‘prophet’: Facebook Prophet model. Default is ‘lr’

  • verbose (bool) – True to print messages. Default is False

Return type:

dict

Returns:

results, which includes the figure object, the time, the true and predicted HI values, the real and predicted RUL, the error and the score.

results.compute_score(real: float, pred: float) -> (<class 'float'>, <class 'float'>)

compute_score.

This function computes the error and the score of a RUL prediction. The function takes the real and the predicted RUL values as floats and calculates the error as the percentage difference between them. The function then calculates the score as an exponential function of the error, with different coefficients depending on whether the error is positive or negative. The function returns the error and the score as a tuple of floats.

Parameters:
  • real (float) – real RUL value

  • pred (float) – predicted RUL value

Return type:

(float, float)

Returns:

error and score

results.forecast_hi_lr(time: ndarray, pred: ndarray) DataFrame

forecast_hi_lr.

This function forecasts the health index (HI) of a bearing using the linear regression model. The function takes the time and the HI values as numpy arrays and filters out any missing values. The function then creates the input and output variables for the linear regression model, where the input is the time and the output is 1-HI. The function then creates and fits a linear regression model without an intercept, in order to force the curve to pass through the point (0, 0). The function then calculates the zero point of the model, which is the time when the HI reaches zero. The function then creates a new time array from zero to the zero point with a step of 10 samples, and predicts the HI values for the new time array. The function returns a data frame of the predictions, with columns ds and yhat.

Parameters:
  • time (np.ndarray) – array of the time values

  • pred (np.ndarray) – array of the HI values

Return type:

pd.DataFrame

Returns:

dataframe of the HI predictions, with columns ds and yhat

results.forecast_hi_prophet(time: ndarray, pred: ndarray) DataFrame

forecast_hi_prophet.

This function forecasts the health index (HI) of a bearing using the Facebook Prophet model. The function takes the time and the HI values as numpy arrays and creates a data frame required by Prophet with two columns: ds and y. The ds column contains the datetime values converted from the time array, and the y column contains the HI values. The function then creates a Prophet model with a specified changepoint_prior_scale parameter, which controls the flexibility of the model to fit the data. The function fits the model to the data frame, dropping any missing values. The function then makes a future data frame with 3000 additional samples, and predicts the HI values for the future data frame. The function returns a data frame of the predictions, with the ds column converted back to seconds.

Parameters:
  • time (np.ndarray) – array of the time values

  • pred (np.ndarray) – array of the HI values

Return type:

pd.DataFrame

Returns:

data frame of the HI predictions, with columns ds and yhat