probability_weighted_ae
¶
Classes:
Name | Description |
---|---|
ProbabilityWeightedAutoencoder |
Wrapper for PyTorch autoencoder models for anomaly detection that |
ProbabilityWeightedAutoencoderInitialized |
|
ProbabilityWeightedAutoencoder
¶
ProbabilityWeightedAutoencoder(
module: Type[Module],
loss_fn: Union[str, Callable] = "mse",
optimizer_fn: Union[str, Callable] = "sgd",
lr: float = 0.001,
device: str = "cpu",
seed: int = 42,
skip_threshold: float = 0.9,
window_size=250,
**kwargs
)
Bases: Autoencoder
Wrapper for PyTorch autoencoder models for anomaly detection that
reduces the employed learning rate based on an outlier probability
estimate of the input example as well as a threshold probability
skip_threshold
. If the outlier probability is above the threshold,
the learning rate is reduced to less than 0. Given the probability
estimate \(p_out\), the adjusted learning rate
\(lr_adj\) is \(lr * 1 - (rac{p_out}{skip_threshold})\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module
|
Type[Module]
|
Torch Module that builds the autoencoder to be wrapped.
The Module should accept parameter |
required |
loss_fn
|
Union[str, Callable]
|
Loss function to be used for training the wrapped model.
Can be a loss function provided by |
'mse'
|
optimizer_fn
|
Union[str, Callable]
|
Optimizer to be used for training the wrapped model.
Can be an optimizer class provided by |
'sgd'
|
lr
|
float
|
Base learning rate of the optimizer. |
0.001
|
skip_threshold
|
float
|
Threshold probability to use as a reference for the reduction of the base learning rate. |
0.9
|
device
|
str
|
Device to run the wrapped model on. Can be "cpu" or "cuda". |
'cpu'
|
seed
|
int
|
Random seed to be used for training the wrapped model. |
42
|
**kwargs
|
Parameters to be passed to the Examples |
{}
|
|
Rolling
|
|
required |
Methods:
Name | Description |
---|---|
clone |
Clones the estimator. |
draw |
Draws the wrapped model. |
initialize_module |
Parameters |
learn_one |
Performs one step of training with a single example, |
score_many |
Returns an anomaly score for the provided batch of examples in |
score_one |
Returns an anomaly score for the provided example in the form of |
Source code in deep_river/anomaly/probability_weighted_ae.py
clone
¶
Clones the estimator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_params
|
dict[Any, Any] | None
|
New parameters to be passed to the cloned estimator. |
None
|
include_attributes
|
If True, the attributes of the estimator will be copied to the cloned estimator. This is useful when the estimator is a transformer and the attributes are the learned parameters. |
False
|
Returns:
Type | Description |
---|---|
DeepEstimator
|
The cloned estimator. |
Source code in deep_river/base.py
draw
¶
Draws the wrapped model.
Source code in deep_river/base.py
initialize_module
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module
|
The instance or class or callable to be initialized, e.g.
|
required | |
kwargs
|
dict
|
The keyword arguments to initialize the instance or class. Can be an empty dict. |
{}
|
Returns:
Type | Description |
---|---|
instance
|
The initialized component. |
Source code in deep_river/base.py
learn_one
¶
Performs one step of training with a single example, scaling the employed learning rate based on the outlier probability estimate of the input example.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
|
{}
|
|
x
|
dict
|
Input example. |
required |
Returns:
Type | Description |
---|---|
ProbabilityWeightedAutoencoder
|
The autoencoder itself. |
Source code in deep_river/anomaly/probability_weighted_ae.py
score_many
¶
Returns an anomaly score for the provided batch of examples in the form of the autoencoder's reconstruction error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Input batch of examples. |
required |
Returns:
Type | Description |
---|---|
float
|
Anomaly scores for the given batch of examples. Larger values indicate more anomalous examples. |
Source code in deep_river/anomaly/ae.py
score_one
¶
Returns an anomaly score for the provided example in the form of the autoencoder's reconstruction error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
dict
|
Input example. |
required |
Returns:
Type | Description |
---|---|
float
|
Anomaly score for the given example. Larger values indicate more anomalous examples. |
Source code in deep_river/anomaly/ae.py
ProbabilityWeightedAutoencoderInitialized
¶
ProbabilityWeightedAutoencoderInitialized(
module: Module,
loss_fn: Union[str, Callable] = "mse",
optimizer_fn: Union[str, Callable] = "sgd",
lr: float = 0.001,
device: str = "cpu",
seed: int = 42,
skip_threshold: float = 0.9,
window_size=250,
**kwargs
)
Bases: AutoencoderInitialized
Methods:
Name | Description |
---|---|
learn_one |
Performs one step of training with a single example, |
score_many |
Returns an anomaly score for the provided batch of examples in |
score_one |
Returns an anomaly score for the provided example in the form of |
Source code in deep_river/anomaly/probability_weighted_ae.py
learn_one
¶
Performs one step of training with a single example, scaling the employed learning rate based on the outlier probability estimate of the input example.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
|
{}
|
|
x
|
dict
|
Input example. |
required |
Returns:
Type | Description |
---|---|
ProbabilityWeightedAutoencoder
|
The autoencoder itself. |
Source code in deep_river/anomaly/probability_weighted_ae.py
score_many
¶
Returns an anomaly score for the provided batch of examples in the form of the autoencoder's reconstruction error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Input batch of examples. |
required |
Returns:
Type | Description |
---|---|
float
|
Anomaly scores for the given batch of examples. Larger values indicate more anomalous examples. |
Source code in deep_river/anomaly/ae.py
score_one
¶
Returns an anomaly score for the provided example in the form of the autoencoder's reconstruction error.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
dict
|
Input example. |
required |
Returns:
Type | Description |
---|---|
float
|
Anomaly score for the given example. Larger values indicate more anomalous examples. |