home › Forums › # Technical Support › JAVA API
- This topic has 26 replies, 6 voices, and was last updated 8 years, 9 months ago by
Unknown.
-
AuthorPosts
-
June 16, 2014 at 19:15 #1107
Unknown
MemberHello,
I want to use the library as part of my application so I decided to code the fuzzy system.
First I was trying to inference on the example, to understand how it works.So I set an input value and then I tried to get the output variable value. But it always returns NaN.
This is the code, please, let me know what I am doing wrong.
—–
Engine engine = new Engine();
engine.setName(“simple-dimmer”);InputVariable inputVariable = new InputVariable();
inputVariable.setEnabled(true);
inputVariable.setName(“Ambient”);
inputVariable.setRange(0.000, 1.000);
inputVariable.addTerm(new Triangle(“DARK”, 0.000, 0.250, 0.500));
inputVariable.addTerm(new Triangle(“MEDIUM”, 0.250, 0.500, 0.750));
inputVariable.addTerm(new Triangle(“BRIGHT”, 0.500, 0.750, 1.000));
engine.addInputVariable(inputVariable);OutputVariable outputVariable = new OutputVariable();
outputVariable.setEnabled(true);
outputVariable.setName(“Power”);
outputVariable.setRange(0.000, 1.000);
outputVariable.fuzzyOutput().setAccumulation(null);
outputVariable.setDefuzzifier(new WeightedAverage());
outputVariable.setDefaultValue(Double.NaN);
outputVariable.setLockValidOutput(false);
outputVariable.setLockOutputRange(false);
outputVariable.addTerm(new Constant(“LOW”, 0.250));
outputVariable.addTerm(new Constant(“MEDIUM”, 0.500));
outputVariable.addTerm(new Constant(“HIGH”, 0.750));
engine.addOutputVariable(outputVariable);RuleBlock ruleBlock = new RuleBlock();
ruleBlock.setEnabled(true);
ruleBlock.setName(“”);
ruleBlock.setConjunction(new Minimum());
ruleBlock.setDisjunction(new Maximum());
ruleBlock.setActivation(new Minimum());
ruleBlock.addRule(Rule.parse(“if Ambient is DARK then Power is HIGH”,
engine));
ruleBlock.addRule(Rule.parse(
“if Ambient is MEDIUM then Power is MEDIUM”, engine));
ruleBlock.addRule(Rule.parse(“if Ambient is BRIGHT then Power is LOW”,
engine));
engine.addRuleBlock(ruleBlock);StringBuilder status = new StringBuilder();
if (!engine.isReady(status))
throw new RuntimeException(“Engine not ready. ”
+ “The following errors were encountered:\n”
+ status.toString());engine.setInputValue(“Ambient”, 0.1);
System.out.println(engine.getOutputValue(“Power”)); // This always return NaN
June 16, 2014 at 19:21 #1108Juan Rada-Vilela (admin)
KeymasterHi,
thank you for your post.
You need to process the engine before finding out the output value.
engine.setInputValue("Ambient", 0.1); engine.process(); System.out.println(engine.getOutputValue(“Power”));
You also need an accumulation method when setting the OutputVariable (yours is set to null):
outputVariable.fuzzyOutput().setAccumulation(new Maximum());
Let me know if it works.
Cheers,
Juan.
-
This reply was modified 9 years, 3 months ago by
Juan Rada-Vilela (admin).
July 2, 2014 at 08:20 #1128Unknown
MemberI have the same problem, after adjustments requested by Juan still keeps giving the same answer.
Message: NaN
I hope to return!July 2, 2014 at 10:02 #1130Juan Rada-Vilela (admin)
KeymasterCan you please post your current code?
July 3, 2014 at 09:46 #1135Unknown
MemberFollowing code.
//OBJETO FUZZY Engine engine = new Engine(); engine.setName("simple-dimmer"); //VARIAVEIS LINGUISTICAS DE ENTRADA InputVariable inputVariable = new InputVariable(); inputVariable.setEnabled(true); inputVariable.setName("Ambient"); inputVariable.setRange(0.000, 1.000); inputVariable.addTerm(new Triangle("DARK", 0.000, 0.250, 0.500)); inputVariable.addTerm(new Triangle("MEDIUM", 0.250, 0.500, 0.750)); inputVariable.addTerm(new Triangle("BRIGHT", 0.500, 0.750, 1.000)); engine.addInputVariable(inputVariable); //SAIDA OutputVariable outputVariable = new OutputVariable(); outputVariable.setEnabled(true); outputVariable.setName("Power"); outputVariable.setRange(0.000, 1.000); outputVariable.fuzzyOutput().setAccumulation(new Maximum()); outputVariable.fuzzyOutput().setAccumulation(new AlgebraicSum()); outputVariable.setDefuzzifier(new WeightedAverage()); outputVariable.setDefuzzifier(new Centroid(200)); outputVariable.setDefaultValue(Double.NaN); outputVariable.setLockValidOutput(false); outputVariable.setLockOutputRange(false); outputVariable.addTerm(new Constant("LOW", 0.250)); outputVariable.addTerm(new Constant("MEDIUM", 0.500)); outputVariable.addTerm(new Constant("HIGH", 0.750)); engine.addOutputVariable(outputVariable); //RULES RuleBlock ruleBlock = new RuleBlock(); ruleBlock.setEnabled(true); ruleBlock.setName(""); ruleBlock.setConjunction(new Minimum()); ruleBlock.setDisjunction(new Maximum()); ruleBlock.setActivation(new Minimum()); ruleBlock.addRule(Rule.parse("if Ambient is DARK then Power is HIGH",engine)); ruleBlock.addRule(Rule.parse("if Ambient is MEDIUM then Power is MEDIUM", engine)); ruleBlock.addRule(Rule.parse("if Ambient is BRIGHT then Power is LOW",engine)); engine.addRuleBlock(ruleBlock); StringBuilder status = new StringBuilder(); if (!engine.isReady(status)) throw new RuntimeException("Nao foi possivel gerar o arquivo. " + "O seguintes erros foram encontrados:\n" + status.toString()); engine.setInputValue("Ambient", 0.1); engine.process(); System.out.println(engine.getOutputValue("Power"));
July 3, 2014 at 10:10 #1136Juan Rada-Vilela (admin)
KeymasterHi Allison,
I have created the file
Allison.java
as follows:import com.fuzzylite.*; import com.fuzzylite.defuzzifier.*; import com.fuzzylite.factory.*; import com.fuzzylite.hedge.*; import com.fuzzylite.imex.*; import com.fuzzylite.norm.*; import com.fuzzylite.norm.s.*; import com.fuzzylite.norm.t.*; import com.fuzzylite.rule.*; import com.fuzzylite.term.*; import com.fuzzylite.variable.*; class Allison{ public static void main(String[] args){ //OBJETO FUZZY Engine engine = new Engine(); engine.setName("simple-dimmer"); //VARIAVEIS LINGUISTICAS DE ENTRADA InputVariable inputVariable = new InputVariable(); inputVariable.setEnabled(true); inputVariable.setName("Ambient"); inputVariable.setRange(0.000, 1.000); inputVariable.addTerm(new Triangle("DARK", 0.000, 0.250, 0.500)); inputVariable.addTerm(new Triangle("MEDIUM", 0.250, 0.500, 0.750)); inputVariable.addTerm(new Triangle("BRIGHT", 0.500, 0.750, 1.000)); engine.addInputVariable(inputVariable); //SAIDA OutputVariable outputVariable = new OutputVariable(); outputVariable.setEnabled(true); outputVariable.setName("Power"); outputVariable.setRange(0.000, 1.000); outputVariable.fuzzyOutput().setAccumulation(new Maximum()); outputVariable.fuzzyOutput().setAccumulation(new AlgebraicSum()); outputVariable.setDefuzzifier(new WeightedAverage()); outputVariable.setDefuzzifier(new Centroid(200)); outputVariable.setDefaultValue(Double.NaN); outputVariable.setLockValidOutput(false); outputVariable.setLockOutputRange(false); outputVariable.addTerm(new Constant("LOW", 0.250)); outputVariable.addTerm(new Constant("MEDIUM", 0.500)); outputVariable.addTerm(new Constant("HIGH", 0.750)); engine.addOutputVariable(outputVariable); //RULES RuleBlock ruleBlock = new RuleBlock(); ruleBlock.setEnabled(true); ruleBlock.setName(""); ruleBlock.setConjunction(new Minimum()); ruleBlock.setDisjunction(new Maximum()); ruleBlock.setActivation(new Minimum()); ruleBlock.addRule(Rule.parse("if Ambient is DARK then Power is HIGH",engine)); ruleBlock.addRule(Rule.parse("if Ambient is MEDIUM then Power is MEDIUM", engine)); ruleBlock.addRule(Rule.parse("if Ambient is BRIGHT then Power is LOW",engine)); engine.addRuleBlock(ruleBlock); StringBuilder status = new StringBuilder(); if (!engine.isReady(status)) throw new RuntimeException("Nao foi possivel gerar o arquivo. " + "O seguintes erros foram encontrados:\n" + status.toString()); engine.setInputValue("Ambient", 0.1); engine.process(); System.out.println(engine.getOutputValue("Power")); } }
I have compiled it as follows:
javac -cp jfuzzylite.jar Allison.java
I have executed it as follows:
java -cp .:jfuzzylite.jar Allison
And I have obtained the following result:
0.4999999999999997
Please, make sure you have not modified the sources of jfuzzylite and you are using the correct jar file which you can download from http://www.fuzzylite.com/downloads.
Cheers.
July 4, 2014 at 00:41 #1147Unknown
MemberThank you for the clarification, I checked their help after the problem was actually with some classes not imported.
I appreciate the efficiency in responses.
July 12, 2014 at 04:57 #1186Unknown
MemberHello juan
I want to thank you first for your valuable job.
I’m trying to use fuzzylite for android application but unfortunately i get nan answer with all the inputs.
I’ve tried all your previous recommendations and I also compiled and executed my code but the same result again (nan).
I also kept my code structure with samples in package but it worked fine. I am really confused now.
Any help would be appreciated. Here is my code.import com.fuzzylite.*; import com.fuzzylite.defuzzifier.*; import com.fuzzylite.factory.*; import com.fuzzylite.hedge.*; import com.fuzzylite.imex.*; import com.fuzzylite.norm.*; import com.fuzzylite.norm.s.*; import com.fuzzylite.norm.t.*; import com.fuzzylite.rule.*; import com.fuzzylite.term.*; import com.fuzzylite.variable.*; public class test { public static void main(String[] args) { Engine engine = new Engine(); engine.setName("Untitled8"); InputVariable inputVariable1 = new InputVariable(); inputVariable1.setEnabled(true); inputVariable1.setName("Gender"); inputVariable1.setRange(0.000, 1.000); inputVariable1.addTerm(new Triangle("Male", 0.000, 0.000, 0.000)); inputVariable1.addTerm(new Triangle("Female", 1.000, 1.000, 1.000)); engine.addInputVariable(inputVariable1); InputVariable inputVariable2 = new InputVariable(); inputVariable2.setEnabled(true); inputVariable2.setName("Age"); inputVariable2.setRange(2.000, 20.000); inputVariable2.addTerm(new Trapezoid("25", 2.000, 2.000, 5.000, 5.000)); inputVariable2.addTerm(new Trapezoid("58", 5.000, 5.000, 8.000, 8.000)); inputVariable2.addTerm(new Trapezoid("89", 8.000, 8.000, 9.000, 9.000)); inputVariable2.addTerm(new Trapezoid("910", 9.000, 9.000, 10.000, 10.000)); inputVariable2.addTerm(new Trapezoid("1011", 10.000, 10.000, 11.000, 11.000)); inputVariable2.addTerm(new Trapezoid("1112", 11.000, 11.000, 12.000, 12.000)); inputVariable2.addTerm(new Trapezoid("1213", 12.000, 12.000, 13.000, 13.000)); inputVariable2.addTerm(new Trapezoid("1314", 13.000, 13.000, 14.000, 14.000)); inputVariable2.addTerm(new Trapezoid("1415", 14.000, 14.000, 15.000, 15.000)); inputVariable2.addTerm(new Trapezoid("1520", 15.000, 15.000, 20.000, 20.000)); engine.addInputVariable(inputVariable2); InputVariable inputVariable3 = new InputVariable(); inputVariable3.setEnabled(true); inputVariable3.setName("BMI"); inputVariable3.setRange(0.000, 33.000); inputVariable3.addTerm(new Trapezoid("013", 0.000, 0.000, 13.000, 13.000)); inputVariable3.addTerm(new Trapezoid("1314", 13.000, 13.000, 14.000, 14.000)); inputVariable3.addTerm(new Trapezoid("1415", 14.000, 14.000, 15.000, 15.000)); inputVariable3.addTerm(new Trapezoid("1516", 15.000, 15.000, 16.000, 16.000)); inputVariable3.addTerm(new Trapezoid("1617", 16.000, 16.000, 17.000, 17.000)); inputVariable3.addTerm(new Trapezoid("1718", 17.000, 17.000, 18.000, 18.000)); inputVariable3.addTerm(new Trapezoid("1819", 18.000, 18.000, 19.000, 19.000)); inputVariable3.addTerm(new Trapezoid("1920", 19.000, 19.000, 20.000, 20.000)); inputVariable3.addTerm(new Trapezoid("2021", 20.000, 20.000, 21.000, 21.000)); inputVariable3.addTerm(new Trapezoid("2122", 21.000, 21.000, 22.000, 22.000)); inputVariable3.addTerm(new Trapezoid("2223", 22.000, 22.000, 23.000, 23.000)); inputVariable3.addTerm(new Trapezoid("2324", 23.000, 23.000, 24.000, 24.000)); inputVariable3.addTerm(new Trapezoid("2425", 24.000, 24.000, 25.000, 25.000)); inputVariable3.addTerm(new Trapezoid("2526", 25.000, 25.000, 26.000, 26.000)); inputVariable3.addTerm(new Trapezoid("2627", 26.000, 26.000, 27.000, 27.000)); inputVariable3.addTerm(new Trapezoid("2728", 27.000, 27.000, 28.000, 28.000)); inputVariable3.addTerm(new Trapezoid("2829", 28.000, 28.000, 29.000, 29.000)); inputVariable3.addTerm(new Trapezoid("2940", 29.000, 29.000, 40.000, 40.000)); engine.addInputVariable(inputVariable3); OutputVariable outputVariable = new OutputVariable(); outputVariable.setEnabled(true); outputVariable.setName("Interpretation"); outputVariable.setRange(0.000, 100.000); outputVariable.fuzzyOutput().setAccumulation(new Maximum()); outputVariable.setDefuzzifier(new Centroid(200)); outputVariable.setDefaultValue(Double.NaN); outputVariable.setLockValidOutput(false); outputVariable.setLockOutputRange(false); outputVariable.addTerm(new Trapezoid("Risk_for_Underweight", 0.000, 0.000, 2.500, 3.500)); outputVariable.addTerm(new Trapezoid("Obese", 99.000, 99.900, 100.000, 100.000)); outputVariable.addTerm(new Trapezoid("Healthy", 2.500, 3.500, 84.000, 86.000)); outputVariable.addTerm(new Trapezoid("Risk_for_Overweight", 84.000, 85.000, 96.000, 98.000)); outputVariable.addTerm(new Trapezoid("Overweight", 96.500, 97.000, 99.500, 99.900)); engine.addOutputVariable(outputVariable); RuleBlock ruleBlock = new RuleBlock(); ruleBlock.setEnabled(true); ruleBlock.setName(""); ruleBlock.setConjunction(new Minimum()); ruleBlock.setDisjunction(new Maximum()); ruleBlock.setActivation(new Minimum()); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 25 and BMI is 013 then Interpretation is Risk_for_Underweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 25 and BMI is 1314 then Interpretation is Healthy", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 25 and BMI is 1415 then Interpretation is Healthy", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 1520 and BMI is 013 then Interpretation is Risk_for_Underweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 1520 and BMI is 1314 then Interpretation is Risk_for_Underweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 1520 and BMI is 1415 then Interpretation is Risk_for_Underweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 1520 and BMI is 1516 then Interpretation is Risk_for_Underweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 1520 and BMI is 1617 then Interpretation is Risk_for_Underweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 1520 and BMI is 1718 then Interpretation is Healthy", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 1520 and BMI is 1819 then Interpretation is Healthy", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 1520 and BMI is 1920 then Interpretation is Healthy", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 1520 and BMI is 2021 then Interpretation is Healthy", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 1520 and BMI is 2122 then Interpretation is Healthy", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 1520 and BMI is 2223 then Interpretation is Healthy", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 1520 and BMI is 2324 then Interpretation is Healthy", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 1520 and BMI is 2425 then Interpretation is Risk_for_Overweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 1520 and BMI is 2526 then Interpretation is Risk_for_Overweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 1520 and BMI is 2526 then Interpretation is Risk_for_Overweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 1520 and BMI is 2627 then Interpretation is Risk_for_Overweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 1520 and BMI is 2728 then Interpretation is Risk_for_Overweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 1520 and BMI is 2829 then Interpretation is Overweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Female and Age is 1520 and BMI is 2940 then Interpretation is Obese", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 25 and BMI is 013 then Interpretation is Risk_for_Underweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 25 and BMI is 1314 then Interpretation is Risk_for_Underweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 25 and BMI is 1415 then Interpretation is Healthy", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 25 and BMI is 1516 then Interpretation is Healthy", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 25 and BMI is 1617 then Interpretation is Healthy", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 25 and BMI is 1718 then Interpretation is Risk_for_Overweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 25 and BMI is 1819 then Interpretation is Risk_for_Overweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 25 and BMI is 1920 then Interpretation is Overweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 25 and BMI is 2021 then Interpretation is Obese", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 25 and BMI is 2122 then Interpretation is Obese", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 25 and BMI is 2223 then Interpretation is Obese", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 25 and BMI is 2324 then Interpretation is Obese", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 25 and BMI is 2425 then Interpretation is Obese", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 25 and BMI is 2526 then Interpretation is Obese", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 25 and BMI is 2627 then Interpretation is Obese", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 25 and BMI is 2728 then Interpretation is Obese", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 25 and BMI is 2829 then Interpretation is Obese", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 25 and BMI is 2940 then Interpretation is Obese", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 1520 and BMI is 013 then Interpretation is Risk_for_Underweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 1520 and BMI is 1314 then Interpretation is Risk_for_Underweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 1520 and BMI is 1415 then Interpretation is Risk_for_Underweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 1520 and BMI is 1516 then Interpretation is Risk_for_Underweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 1520 and BMI is 1617 then Interpretation is Risk_for_Underweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 1520 and BMI is 1718 then Interpretation is Risk_for_Underweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 1520 and BMI is 1819 then Interpretation is Healthy", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 1520 and BMI is 1920 then Interpretation is Healthy", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 1520 and BMI is 2021 then Interpretation is Healthy", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 1520 and BMI is 2122 then Interpretation is Healthy", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 1520 and BMI is 2223 then Interpretation is Healthy", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 1520 and BMI is 2324 then Interpretation is Risk_for_Overweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 1520 and BMI is 2425 then Interpretation is Risk_for_Overweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 1520 and BMI is 2526 then Interpretation is Risk_for_Overweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 1520 and BMI is 2627 then Interpretation is Risk_for_Overweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 1520 and BMI is 2728 then Interpretation is Overweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 1520 and BMI is 2829 then Interpretation is Overweight", engine)); ruleBlock.addRule(Rule.parse("if Gender is Male and Age is 1520 and BMI is 2940 then Interpretation is Obese", engine)); engine.addRuleBlock(ruleBlock); //No Conjunction or Disjunction is needed engine.configure("AlgebraicProduct", "AlgebraicSum", "AlgebraicProduct", "AlgebraicSum", "Centroid"); StringBuilder status = new StringBuilder(); if (!engine.isReady(status)) throw new RuntimeException("Engine not ready. " + "The following errors were encountered:\n" + status.toString()); for (int i = 0; i < 50; ++i){ double light = inputVariable1.getMinimum() + i * (inputVariable1.range() / 50); inputVariable1.setInputValue(light); double light1 = inputVariable2.getMinimum() + i * (inputVariable2.range() / 50); inputVariable2.setInputValue(light1); double light2 = inputVariable3.getMinimum() + i * (inputVariable3.range() / 50); inputVariable3.setInputValue(light2); engine.process(); engine.process(); FuzzyLite.logger().info(String.format( "input1 = %s, input2 %s, input3 %s -> output = %s", Op.str(light),Op.str(light1), Op.str(light2), Op.str(outputVariable.defuzzify()))); } } }
July 12, 2014 at 08:23 #1187Juan Rada-Vilela (admin)
KeymasterHi,
(1) I think jfuzzylite has an issue with Trapezoids when a=b and c=d, that is, when the trapezoids are rectangles. Please, change your Trapezoid for a Rectangle
new Rectangle(a, c)
.(2) There is nothing fuzzy on your controller. Gender is either male or female. Age is defined in ranges. BMI is also defined in ranges. For any given set of inputs, there will only be one rule activated. All these reasons suggest that you do not need a fuzzy logic controller, especially considering that crisp logic would be far more efficient and have the same results. By crisp logic, I refer in this case to simply programming of if-then rules in your language of choice without any fuzzy logic. Please, read the documentation available at http://fuzzylite.com/downloads/
(3) Since gender and age are clearly defined, that is, there is no uncertainty on either input variable, you could remove the two variables from the engine and significantly reduce the number of rules. You can check their values using crisp logic
if (age > 10 and age < 30) then...
(4) Instead of a single rule block, create two rule blocks, one for females and one for males, enabling and disabling each as required.
(5) If you run into problems, you need to debug your Engine, but first you need to significantly reduce the number of rules and check that each rule is correctly activated.
Note: I have deleted some of the rules in your post to keep it concise.
July 12, 2014 at 14:30 #1188Unknown
MemberThank you very very much for your perfect answer. I wish you luck.
-
This reply was modified 9 years, 3 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.