fuzzylogic


Namefuzzylogic JSON
Version 1.4.1 PyPI version JSON
download
home_pagehttps://github.com/amogorkon/fuzzylogic
SummaryFuzzy Logic for Python 3
upload_time2024-05-24 10:37:03
maintainerNone
docs_urlNone
authorAnselm Kiefner
requires_python>=3.12
licenseMIT
keywords fuzzy logic
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Fuzzy Logic for Python 3

[![license](https://img.shields.io/github/license/amogorkon/fuzzylogic)](https://github.com/amogorkon/fuzzylogic/blob/master/LICENSE)
[![stars](https://img.shields.io/github/stars/amogorkon/fuzzylogic?style=plastic)](https://github.com/amogorkon/fuzzylogic/stargazers)
[![forks](https://img.shields.io/github/forks/amogorkon/fuzzylogic?style=plastic)](https://github.com/amogorkon/fuzzylogic/network/members)
[![Downloads](https://pepy.tech/badge/fuzzylogic)](https://pepy.tech/project/fuzzylogic)


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
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](https://jupyter.org) :-)

# Documentation
Thanks to [Atul Kushwaha](https://github.com/coderatul), we now have an amazing [documentation](https://fuzzylogic.readthedocs.io/en/latest/) including our [Showcase](https://github.com/amogorkon/fuzzylogic/blob/master/docs/Showcase.ipynb) - check it out!

# Office Hours
You can also contact me one-on-one! Check my [office hours](https://calendly.com/amogorkon/officehours) to set up a meeting :-)

-- Anselm Kiefner

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/amogorkon/fuzzylogic",
    "name": "fuzzylogic",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": null,
    "keywords": "fuzzy logic",
    "author": "Anselm Kiefner",
    "author_email": "fuzzylogic-pypi@anselm.kiefner.de",
    "download_url": "https://files.pythonhosted.org/packages/0d/74/2ac99dc5e35cb0d50a247be7e9c2a0cff32b4548893dd4434f24f8989cf1/fuzzylogic-1.4.1.tar.gz",
    "platform": null,
    "description": "# Fuzzy Logic for Python 3\r\n\r\n[![license](https://img.shields.io/github/license/amogorkon/fuzzylogic)](https://github.com/amogorkon/fuzzylogic/blob/master/LICENSE)\r\n[![stars](https://img.shields.io/github/stars/amogorkon/fuzzylogic?style=plastic)](https://github.com/amogorkon/fuzzylogic/stargazers)\r\n[![forks](https://img.shields.io/github/forks/amogorkon/fuzzylogic?style=plastic)](https://github.com/amogorkon/fuzzylogic/network/members)\r\n[![Downloads](https://pepy.tech/badge/fuzzylogic)](https://pepy.tech/project/fuzzylogic)\r\n\r\n\r\nThis 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!). \r\n\r\n### Why a new library?\r\nThe 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.\r\nSure, 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).\r\nAnd 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.\r\nFinally, 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!\r\n\r\n### The Idea\r\nSo, 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.\r\nFinally, use the Rules to map input domain to output domain to actually control stuff.\r\n### Warning: Magic\r\nTo 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:\r\n* all functions are recursive closures (which makes it kinda hard to serialize things, if you really want to do that)\r\n* The main classes use a lot of dunder methods to implement their logic, which can be a bit daunting at first glance\r\n* 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.\r\n\r\n# Installation\r\nJust enter \r\n`python -m pip install fuzzylogic`\r\nin a commandline prompt and you should be good to go!\r\n\r\nIt's even more fun to experiment with it in [Jupyter Lab](https://jupyter.org) :-)\r\n\r\n# Documentation\r\nThanks to [Atul Kushwaha](https://github.com/coderatul), we now have an amazing [documentation](https://fuzzylogic.readthedocs.io/en/latest/) including our [Showcase](https://github.com/amogorkon/fuzzylogic/blob/master/docs/Showcase.ipynb) - check it out!\r\n\r\n# Office Hours\r\nYou can also contact me one-on-one! Check my [office hours](https://calendly.com/amogorkon/officehours) to set up a meeting :-)\r\n\r\n-- Anselm Kiefner\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Fuzzy Logic for Python 3",
    "version": "1.4.1",
    "project_urls": {
        "Homepage": "https://github.com/amogorkon/fuzzylogic"
    },
    "split_keywords": [
        "fuzzy",
        "logic"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0d742ac99dc5e35cb0d50a247be7e9c2a0cff32b4548893dd4434f24f8989cf1",
                "md5": "ed929178a102c8c343213ee6b3ff22d4",
                "sha256": "7ba6cfc3c0e202c9fae9ba500f1b7e1d64e0df68d3d18c74349e3e3fc4e35821"
            },
            "downloads": -1,
            "filename": "fuzzylogic-1.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ed929178a102c8c343213ee6b3ff22d4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 24711,
            "upload_time": "2024-05-24T10:37:03",
            "upload_time_iso_8601": "2024-05-24T10:37:03.792527Z",
            "url": "https://files.pythonhosted.org/packages/0d/74/2ac99dc5e35cb0d50a247be7e9c2a0cff32b4548893dd4434f24f8989cf1/fuzzylogic-1.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-24 10:37:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "amogorkon",
    "github_project": "fuzzylogic",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "fuzzylogic"
}
        
Elapsed time: 9.83356s