Skip to main content
fylearn - fuzzy machine learning

Build status PyPI version CodeQL Codecov

fylearn is a fuzzy machine learning library, built on top of SciKit-Learn.

SciKit-Learn contains many common machine learning algorithms, and is a good place to start if you want to play or program anything related to machine learning in Python. fylearn is not intended to be a replacement for SciKit-Learn (in fact fylearn depends on SciKit-Learn), but to provide an extra set of machine learning algorithms from the fuzzy logic community.

Machine learning algorithms

Fuzzy pattern classifiers

Fuzzy pattern classifiers are classifiers that describe data using fuzzy sets and fuzzy aggregation functions.

Several fuzzy pattern classifiers are implemented in the library:

  • fylearn.fpcowa.FuzzyPatternClassifier -- base classifier with OWA-based aggregation (see parameters).
  • fylearn.fpcowa.MultipleAggregationsFuzzyPatternClassifier -- combines several aggregations in a single classifier.
  • fylearn.fpcga.FuzzyPatternClassifierGA -- optimizes membership functions globally using a genetic algorithm.
  • fylearn.fpcga.FuzzyPatternClassifierLGA -- optimizes membership functions locally using a genetic algorithm.
  • fylearn.fpcga.SEFuzzyPatternClassifier -- fuzzy pattern classifier with membership functions optimized by search effort.
  • fylearn.fpt.FuzzyPatternTreeClassifier -- builds fuzzy pattern trees using bottom-up method.
  • fylearn.fpt.FuzzyPatternTreeTopDownClassifier -- builds fuzzy pattern trees using top-down method.
  • fylearn.frr.FuzzyReductionRuleClassifier -- based on learning membership functions from min/max.
  • fylearn.frr.ModifiedFuzzyPatternClassifier -- reduction-rule classifier using OWA / AIWA operators.
  • fylearn.rafpc.RandomAgreementFuzzyPatternClassifier -- builds fuzzy pattern classifiers using agreement-based random sampling.

Genetic Algorithm rule based classifiers

A type of classifier that uses GA to optimize rules:

  • fylearn.garules.MultimodalEvolutionaryClassifier -- learns rules using genetic algorithm.
  • fylearn.garules.EnsembleMultimodalEvolutionaryClassifier -- ensemble of multimodal evolutionary classifiers.

ANFIS

  • fylearn.anfis.AnfisClassifier -- Adaptive-Network-based Fuzzy Inference System classifier (Jang, 1993).

Installation

You can add fylearn to your project by using pip:

pip install fylearn

For development, install the dependencies and run the tests with uv:

uv sync
uv run make test

Usage

You can use the classifiers as any other SciKit-Learn classifier:

from sklearn.datasets import load_iris
from fylearn.anfis import AnfisClassifier
from fylearn.fpcowa import FuzzyPatternClassifier
from fylearn.fpt import FuzzyPatternTreeTopDownClassifier
from fylearn.garules import MultimodalEvolutionaryClassifier

X, y = load_iris(return_X_y=True)

C = (FuzzyPatternClassifier(),
     MultimodalEvolutionaryClassifier(n_iterations=100),
     FuzzyPatternTreeTopDownClassifier(),
     AnfisClassifier())

for c in C:
    print(type(c).__name__, c.fit(X, y).predict(X[:5]))

Heuristic search methods

Several heuristic search methods are implemented. These are used in the learning algorithms for parameter assignment, but, are also usable directly.

  • fylearn.local_search.PatternSearchOptimizer
  • fylearn.local_search.LocalUnimodalSamplingOptimizer
  • fylearn.ga.GeneticAlgorithm: Search parameters using modification and a scaling
  • fylearn.ga.UnitIntervalGeneticAlgorithm: Search parameters in unit interval universe.
  • fylearn.ga.DiscreteGeneticAlgorithm: Search parameters from discrete universe.
  • fylearn.tlbo.TeachingLearningBasedOptimizer: Search using teaching-learning based optimization.
  • fylearn.jaya.JayaOptimizer: Search based on moving towards best solution while avoiding worst.

Example use:

import numpy as np
from fylearn.ga import UnitIntervalGeneticAlgorithm, helper_fitness, helper_n_generations
from fylearn.local_search import LocalUnimodalSamplingOptimizer, helper_num_runs
from fylearn.tlbo import TeachingLearningBasedOptimizer
from fylearn.jaya import JayaOptimizer

def fitness(x):  # defined for a single chromosome, so we need helper_fitness for GA
    return np.sum(x**2)

ga = UnitIntervalGeneticAlgorithm(fitness_function=helper_fitness(fitness), n_chromosomes=100, n_genes=10)
ga = helper_n_generations(ga, 100)
best_chromosomes, best_fitness = ga.best(1)
print("GA solution", best_chromosomes[0], "fitness", best_fitness[0])

lower_bounds, upper_bounds = np.ones(10) * -10.0, np.ones(10) * 10.0
lus = LocalUnimodalSamplingOptimizer(fitness, lower_bounds, upper_bounds)
best_solution, best_fitness = helper_num_runs(lus, 100)
print("LUS solution", best_solution, "fitness", best_fitness)

tlbo = TeachingLearningBasedOptimizer(f=fitness, lower_bound=lower_bounds, upper_bound=upper_bounds)
tlbo = helper_n_generations(tlbo, 100)
best_solution, best_fitness = tlbo.best()
print("TLBO solution", best_solution, "fitness", best_fitness)

jaya = JayaOptimizer(f=fitness, lower_bound=lower_bounds, upper_bound=upper_bounds)
jaya = helper_n_generations(jaya, 100)
best_solution, best_fitness = jaya.best()
print("Jaya solution", best_solution, "fitness", best_fitness)

A tiny fuzzy logic library

Tiny, but hopefully useful. The focus of the library is on providing membership functions and aggregations that work with NumPy, for using in the implemented learning algorithms.

Membership functions

  • fylearn.fuzzylogic.TriangularSet
  • fylearn.fuzzylogic.TrapezoidalSet
  • fylearn.fuzzylogic.PiSet
  • fylearn.fuzzylogic.ZadehNegatedSet
  • fylearn.nonstationary.NonstationaryFuzzySet

Example use:

import numpy as np
from fylearn.fuzzylogic import TriangularSet
t = TriangularSet(1.0, 4.0, 5.0)
print(t(3))   # use with singletons
print(t(np.array([[1, 2, 3], [4, 5, 6]])))  # use with arrays

Aggregation functions

Here focus has been on providing aggregation functions that support aggregation along a specified axis for 2-dimensional matrices.

Example use:

import numpy as np
from fylearn.fuzzylogic import meowa, OWA
a = OWA(np.array([1.0, 0.0, 0.0]))  # pure AND in OWA
X = np.random.rand(5, 3)
print(a(X))  # AND row-wise
a = meowa(5, 0.2)  # OR, orness = 0.2
print(a(X.T))  # works column-wise, so apply to transposed X

Also available: t-norms / t-conorms (product, mean, min, max, Lukasiewicz, Einstein, algebraic sum), OWA variants (GOWA, weights_mapping, sampling_owa_orness), and andness-directed averaging (fylearn.fuzzylogic.AndnessDirectedAveraging).

To Do

We are working on adding the following algorithms:

  • FRBCS.

About

fylearn is supposed to mean "FuzzY learning", but in Danish the word "fy" means loosely translated "for shame". It has been created by the Department of Computer Science at Sri Venkateswara University, Tirupati, INDIA by a PhD student as part of his research.

Contributions:

  • fylearn.local_search Python code by M. E. H. Pedersen (M. E. H. Pedersen, Tuning and Simplifying Heuristical Optimization, PhD Thesis, University of Southampton, U.K., 2010)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fylearn-0.2.3.tar.gz (114.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fylearn-0.2.3-py3-none-any.whl (43.6 kB view details)

Uploaded Python 3

File details

Details for the file fylearn-0.2.3.tar.gz.

File metadata

  • Download URL: fylearn-0.2.3.tar.gz
  • Upload date:
  • Size: 114.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fylearn-0.2.3.tar.gz
Algorithm Hash digest
SHA256 1d78f6d1292795ee014133a125b04714bcd73a66e3803a5c5090c36b96677c85
MD5 c71e0b7c0ea12b9094d9392ebca2d514
BLAKE2b-256 22432ef8f2bb3fe880a170664fba1f18456f60fee1e3ad302153106b7ded7f02

See more details on using hashes here.

File details

Details for the file fylearn-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: fylearn-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 43.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fylearn-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 087e3bd5ab89b14691e105b0f67cc0966746bb21262ef58111f73052016b88e5
MD5 3f762b303032b57fcf64e16ae087326d
BLAKE2b-256 ac937cb19e1eaf1a169bf924130611453382448cc7003a4ddb90d310e73d5a85

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 files

0.2.2

2 files

0.2.1

2 files

0.1.10

1 file

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.4

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page