Reconstruction Criteria
Utility functions required for the GAN based anomaly detection.
- class ecgan.utils.reconstruction_criteria.SimilarityCriterions[source]
Bases:
abc.ABC
Optimization criterion based on the dissimilarity of samples.
- class ecgan.utils.reconstruction_criteria.RBFSimilarityCriterion(**kwargs)[source]
Bases:
ecgan.utils.reconstruction_criteria.SimilarityCriterions
Optimization criterion based on the RBF similarity of samples.
- class ecgan.utils.reconstruction_criteria.CosineSimilarityCriterion[source]
Bases:
ecgan.utils.reconstruction_criteria.SimilarityCriterions
Optimization criterion based on the cosine similarity of samples.
- class ecgan.utils.reconstruction_criteria.RganMmdCriterion(sigma=None)[source]
Bases:
ecgan.utils.reconstruction_criteria.SimilarityCriterions
Optimization criterion based on the MMD similarity of samples.
- calculate(x, y)[source]
Pytorch implementation of the RGAN MMD.
The implementation is equivalent to the implementation of the
ecgan.utils.reconstruction_criteria._mix_rbf_kernel function()
from [RGAN repository, GitHub](https://github.com/ratschlab/RGAN/blob/master/mmd.py). The quadratic-time MMD with Gaussian RBF kernel is computed and - digressing from the original tensorflow implementation - only the K_XY kernel is returned.
- ecgan.utils.reconstruction_criteria.rbf_kernel(x, y, rbf_mode=None, sigma=None)[source]
Calculate the Gaussian kernel function between two tensors.
Gaussian kernel between samples of x and y. If sigma is not set, the kernel will infer the sigma value via median pairwise distance.
- Parameters
x (
Tensor
) -- Tensor of shape (N x Features).y (
Tensor
) -- Tensor of shape (N x Features).rbf_mode (
Optional
[str
]) -- Explicit choice of kernel: gaussian, exp or laplacian.sigma (
Optional
[float
]) -- Sigma for RBF bandwidth. Is usually set automatically by the object but can also be set manually.
- Return type
Tensor
- Returns
Kernel matrix K(X,Y) with shape [NX, NY]
- ecgan.utils.reconstruction_criteria.get_reconstruction_criterion(criterion='residual')[source]
Select criterion function.
Criteria are either distance based or similarity based. The target is usually to reduce either the distance or the dissimilarity (i.e. increase the similarity) between to samples.
- Return type
Callable
[[Tensor
,Tensor
],Tensor
]- Returns
Callable reconstruction criterion.