Skip to main content

a fuzzy logic control library in Python

Project description

fuzzylite

pyfuzzylite 8.0.6

A Fuzzy Logic Control Library in Python

by Juan Rada-Vilela, PhD

License: GPL v3 License: Paid Coverage Status
Build Test Publish

FuzzyLite

The FuzzyLite Libraries for Fuzzy Logic Control refer to fuzzylite (C++), pyfuzzylite (Python), and jfuzzylite (Java).

The goal of the FuzzyLite Libraries is to easily design and efficiently operate fuzzy logic controllers following an object-oriented programming model with minimal dependency on external libraries.

License

pyfuzzylite is dual-licensed under the GNU GPL 3.0 and under a proprietary license for commercial purposes.

You are strongly encouraged to support the development of the FuzzyLite Libraries by purchasing a license of QtFuzzyLite.

QtFuzzyLite is the best graphical user interface available to easily design and directly operate fuzzy logic controllers in real time. Available for Windows, Mac, and Linux, its goal is to significantly speed up the design of your fuzzy logic controllers, while providing a very useful, functional and beautiful user interface. Please, download it and check it out for free at fuzzylite.com/downloads.

Install

pip install pyfuzzylite

Features

Documentation: fuzzylite.github.io/pyfuzzylite/

(6) Controllers: Mamdani, Takagi-Sugeno, Larsen, Tsukamoto, Inverse Tsukamoto, Hybrid

(25) Linguistic terms: (5) Basic: Triangle, Trapezoid, Rectangle, Discrete, SemiEllipse. (8) Extended: Bell, Cosine, Gaussian, GaussianProduct, PiShape, SigmoidDifference, SigmoidProduct, Spike. (7) Edges: Arc, Binary, Concave, Ramp, Sigmoid, SShape, ZShape. (3) Functions: Constant, Linear, Function. (2) Special: Aggregated, Activated.

(7) Activation methods: General, Proportional, Threshold, First, Last, Lowest, Highest.

(9) Conjunction and Implication (T-Norms): Minimum, AlgebraicProduct, BoundedDifference, DrasticProduct, EinsteinProduct, HamacherProduct, NilpotentMinimum, LambdaNorm, FunctionNorm.

(11) Disjunction and Aggregation (S-Norms): Maximum, AlgebraicSum, BoundedSum, DrasticSum, EinsteinSum, HamacherSum, NilpotentMaximum, NormalizedSum, UnboundedSum, LambdaNorm, FunctionNorm.

(7) Defuzzifiers: (5) Integral: Centroid, Bisector, SmallestOfMaximum, LargestOfMaximum, MeanOfMaximum. (2) Weighted: WeightedAverage, WeightedSum.

(7) Hedges: Any, Not, Extremely, Seldom, Somewhat, Very, Function.

(3) Importers: FuzzyLite Language fll. With fuzzylite: Fuzzy Inference System fis, Fuzzy Control Language fcl.

(7) Exporters: Python, FuzzyLite Language fll, FuzzyLite Dataset fld. With fuzzylite: C++, Java, FuzzyLite Language fll, FuzzyLite Dataset fld, R script, Fuzzy Inference System fis, Fuzzy Control Language fcl.

(30+) Examples of Mamdani, Takagi-Sugeno, Tsukamoto, and Hybrid controllers from fuzzylite, Octave, and Matlab, each included in the following formats: py, fll, fld. With fuzzylite: C++, Java, R, fis, and fcl.

Examples

FuzzyLite Language

# File: examples/mamdani/ObstacleAvoidance.fll
Engine: ObstacleAvoidance
InputVariable: obstacle
  enabled: true
  range: 0.000 1.000
  lock-range: false
  term: left Ramp 1.000 0.000
  term: right Ramp 0.000 1.000
OutputVariable: mSteer
  enabled: true
  range: 0.000 1.000
  lock-range: false
  aggregation: Maximum
  defuzzifier: Centroid 100
  default: nan
  lock-previous: false
  term: left Ramp 1.000 0.000
  term: right Ramp 0.000 1.000
RuleBlock: mamdani
  enabled: true
  conjunction: none
  disjunction: none
  implication: AlgebraicProduct
  activation: General
  rule: if obstacle is left then mSteer is right
  rule: if obstacle is right then mSteer is left
# Python
import fuzzylite as fl

engine = fl.FllImporter().from_file("examples/mamdani/ObstacleAvoidance.fll")

Python

import fuzzylite as fl

engine = fl.Engine(
    name="ObstacleAvoidance",
    input_variables=[
        fl.InputVariable(
            name="obstacle",
            minimum=0.0,
            maximum=1.0,
            lock_range=False,
            terms=[fl.Ramp("left", 1.0, 0.0), fl.Ramp("right", 0.0, 1.0)],
        )
    ],
    output_variables=[
        fl.OutputVariable(
            name="mSteer",
            minimum=0.0,
            maximum=1.0,
            lock_range=False,
            lock_previous=False,
            default_value=fl.nan,
            aggregation=fl.Maximum(),
            defuzzifier=fl.Centroid(resolution=100),
            terms=[fl.Ramp("left", 1.0, 0.0), fl.Ramp("right", 0.0, 1.0)],
        )
    ],
    rule_blocks=[
        fl.RuleBlock(
            name="mamdani",
            conjunction=None,
            disjunction=None,
            implication=fl.AlgebraicProduct(),
            activation=fl.General(),
            rules=[
                fl.Rule.create("if obstacle is left then mSteer is right"),
                fl.Rule.create("if obstacle is right then mSteer is left"),
            ],
        )
    ],
)

float and vectorization

# single `float` operation
engine.input_variable("obstacle").value = 0.5
engine.process()
print("y =", engine.output_variable("mSteer").value)
# > y = 0.5
print("ỹ =", engine.output_variable("mSteer").fuzzy_value())
# > ỹ = 0.500/left + 0.500/right

# vectorization
engine.input_variable("obstacle").value = fl.array([0, 0.25, 0.5, 0.75, 1.0])
engine.process()
print("y =", repr(engine.output_variable("mSteer").value))
# > y = array([0.6666665 , 0.62179477, 0.5       , 0.37820523, 0.3333335 ])
print("ỹ =", repr(engine.output_variable("mSteer").fuzzy_value()))
# > ỹ = array(['0.000/left + 1.000/right',
#              '0.250/left + 0.750/right',
#              '0.500/left + 0.500/right',
#              '0.750/left + 0.250/right',
#              '1.000/left + 0.000/right'], dtype='<U26')

Please refer to the documentation for more information: fuzzylite.github.io/pyfuzzylite/

Contributing

All contributions are welcome, provided they follow the following guidelines:

  • Source code is consistent with standards in the library
  • Contribution is properly documented and tested, raising issues where appropriate
  • Contribution is licensed under the FuzzyLite License

Reference

If you are using the FuzzyLite Libraries, please cite the following reference in your article:

Juan Rada-Vilela. The FuzzyLite Libraries for Fuzzy Logic Control, 2018. URL https://fuzzylite.com.

Or using bibtex:

@misc{fl::fuzzylite,
    author={Juan Rada-Vilela},
    title={The FuzzyLite Libraries for Fuzzy Logic Control},
    url={https://fuzzylite.com},
    year={2018}
}

fuzzylite® is a registered trademark of FuzzyLite
jfuzzylite™, pyfuzzylite™ and QtFuzzyLite™ are trademarks of FuzzyLite

Project details


Download files

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

Source Distribution

pyfuzzylite-8.0.6.tar.gz (688.0 kB view details)

Uploaded Source

Built Distribution

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

pyfuzzylite-8.0.6-py3-none-any.whl (699.8 kB view details)

Uploaded Python 3

File details

Details for the file pyfuzzylite-8.0.6.tar.gz.

File metadata

  • Download URL: pyfuzzylite-8.0.6.tar.gz
  • Upload date:
  • Size: 688.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyfuzzylite-8.0.6.tar.gz
Algorithm Hash digest
SHA256 69b28241f283fd2ef1b359f3530b752ecbbf7e5908518d452ecf2f2e71c6599f
MD5 e55766f283507f0be9b4c055a70df5cb
BLAKE2b-256 48f84d283f9a943a8ccdc11a6d908ed1d26d941dc41c5f3d8ba972daea8dcd6b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfuzzylite-8.0.6.tar.gz:

Publisher: publish.yml on fuzzylite/pyfuzzylite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyfuzzylite-8.0.6-py3-none-any.whl.

File metadata

  • Download URL: pyfuzzylite-8.0.6-py3-none-any.whl
  • Upload date:
  • Size: 699.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyfuzzylite-8.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 4c8276357dbea495c6ef36d5e273829b5695f7c4212e53b805898b5e86dfbb34
MD5 e9f17d862507c302f2c9b558cbeb5505
BLAKE2b-256 3960664e2158caddc1a168fbf232cca134f2d35b37f34cfb7c0257b101c385f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfuzzylite-8.0.6-py3-none-any.whl:

Publisher: publish.yml on fuzzylite/pyfuzzylite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page