Skip to content

Commit a96b19d

Browse files
committed
updated README
1 parent 20e0f64 commit a96b19d

File tree

2 files changed

+4
-29
lines changed

2 files changed

+4
-29
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ The first time I publish one of my private libraries. Thanks to hypothesis unit
66
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.
77
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).
88
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.
9-
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* what these things do!
9+
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!
1010

1111
### The Idea
12-
So, the idea is to have four main parts that work together: Domains, Sets, functions and Rules. You start modelling your system by defining your domain of interest. Then you think where your interesting points are in that domain and look for a function that might do what you want. In general, those fuzzy.functions map any value to [0,1], that's all. Then simply wrap your function in a Set and assign this 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.
13-
Finally, use the Rules to map some input domain to some other output domain to actually control stuff.
12+
So, the idea is to have four main parts that work together: Domains, Sets, functions and Rules. 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. Then simply wrap your function in a Set and assign this 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.
13+
Finally, use the Rules to map input domain to output domain to actually control stuff.
1414

1515
Check the notebook for working examples and documentation.
1616

Showcase.ipynb

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
"source": [
77
"# Fuzzy Logic for Python 3\n",
88
"\n",
9-
"In my ventures into game dev, scheduling etc. I often came across the need to normalize values and apply some logic on these values. I thought that fuzzy logic would be the best tool for this job, but the libraries I found were not easily integrated into the rest of my code and not very intuitive to use.\n",
10-
"One of my (many) approaches was to actually build fuzzy values out of native python bools or floats, but this was not supported by the language itself due to restrictions on what can be done with bool. Then I started to collect useful math functions from different places and made them usable just by pluggin them in.\n",
11-
"\n",
129
"The doctests in the modules should give a good idea how to use things by themselves, while here are some examples how to use everything together."
1310
]
1411
},
@@ -20,8 +17,7 @@
2017
"Defining a domain with its range and resolution should be trivial since most real world instruments come with those specifications. However, defining the fuzzy sets within those domains is where the fun begins as only a human can tell whether something is \"hot\" or \"not\", right?\n",
2118
"I've included some simple convenience functions that combine two or more functions over a range, however I consciously left out more complex \"convenience\" functions such as polygons because it is probably easier to just build those as combinations of sets.\n",
2219
"\n",
23-
"Why the distinction? Functions only map values, nothing special there at all - which is good for testing and performance. Sets on the other hand implement logical operations that have special python syntax, which makes it easy to work with but a little more difficult to test and adds some performance overhead. So, sets are for abstraction and easy handling, functions for performance.\n",
24-
"It is possible to implement everything as pure classes as well as pure functions (been there, done that) but both approaches make things either harder to test and optimize or very hard to read."
20+
"Why the distinction? Functions only map values, nothing special there at all - which is good for testing and performance. Sets on the other hand implement logical operations that have special python syntax, which makes it easy to work with but a little more difficult to test and adds some performance overhead. So, sets are for abstraction and easy handling, functions for performance."
2521
]
2622
},
2723
{
@@ -168,27 +164,6 @@
168164
"all(isclose(D.s1.array(), D.s2.array()))"
169165
]
170166
},
171-
{
172-
"cell_type": "code",
173-
"execution_count": 8,
174-
"metadata": {
175-
"collapsed": false
176-
},
177-
"outputs": [
178-
{
179-
"ename": "NameError",
180-
"evalue": "name 'fun' is not defined",
181-
"output_type": "error",
182-
"traceback": [
183-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
184-
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
185-
"\u001b[0;32m<ipython-input-8-cd1aace75fdc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mD\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mDomain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"d\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mres\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0.1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mD\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0ms1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mSet\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfun\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbounded_linear\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m12\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mD\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0ms2\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m~\u001b[0m\u001b[0;34m~\u001b[0m\u001b[0mD\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0ms1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
186-
"\u001b[0;31mNameError\u001b[0m: name 'fun' is not defined"
187-
]
188-
}
189-
],
190-
"source": []
191-
},
192167
{
193168
"cell_type": "code",
194169
"execution_count": 4,

0 commit comments

Comments
 (0)