|
6 | 6 | "source": [ |
7 | 7 | "# Fuzzy Logic for Python 3\n", |
8 | 8 | "\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", |
12 | 9 | "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." |
13 | 10 | ] |
14 | 11 | }, |
|
20 | 17 | "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", |
21 | 18 | "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", |
22 | 19 | "\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." |
25 | 21 | ] |
26 | 22 | }, |
27 | 23 | { |
|
168 | 164 | "all(isclose(D.s1.array(), D.s2.array()))" |
169 | 165 | ] |
170 | 166 | }, |
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 | | - }, |
192 | 167 | { |
193 | 168 | "cell_type": "code", |
194 | 169 | "execution_count": 4, |
|
0 commit comments