home Forums # Technical Support logical operators grammers , error in numbers of operands

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #979
    Unknown
    Member

    I am a beginner in fuzzylite
    when i using it in java (eclipse IDE) , I receive below error
    please help me

    03-06 17:19:49.155: W/System.err(712): java.lang.RuntimeException: [syntax error] logical operator <and> expects two operands, but found <3>
    03-06 17:19:49.155: W/System.err(712): 	at com.fuzzylite.rule.Antecedent.load(Unknown Source)
    03-06 17:19:49.155: W/System.err(712): 	at com.fuzzylite.rule.Rule.parse(Unknown Source)

    and my rules is :

    
    	RuleBlock ruleBlock = new RuleBlock();
    					  	 ruleBlock.addRule(Rule.parse("if chestpain is TYPIC and restpress is MIN and serum is MINLEVEL and smoke is LOWPOSSIBILITY and sugar is LEVELNO and maxrate is MINRATE and restrate is LOWRATE then angin  is MILD", engine));
    					  	 ruleBlock.addRule(Rule.parse("if chestpain is ASYMPTOMATIC and restpress is MIN and serum is MAXLEVEL and smoke is LOWPOSSIBILITY and sugar is LEVELNO and  maxrate is MINRATE and restrate is HIGHRATE then angin is MASSIVE", engine)); .... and more
    • This topic was modified 9 years, 6 months ago by Unknown.
    #982

    Hi,

    Could you please post all the code setting up your engine?

    #985
    Unknown
    Member

    hello again
    yes of course
    thank you
    Great help to me

    		
    					try{
    						
    						
    						
    					      Engine engine = new Engine("hearter");
    					      InputVariable chestpain = new InputVariable();
    					      chestpain.setName("chestpain");
    					      chestpain.setRange(0.000, 4.000);
    					      chestpain.addTerm(new Triangle("TYPIC", 1.000, 1.000));
    					      chestpain.addTerm(new Triangle("ATYPIC", 2.0, 2.000));
    					      chestpain.addTerm(new Triangle("NONANGIN", 3.000, 3.000));
    					      chestpain.addTerm(new Triangle("ASYMPTOMATIC", 4.000, 4.000));
    					      engine.addInputVariable(chestpain);
    					      
    					     					
    					      InputVariable restpress = new InputVariable();
    					      restpress.setName("restpress");
    					      restpress.setRange(100.000, 200.000);
    					      restpress.addTerm(new Triangle("MIN", 100.000, 155.000));
    					      restpress.addTerm(new Triangle("MAX", 140.000, 200.000));
    					      engine.addInputVariable(restpress);
    					      
    					      InputVariable serum = new InputVariable();
    					      serum.setName("serum");
    					      serum.setRange(150.000, 300.000);
    					      serum.addTerm(new Triangle("MINLEVEL", 150.000, 250.000));
    					      serum.addTerm(new Triangle("MAXLEVEL", 240.000, 300.000));
    					      engine.addInputVariable(serum);
    					      
    					      InputVariable smoke = new InputVariable();
    					      smoke.setName("smoke");
    					      smoke.setRange(0.000, 100.000);
    					      smoke.addTerm(new Triangle("LOWPOSSIBILITY", 0.000, 40.000));
    					      smoke.addTerm(new Triangle("HIGHPOSSIBILITY", 35.000, 100.000));
    					      engine.addInputVariable(smoke);
    					      
    					      InputVariable sugar = new InputVariable();
    					      sugar.setName("sugar");
    					      sugar.setRange(10.000, 200.000);
    					      sugar.addTerm(new Triangle("LEVELNO", 10.000, 130.000));
    					      sugar.addTerm(new Triangle("LEVELYES", 125.000, 200.000));
    					      engine.addInputVariable(sugar);
    					      
    					      InputVariable maxrate = new InputVariable();
    					      maxrate.setName("maxrate");
    					      maxrate.setRange(40.000, 90.000);
    					      maxrate.addTerm(new Triangle("MINRATE", 40.000, 80.000));
    					      maxrate.addTerm(new Triangle("MAXRATE", 65.000, 85.000));
    					      engine.addInputVariable(maxrate);
    					      
    					      InputVariable restrate = new InputVariable();
    					      restrate.setName("restrate");
    					      restrate.setRange(70.000, 200.000);
    					      restrate.addTerm(new Triangle("LOWRATE", 70.000, 150.000));
    					      restrate.addTerm(new Triangle("HIGHRATE", 145.000, 200.000));
    					      engine.addInputVariable(restrate);
    					      
    
    					      OutputVariable angin = new OutputVariable();
    					      angin.setName("angin");
    					      angin.setRange(0.000, 4.000);
    					      angin.setDefaultValue(Double.NaN);
    					      angin.addTerm(new Triangle("MILD", 0.000, 2.000));
    					      angin.addTerm(new Triangle("MASSIVE", 2.000, 4.000));
    					  	  engine.addOutputVariable(angin);
    					      
    					  	RuleBlock ruleBlock = new RuleBlock();
    					  	 ruleBlock.addRule(Rule.parse("if chestpain is TYPIC and restpress is MIN and serum is MINLEVEL and smoke is LOWPOSSIBILITY and sugar is LEVELNO and maxrate is MINRATE and restrate is LOWRATE then angin  is MILD", engine));
    					  	 ruleBlock.addRule(Rule.parse("if chestpain is ASYMPTOMATIC and restpress is MIN and serum is MAXLEVEL and smoke is LOWPOSSIBILITY and sugar is LEVELNO and  maxrate is MINRATE and restrate is HIGHRATE then angin is MASSIVE", engine));
    					  	 ruleBlock.addRule(Rule.parse("if chestpain is NONANGIN and restpress is MIN and serum is MAXLEVEL and smoke is HIGHPOSSIBILITY and sugar is LEVELNO and  maxrate is MINRATE and restrate is HIGHRATE then angin is MILD", engine));
    					   	 ruleBlock.addRule(Rule.parse("if chestpain is ATYPIC and restpress is MIN and serum is MAXLEVEL and smoke is LOWPOSSIBILITY and sugar is LEVELNO and  maxrate is MINRATE and restrate is HIGHRATE then angin is MILD", engine));
    					   	 ruleBlock.addRule(Rule.parse("if chestpain is ATYPIC and restpress is MIN and serum is MAXLEVEL and smoke is HIGHPOSSIBILITY and sugar is LEVELNO and  maxrate is MINRATE and restrate is LOWRATE then angin is MILD", engine));
    					   	 ruleBlock.addRule(Rule.parse("if chestpain is ASYMPTOMATIC and restpress is MAX and serum is MINLEVEL and smoke is LOWPOSSIBILITY and sugar is LEVELNO and  maxrate is MINRATE and restrate is LOWRATE then angin is MILD", engine));
    					   	 ruleBlock.addRule(Rule.parse("if chestpain is ASYMPTOMATIC or restpress is MAX or serum is MAXLEVEL and smoke is LOWPOSSIBILITY or sugar is LEVELNO or  minrate is MINRATE or restrate is HIGHRATE then angin is MASSIVE", engine));
    					   	 ruleBlock.addRule(Rule.parse("if chestpain is ASYMPTOMATIC and restpress is MAX and serum is MAXLEVEL and smoke is HIGHPOSSIBILITY and sugar is LEVELNO and  maxrate is MINRATE and restrate is LOWRATE then angin is MILD",engine));
    					   	 ruleBlock.addRule(Rule.parse("if chestpain is ATYPIC and restpress is MIN and serum is MAXLEVEL and smoke is HIGHPOSSIBILITY and sugar is LEVELNO and  maxrate is MINRATE and restrate is LOWRATE then angin is MILD",engine));
    					   	 ruleBlock.addRule(Rule.parse("if chestpain is NONANGIN and restpress is MIN and serum is MAXLEVEL and smoke is HIGHPOSSIBILITY and sugar is LEVELNO and  maxrate is MINRATE and restrate is LOWRATE then angin is MILD",engine));
    					   	 ruleBlock.addRule(Rule.parse("if chestpain is NONANGIN and restpress is MAX and serum is MAXLEVEL and smoke is HIGHPOSSIBILITY and sugar is LEVELYES and  maxrate is MAXRATE and restrate is HIGHRATE then angin is MASSIVE",engine));
    					   	
    					  
    					  	  
    					     engine.addRuleBlock(ruleBlock);
    					     
    					     engine.configure("", "", "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());
    
    					    
    					     
    					        
    					         chestpain.setInputValue(selectedchestpain);
    					         restpress.setInputValue(numrestingpress);
    					         serum.setInputValue(numcholeserum);
    					         smoke.setInputValue(selectedsmoke);
    					         sugar.setInputValue(selectedfasting);
    					         maxrate.setInputValue(nummaxrate);
    					         restrate.setInputValue(numrestrate);
    					         engine.process();
    					  
    					         double result= angin.defuzzify();
    					         String resultstr= String.valueOf(result);
    					         FuzzyLite.logger().info(String.format("A -> Power.output = %s", angin.defuzzify()));
    					         Log.d("output", resultstr);
    					     }
    
    					      
    ////////////////////////////
    							
    			
    						
    					
    					catch(Exception e)
    					{
    						e.printStackTrace();
    					Log.d("catch error", "error in fuzzy system");
    					}
    						
    					
    #986

    Hi,

    the problem is in rule:

    if (chestpain is ASYMPTOMATIC or restpress is MAX or serum is MAXLEVEL) and (smoke is LOWPOSSIBILITY or sugar is LEVELNO or minrate is MINRATE or restrate is HIGHRATE) then angin is MASSIVE

    where you refer to minrate, but you have not added any variable named minrate to the engine.

    In addition, please make sure you have considered the precedence order of the connectors and|or in your rules. If unsure, please group propositions in parenthesis as I have done (if that grouping makes sense to your problem).

    Notice also that since you are using and|or in your rules, you have to set the respective conjunction and disjunction operators of your choice. For example,

    engine.configure("AlgebraicProduct", "AlgebraicSum", "AlgebraicProduct", "AlgebraicSum", "Centroid");

    Cheers.

    #988
    Unknown
    Member

    thank you very much Juan
    you are a great person
    my problem resolved

    #1000
    Unknown
    Member

    Hi
    Sorry , i have a new question
    for this rule :

    ruleBlock.addRule(Rule.parse("if chestpain is ASYMPTOMATIC or restpress is MAX or serum is MAXLEVEL and smoke is LOWPOSSIBILITY or sugar is LEVELNO or maxrate is MINRATE or restrate is HIGHRATE then angin is MASSIVE", engine));

    How can i set the engine parameters? is it true? :

    engine.configure("TNorm", "SNorm", "TNorm", "SNorm", "Centroid");

    thanks a lot

    #1001

    Hi,

    Please check QtFuzzyLite to have an idea which TNorms and SNorms to use. The configuration requires case-sensitive names of the TNorms and SNorms. For example,

    engine.configure("AlgebraicProduct", "AlgebraicSum", "AlgebraicProduct", "AlgebraicSum", "Centroid");

    Please, also notice that you should group the conditions in the rules within parenthesis as I mentioned before:

    if (chestpain is ASYMPTOMATIC or restpress is MAX or serum is MAXLEVEL) and (smoke is LOWPOSSIBILITY or sugar is LEVELNO or minrate is MINRATE or restrate is HIGHRATE) then angin is MASSIVE

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.