energy_fault_detector.threshold_selectors.adaptive_threshold
- class AdaptiveThresholdSelector(gamma=0.2, nn_size=10, nn_epochs=300, nn_learning_rate=0.001, nn_batch_size=128, smoothing_parameter=1, early_stopping=True, patience=3, validation_split=0.25, verbose=0)
Bases:
ThresholdSelectorAdaptive threshold calculation based on NN regression and mutual information.
- Parameters:
gamma (float) – Determines the sensitivity; added to the SVR model output (the expected anomaly score).
nn_size (int) – NN hyperparameter determining the size of the hidden layer of the NN.
nn_epochs (int) – NN hyperparameter for the number of epochs during training.
nn_learning_rate (float) – NN hyperparameter for the learning rate of the optimizer during training.
nn_batch_size (int) – Number of samples per gradient update.
smoothing_parameter (int) – Parameter for score smoothing; determines the length of segments in the smoothing function. A value of 1 practically disables smoothing (default is 1).
early_stopping (bool) – If True, the early stopping callback will be used in the fit method.
patience (int) – Parameter for early stopping. If early stopping is used, training will end if more than patience epochs in a row have not shown an improved loss. (default is 3)
verbose (int) – Determines the amount of console output during training: 0=silent, 1=progress bar, 2=one line per epoch.
Configuration example:
train: threshold_selector: name: AdaptiveThresholdSelector params: gamma: 0.2 nn_size: 10 nn_epochs: 100 nn_learning_rate: 0.001 nn_batch_size: 128 smoothing_parameter: 3 early_stopping: True patience: 3 verbose: 0- fit(scaled_ae_input, anomaly_score, normal_index=None)
Trains an NN model with the autoencoder input as input and the corresponding anomaly_score as targets.
- Parameters:
scaled_ae_input (DataType) – Standardized sensor data (autoencoder input).
anomaly_score (Array1D) – Anomaly scores based on deviations of the autoencoder.
normal_index (pd.Series, optional) – Labels indicating whether each sample is normal (True) or anomalous (False). Optional; if not provided, assumes all data represents normal behavior.
- Returns:
The instance of this class after fitting the model.
- Return type:
- predict(x, scaled_ae_input)
Predicts the status (normal or anomalous) of each sample based on the trained NN model.
- Parameters:
x (Array1D) – Anomaly scores based on deviations of the autoencoder.
scaled_ae_input (DataType) – Standardized sensor data (autoencoder input).
- Returns:
- A tuple containing a boolean array indicating the predicted status of each
sample and the corresponding adaptive thresholds.
- Return type:
Tuple[np.ndarray, np.ndarray]
- class RegressionNN(size, learning_rate, batch_size, early_stopping, patience, validation_split)
Bases:
objectSimple neural network (NN) with one hidden layer of shape (input_dim, size) used for regression. It uses ReLU-activation and the Adam Optimizer
- Parameters:
Args
size (int) – Hyperparameter determining the size of the hidden layer of the NN.
learning_rate (float) – Hyperparameter for the learning rate of the optimizer during training.
batch_size (int) – Number of samples per gradient update.
early_stopping (bool) – If True, the early stopping callback will be used in the fit method. Early stopping will interrupt the training procedure before the last epoch is reached if the loss is not improving. The exact time of the interruption is based on the patience parameter.
patience (int) – Parameter for early stopping. If early stopping is used, the training will end if more than patience epochs in a row have not shown an improved loss.
validation_split (float) – Fraction of the training data to be used as validation data (between 0 and 1).
- create_model(input_dimension)
“Creates a keras model of a dense autoencoder with one hidden layer.
- Return type:
- fit(x, y, epochs, verbose=0)
Fits the neural network model to the training data.
- predict(x, verbose=0)
Predicts outcomes based on input data using the trained neural network model.
- Parameters:
x (np.array) – Input data for predictions.
verbose (
int) – determines the amount of console output of the NN training: 0=silent, 1=progess bar, 2=one line per epoch
- Returns:
Predicted values from the neural network.
- Return type:
np.ndarray