fuzzylogic

Fuzzy Logic and Fuzzy Inference for Python 3

https://github.com/python-fuzzylogic/fuzzylogic

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.0%) to scientific vocabulary

Keywords

fuzzy-logic python python-3 pythonic

Keywords from Contributors

interactive mesh interpretability evolutionary-algorithms metaheuristic sequences generic projection optim hacking
Last synced: 4 months ago · JSON representation ·

Repository

Fuzzy Logic and Fuzzy Inference for Python 3

Basic Info
  • Host: GitHub
  • Owner: Python-Fuzzylogic
  • License: mit
  • Language: Jupyter Notebook
  • Default Branch: master
  • Homepage:
  • Size: 6.08 MB
Statistics
  • Stars: 146
  • Watchers: 7
  • Forks: 27
  • Open Issues: 36
  • Releases: 4
Topics
fuzzy-logic python python-3 pythonic
Created almost 9 years ago · Last pushed 4 months ago
Metadata Files
Readme Contributing License Citation

README.md

Fuzzy Logic for Python 3

license stars forks Downloads

This is the fourth time I rebuilt this library from scratch to find the sweet spot between ease of use (beautiful is better than ugly!), testability (simple is better than complex!) and potential for performance optimization (practicality beats purity!).

Why a new library?

The first time I was confronted with fuzzy logic, I fell in love with the concept, but after reading books and checking out libraries etc. I found it frustrating how most people make fuzzy logic appear complicated, hard to handle and incorporate in code. Sure, there are frameworks that allow modelling of functions via GUI, but that's not a solution for a coder, right? Then there's a ton of mathematical research and other cruft that no normal person has time and patience to work through before trying to explore and applying things. Coming from this direction, there are also a number of script-ish (DSL) language frameworks that try to make the IF THEN ELSE pattern work (which I also tried in python, but gave it up because it just looks ugly). And yes, it's also possible to implement the whole thing completely in a functional style, but you really don't want to work with a recursive structure of 7+ steps by hand, trying not to miss a (..) along the way. Finally, most education on the subject emphasize sets and membership functions, but fail to mention the importance of the domain (or "universe of discourse"). It's easy to miss this point if you get lost with set operations and membership values, which are actually not that difficult once you can play and explore how these things look and work!

The Idea

So, the idea is to have three parts that work together: domains, sets and rules. Each of these classes wrap additional logic around basic building blocks - Set gives logical operations to simple functions, Domain gives additional logic to numpy arrays and groups Sets together while Rule combines different Domains. You start modelling your system by defining your domain of interest. Then you think about where your interesting points are in that domain and look for a function that might do what you want. In general, fuzzy.functions map any value to [0,1], that's all. Simply wrap the function in a Set and assign it to the domain in question. Once assigned, you can plot that set and see if it actually looks how you imagined. Now that you have one or more sets, you also can start to combine them with set operations &, |, ~, etc. It's fairly straight forward. Finally, use the Rules to map input domain to output domain to actually control stuff.

Warning: Magic

To make it possible to write fuzzy logic in the most pythonic and simplest way imaginable, it was necessary to employ some magic tricks that normally are discouraged, but at least there's no black magic involved (aka meta-programming etc.), so things are easy to debug if there is a problem. Most notably: * all functions are recursive closures (which makes it kinda hard to serialize things, if you really want to do that) * The main classes use a lot of dunder methods to implement their logic, which can be a bit daunting at first glance * Domain and Set uses an assignment trick to make it possible to instantiate Set() without passing domain and name over and over (yet still be explicit, just not the way one would normally expect). This also allows to call sets as Domain.attributes, which also normally shouldn't be possible (since they are technically not attributes). However, this allows interesting things like dangling sets (sets without domains) that can be freely combined with other sets to avoid cluttering of domain-namespaces and just have the resulting set assigned to a domain to work with.

Installation

pip install fuzzylogic

Note: If you want to use the experimental GUI, you'll also need matplotlib: pip install matplotlib

GUI for Experimentation

The library now includes a web-based GUI for experimenting with fuzzy logic and generating code! This makes it easy to:

  • Visually create and test fuzzy logic systems
  • Experiment with different membership functions
  • Generate Python code for your fuzzy logic setup
  • Plot and visualize fuzzy sets

Starting the GUI

```python import fuzzylogic

Start the GUI (opens browser automatically)

fuzzylogic.run_gui()

Or from command line

python -m fuzzylogic.gui.cli

```

Fuzzy Logic GUI Screenshot

GUI Features

  • Create Domains: Define fuzzy logic domains with custom ranges
  • Add Fuzzy Sets: Create sets using R (rising), S (falling), triangular, trapezoid, and rectangular functions
  • Visualization: Real-time plotting of fuzzy sets
  • Test Values: Interactive testing of input values
  • Code Generation: Automatic Python code generation

Documentation

Just enter python -m pip install fuzzylogic in a commandline prompt and you should be good to go!

It's even more fun to experiment with it in Jupyter Lab :-)

Documentation

Thanks to Atul Kushwaha, we now have an amazing documentation including our Showcase - check it out!

Office Hours

You can also contact me one-on-one! Check my office hours to set up a meeting :-)

-- Anselm Kiefner

Owner

  • Name: Python-Fuzzylogic
  • Login: Python-Fuzzylogic
  • Kind: organization

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Kiefner"
  given-names: "Anselm"
  orcid: "https://orcid.org/0000-0002-8009-0733"
title: "FuzzyLogic for Python"
version: 1.2.0
doi: 10.5281/zenodo.6881817
date-released: 2022-02-15
url: "https://github.com/amogorkon/fuzzylogic"

GitHub Events

Total
  • Create event: 5
  • Release event: 1
  • Issues event: 29
  • Watch event: 18
  • Delete event: 2
  • Issue comment event: 2
  • Push event: 16
  • Pull request review event: 1
  • Pull request event: 6
  • Fork event: 1
Last Year
  • Create event: 5
  • Release event: 1
  • Issues event: 29
  • Watch event: 18
  • Delete event: 2
  • Issue comment event: 2
  • Push event: 16
  • Pull request review event: 1
  • Pull request event: 6
  • Fork event: 1

Committers

Last synced: 6 months ago

All Time
  • Total Commits: 290
  • Total Committers: 6
  • Avg Commits per committer: 48.333
  • Development Distribution Score (DDS): 0.245
Past Year
  • Commits: 51
  • Committers: 3
  • Avg Commits per committer: 17.0
  • Development Distribution Score (DDS): 0.059
Top Committers
Name Email Commits
Anselm Kiefner f****y@a****e 219
Atul Kushwaha a****8@g****m 64
dependabot[bot] 4****] 4
firefly-cpp i****k@i****u 1
KebPericles 4****s 1
Gonzalo Pérez Vizuete d****m@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 41
  • Total pull requests: 14
  • Average time to close issues: 12 months
  • Average time to close pull requests: 18 days
  • Total issue authors: 7
  • Total pull request authors: 4
  • Average comments per issue: 0.88
  • Average comments per pull request: 0.0
  • Merged pull requests: 12
  • Bot issues: 0
  • Bot pull requests: 5
Past Year
  • Issues: 28
  • Pull requests: 5
  • Average time to close issues: about 2 months
  • Average time to close pull requests: about 1 month
  • Issue authors: 2
  • Pull request authors: 2
  • Average comments per issue: 0.04
  • Average comments per pull request: 0.0
  • Merged pull requests: 3
  • Bot issues: 0
  • Bot pull requests: 3
Top Authors
Issue Authors
  • amogorkon (34)
  • BorelHendrake (3)
  • KebPericles (1)
  • fbous (1)
  • TheBariumOxide (1)
  • schmid-mat (1)
  • burgosmad (1)
Pull Request Authors
  • dependabot[bot] (6)
  • coderatul (5)
  • Copilot (2)
  • KebPericles (2)
Top Labels
Issue Labels
enhancement (34) help wanted (4) question (1) bug (1)
Pull Request Labels
dependencies (5) python (2)

Dependencies

requirements.txt pypi
  • hypothesis *
  • matplotlib *
  • numpy *
  • python >=3.7
.github/workflows/docsupdater.yaml actions
  • actions/checkout v2 composite
docs/requirements.txt pypi
  • Jinja2 ==3.1.2
  • Markdown ==3.3.7
  • MarkupSafe ==2.1.3
  • PyYAML ==6.0
  • click ==8.1.3
  • colorama ==0.4.6
  • ghp-import ==2.1.0
  • mergedeep ==1.3.4
  • mkdocs ==1.4.3
  • packaging ==23.1
  • python-dateutil ==2.8.2
  • pyyaml_env_tag ==0.1
  • six ==1.16.0
  • watchdog ==3.0.0
pyproject.toml pypi
setup.py pypi