Experiments with fuzzy layers and neural nerworks
- Get more fine-grained features from autoencoders
- Semi-supervised learning
- Anomaly detections
Package requirements:
torch>=1.8
Installation via pip:
pip install torchfuzzy
Membership function for layer FuzzyLayer
have form
with
FuzzyLayer
stores and tunes set of matricies
Let's demonstrate how FuzzyLayer
works on simple 2D case generating dataset with four centroids.
This dataset consists of 2D point coordinates and centroid belongingness as label.
To each coordinate scaled noise component is added.
Resulting clustered structures are shown on picture below.
After training procedure completed (full code see here) and correct points labeling is achieved uniform distribution classification performed. On picture below yellow points are not passed through threshold of any centroid belonginess.
On this primitive example we can see that FuzzyLayer
is able to learn clustered structure of underlying manifold.
In such a way FuzzyLayer
can be used as anomaly detection algorithm if we interpret yellow points as outliers.
But more interesting application of FuzzyLayer
is clusterization of another model outputs to get more fine-grained results.
from torchfuzzy import FuzzyLayer
x = torch.rand((10,2))
fuzzy_layer = FuzzyLayer.from_dimensions(2, 4)
inference = fuzzy_layer.forward(x)
Full example see here.
Mamdani fuzzy model can be represented as a ruleset:
where
Straightforward implementation with FuzzyLayer
:
mamdani_fis = nn.Sequential(
FuzzyLayer.from_dimensions(input_dimention, fuzzy_rules_count, trainable=True),
nn.Softmax(1),
nn.Linear(fuzzy_rules_count, output_dimention, bias=False)
)
A more correct implementation is implemented in the DefuzzyLinearLayer
, the network structure takes the following form
mamdani_fis = nn.Sequential(
FuzzyLayer.from_dimensions(input_dimention, fuzzy_rules_count, trainable=True),
DefuzzyLinearLayer.from_dimensions(fuzzy_rules_count, output_dimention)
)