Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion/RFC: Add Takagi-Sugeno-Kang (TSK, Sugeno) fuzzy systems #95

Open
JDWarner opened this issue Apr 4, 2016 · 7 comments
Open

Comments

@JDWarner
Copy link
Collaborator

JDWarner commented Apr 4, 2016

The new fuzzy system API (initially in #70, follow-ups in #76 and #92 so far) is designed for classical Mamdani fuzzy systems.

It has been requested that we consider adding support for TSK systems in the new framework.

This Issue is the place for discussion about potentially adding this support. Please post any thoughts about

  • How such a system would ideally work, from a user perspective. Pseudo-code appreciated.
  • Options that need to be exposed to the user, and at what levels
  • API concerns - can this be toggled in a Consequent object with a kwarg, or should it be a separate ConsequentTSK object.

Once we have a sense of the ideal design, we can move forward with implementation.

@jcozar87
Copy link

jcozar87 commented Apr 4, 2016

Hi,

In my opinion, one way to do that could be:

  • Antecedents would have the same definition: a combination of Fuzzy Values (Fuzzy Sets defined for a Fuzzy Variable)
  • The case of Mamdani consequents would be managed in the same way: a partition is made before, and then when the Fuzzy Rule is created we specify the label. In the case of TSK consequents, we do not have to make a partition, and when the Fuzzy Rule is created, we use a fuzzymath.polynomial instead of a 'label'.
  • Fuzzy Rule would have a similar definition: one Antecedent, one Consequent, and optionally you can specify the T and S norms (min-max by default).
  • The inference in the case of TSK Rules would be equivalent to have Singleton Fuzzy Sets in Mamdani Rules (but obviously this sets are dependent of the input).

One example of Fuzzy System of TSK rules would be:

quality = fuzz.Antecedent(np.arange(0, 11, 1), 'quality')
service = fuzz.Antecedent(np.arange(0, 11, 1), 'service')
tip = fuzz.Consequent(np.arange(0, 26, 1), 'tip')
quality.automf(3)
service.automf(3)
rule1 = fuzz.Rule(quality['poor'] | service['poor'], tip[fuzz.fuzzymath.polynomial(coefficients=(5,1,1), exponents=(1,1))])
rule2 = fuzz.Rule(service['average'], tip[fuzz.fuzzymath.polynomial(coefficients=(2,1,2), exponents=(1,1))])
rule3 = fuzz.Rule(service['good'] | quality['good'], tip[fuzz.fuzzymath.polynomial(coefficients=(5,2,3), exponents=(1,1))])
tipping_ctrl = fuzz.ControlSystem([rule1, rule2, rule3])
tipping = fuzz.ControlSystemSimulation(tipping_ctrl)
tipping.input['quality'] = 6.5
tipping.input['service'] = 9.8
tipping.compute()

Doing it in this way, there is not a big change in the API and it could work (the main trick would be in the __getitem__() of the Consequents). What do you think?

@JDWarner
Copy link
Collaborator Author

JDWarner commented Apr 5, 2016

Thanks for the detailed input, @jcozar87 - definitely what I was looking for. I don't routinely use TSK systems so I really appreciate your thoughts. From what I read, I hoped it was just the Consequent that needed tweaking. Glad that seems to be the case.

Your way is probably the most transparent method to enable this. I do wonder if it's almost too transparent - we do want people to be able to find this intuitively.

The main new object is the polynomial. This is probably going to be a custom object, and it might be best for it to live in skfuzzy.control as Polynomial or SugenoPolynomial (unfortunately 'TSKPoly' doesn't parse well in CamelCase naming conventions).

We can make this a little clearer via documentation and examples in the docstrings and online gallery.

@JDWarner
Copy link
Collaborator Author

JDWarner commented Apr 5, 2016

Can you give any more details about what ideally the SugenoPolynomial object would do?

My main concern is cross terms or more than one use of a given Antecedent in the polynomial. Something like Ax**2y + Bx + Cxy + Z would not work with a simple coefficients=, exponents= framework. But, perhaps this level of complexity is rare in TSK systems...?

@jcozar87
Copy link

jcozar87 commented Apr 5, 2016

I agree that it may be too transparent. But the point is that in Mamdani consequents, you have a Fuzzy Variable with a fixed partition, and you choose one label for the consequent of the rule. In the case of TSK consequents, it is a polynomial function of the input variables, so for each rule you have to specify a (possible) different polynomial: that is the reason I suggested to follow that procedure.

Regarding the polynomials you are right, it requires more information. As TSK consequents are polynomial functions of the input variables (and the order of the TSK rules refers to the grade of the polynomial), one way to use this type of objects could be as follows:
p = skfuzzy.control.Polynomial(fun='A*x**2*y + B*x + C*x*y + Z', coef={'A':1,'B':2,'C':3,'Z':4})

and we can use the eval function to evaluate the polynomial:

loc = self.coef.copy()
loc.update(variables)
return eval(self.fun, {}, loc)

where variables would be the values for the input variables: variables = {'x':1,'y':7}

@JDWarner
Copy link
Collaborator Author

@jcozar87 are you OK with pushing TSK systems into the next major point release? I do think it's entirely possible to do this, but I'd like to get 0.2 out very soon.

@jcozar87
Copy link

Hi @JDWarner, sorry, I have been very busy. I recently moved to other country because my job, but I will work on it this week! I know how to implement it, so I expect to push it very soon.

@jcozar87
Copy link

Hi @JDWarner, I made a PR to discuss some things about the implementation of the TSK systems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants