scikit fuzzy with array input ....

525 views
Skip to first unread message

Sascha Williams

unread,
May 31, 2017, 4:32:59 AM5/31/17
to scikit-fuzzy
Hi everybody,

scikit fuzzy is a great, efficient and intuitive tool for using fuzzy logic with python coding.
However, I have the following problem, which I am sure someone in this group will know a good solution to ....

I want to hand over multiple input values for each antecedent at once (as an array) and thereby produce multiple consequent values. A for loop is not an option due to computing time (up to several million input values per antecedent).

So far, I set up a list with each element representing the same ctrl.ControlSystemSimulation object

leadFIS = leads.makeFIS()    # here the ctrl.ControlSystemSimulation object with inputs, mfs, rules and outputs is created
fuzzList = list()
for ct in range(numElements):
    fuzzList.append(leadFIS)


.. so far, this is pretty straight forward and fast.
But now I would like to hand over inputs and compute all the consequent values at once, e.g.

fuzzList[:].input['input1'] = input1_values        ....which creates the error: " 'list' object has no attribute 'input' "

Ideally, this should continue as follows:
fuzzList[:].compute()
output = fuzzList[:].output['output']


I see the problem and I think there should be a simple solution to it, but I don't get there. Can someone here give me a hint?

Thanks a lot and best wishes
Sascha

Josh Warner

unread,
Jun 2, 2017, 9:00:18 PM6/2/17
to Sascha Williams, scikit-fuzzy
This isn't you, it's an issue with my original design of the control submodule.  I do think this can be done, but it'll have to be patched in.

You aren't the first to be interested in running a large number of simulations on existing data.  There is a stackoverflow thread about improving performance in a similar case.  My envisioned use cases when designing the control submodule was for control systems, likely on fairly lower-powered systems.  These would have essentially ongoing polled inputs from a set of sensors, run the simulation, adjust outputs based on it, repeat.  It works well for this.  But only a single floating point input for each Antecedent was designed for.  Such systems are often heavily memory-limited, so running full arrays through wasn't thought to be a large use case.  

There have been some improvements in performance realized in 0.3 with the underlying interpolation.  However, you're right in that making this possible to operate on an entire array would be preferable.

I've thought about this for a couple days, and I do think it can be done and is worth pursuing.  You'll have to bear with me for a bit as I figure out the best way to go about this, though, as it increases complexity but I don't want to add too much overhead to the single-input cases.

@JDWarner

Sascha Williams

unread,
Jun 22, 2017, 5:31:24 AM6/22/17
to scikit-fuzzy, sswi...@gmail.com
Hi JDWarner,

thanks a lot for your reply!

Best wishes

Sascha

Josh Warner

unread,
Jun 22, 2017, 9:13:49 AM6/22/17
to Sascha Williams, scikit-fuzzy
I've been working at this.  Complicating the issue is that during the calculation, the number of times a given membership function crosses a certain fuzzy membership threshold must be found.  This is an arbitrary number, and it varies per membership function.

Because of that, simple array math breaks down, as the 'crossings' axis would have a different length for each point.  Dropping into a loop eliminates most of the gains.  I suspect getting maximum performance will require being a little creative, and either Cython or Numba.

Sascha Williams

unread,
Jun 23, 2017, 7:22:27 AM6/23/17
to scikit-fuzzy, sswi...@gmail.com
...does this probelm also apply if membership functions and rules stay the same for all array elements and only antecedent values vary?

JDWarner

unread,
Jul 29, 2017, 4:52:35 AM7/29/17
to scikit-fuzzy, sswi...@gmail.com
PR is up including experimental support for array inputs, and some other performance improvements.  It's dramatically faster in my tests.

Please help test/try it out!  Expect a new major point release after it's merged.

Sascha Williams

unread,
Aug 17, 2017, 4:44:48 AM8/17/17
to scikit-fuzzy, sswi...@gmail.com
...awesome! I will give it a try right now! :)

Joshua Warner

unread,
Aug 25, 2017, 1:53:08 AM8/25/17
to Sascha Williams, scikit-fuzzy
I'm love to hear a report - rather sure it will be faster, but you may run into memory limitations.

Joshua Warner

unread,
Aug 26, 2017, 2:19:08 AM8/26/17
to Sascha Williams, scikit-fuzzy
After robust testing, this PR has now been merged into the development master branch, which may make it easier to evaluate.
Reply all
Reply to author
Forward
0 new messages