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

Target only a subset of input in rules #12

Closed
pierrethiriet opened this issue Jul 13, 2021 · 5 comments
Closed

Target only a subset of input in rules #12

pierrethiriet opened this issue Jul 13, 2021 · 5 comments
Assignees

Comments

@pierrethiriet
Copy link

I am currently moving from R to Julia. I am trying to test the Fuzzy.jl package and I have a small issue with the rule definition.
Is it possible to target only a subset of input in a rule?
In the following example, I a trying to reproduce the classical example of restaurant tip :

Rules:

  • IF the service was excellent or the food quality was delicious, THEN the tip will be generous.
  • IF the service was good, THEN the tip will be average.
  • IF the service was poor and the food quality was poor THEN the tip will be cheap.
service = Dict( "poor"      => TriangularMF(-1, 0, 1.5), 
                "good"      => TriangularMF(3.5, 5, 6.5),
                "excellent" => TriangularMF(8.5, 10, 11.5))

food = Dict("rancid"    => TrapezoidalMF(-2, 0, 2, 4),
            "delicious" => TrapezoidalMF(7, 9, 11, 13))

inputs = [service, food]

tip  = Dict("cheap"     => TriangularMF(2.5, 5, 7.5),
            "average"   => TriangularMF(10, 12.5, 15), 
            "generous"  => TriangularMF(17.5, 20, 22.5))

rule1 = Rule(["poor", "rancid"], "cheap", "MAX")

# How to not include food input ?
rule2 = Rule(["good", ""], "average")

rule3 = Rule(["excellent", "delicious"], "generous", "MAX")
rules = [rule1, rule2, rule3]

fis_tips = FISMamdani(inputs, tip, rules)

So is there a way to avoid including food input for the rule2 ?
Thanks

@phelipe
Copy link
Owner

phelipe commented Jul 13, 2021

Hi!
At the moment it is not possible to do this, but it is a good functionality and I think it is not hard to implement. I will try do this next weekend and report here the results.

@phelipe phelipe self-assigned this Jul 13, 2021
@pierrethiriet
Copy link
Author

Thanks a lot

@phelipe
Copy link
Owner

phelipe commented Jul 18, 2021

Hi!

Can you test the subset_rule branch? I did a modification and did the model presented in https://iopscience.iop.org/article/10.1088/1742-6596/1830/1/012008/pdf

service = Dict( "poor"      => TrapezoidalMF(0.0, 0.0, 2.0, 4.0), 
                "good"      => TriangularMF(3., 5., 7.),
                "excellent" => TrapezoidalMF(6., 8., 10., 10.))

food = Dict("rancid"    => TrapezoidalMF(0., 0., 3., 6.),
            "delicious" => TrapezoidalMF(4., 7., 10., 10.))

inputs = [service, food]

tip  = Dict("cheap"     => TrapezoidalMF(10., 10., 20., 30.),
            "average"   => TriangularMF(20., 30., 40.), 
            "generous"  => TrapezoidalMF(30., 40, 50., 50.))

rule1 = Rule(["poor", "rancid"], "cheap", "MAX")
rule2 = Rule(["good", ""], "average")
rule3 = Rule(["excellent", "delicious"], "generous", "MAX")
rules = [rule1, rule2, rule3]

fis_tips = FISMamdani(inputs, tip, rules)

in_vals = [7., 8.]

println(eval_fis(fis_tips, in_vals) )

@pierrethiriet
Copy link
Author

Thanks a lot,
The new branch works well with the proposed example.
I just have one cometic comment. With more input variables, rules can become complex to follow. For this reason, I use a named tuple in place of the input vector (close to the R Sets package) :

# Convert named tuple to array
inputs_names = [:service, :food]
r(val) = [haskey(val, i) ? getindex(val, i) : "" for i in inputs_names]

rule1 = Rule(r((service="poor", food = "rancid")), "cheap", "MAX")
rule2 = Rule(r((service="good",)), "average")
rule3 = Rule(r((service="excellent", food = "delicious")), "generous", "MAX")
rules = [rule1, rule2, rule3]

I don't know if this syntax could be relevant for others?

@phelipe
Copy link
Owner

phelipe commented Jul 20, 2021

@pierrethiriet I created a new issue related to this modification in syntax, for now I will close this issue and merge the changes with master.

@phelipe phelipe closed this as completed Jul 20, 2021
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