home Forums # Technical Support Help to resolve error

Tagged: 

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #2596
    Unknown
    Member

    I did below function but error occurred while run time..
    ” java runtime exception consequent expected output variable but found <tip>”

    public String fuzzy(){

    Engine engine = new Engine();
    engine.setName(“simple-dimmer”);

    InputVariable service= new InputVariable();
    service.setName(“service”);
    service.setRange(0.000, 1.000);
    service.addTerm(new Triangle(“poor”, 0.000, 0.250, 0.500));
    service.addTerm(new Triangle(“good”, 0.250, 0.500, 0.750));
    service.addTerm(new Triangle(“excellent”, 0.500, 0.750, 1.000));
    engine.addInputVariable(service);

    OutputVariable tip = new OutputVariable();
    tip.setName(“Power”);
    tip.setRange(0.000, 1.000);
    tip.setDefaultValue(Double.NaN);
    tip.addTerm(new Triangle(“LOW”, 0.000, 0.250, 0.500));
    tip.addTerm(new Triangle(“MEDIUM”, 0.250, 0.500, 0.750));
    tip.addTerm(new Triangle(“HIGH”, 0.500, 0.750, 1.000));
    engine.addOutputVariable(tip);

    RuleBlock ruleBlock = new RuleBlock();
    ruleBlock.addRule(Rule.parse(“if service is poor then tip is HIGH”, engine));
    ruleBlock.addRule(Rule.parse(“if service is good then tip is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if service is excellent then tip is LOW”, engine));
    engine.addRuleBlock(ruleBlock);

    engine.configure(“”, “”, “Minimum”, “Maximum”, “Centroid”, null);
    engine.setInputValue(“service”,0.1);
    engine.process();
    return String.format(“0.3f”, engine.getOutputValue(“Power”));
    }

    Please help me to resolve this problem….

    #2597
    Unknown
    Member

    I did changes now it work well but output result is not working well

    public static String fuzzy(){

    Engine engine = new Engine();
    engine.setName(“simple-dimmer”);

    InputVariable service= new InputVariable();
    service.setName(“service”);
    service.setRange(0.000, 1.000);
    service.addTerm(new Triangle(“poor”, 0.000, 0.250, 0.500));
    service.addTerm(new Triangle(“good”, 0.250, 0.500, 0.750));
    service.addTerm(new Triangle(“excellent”, 0.500, 0.750, 1.000));
    engine.addInputVariable(service);

    OutputVariable tip = new OutputVariable();
    tip.setName(“Power”);
    tip.setRange(0.000, 1.000);
    tip.setDefaultValue(Double.NaN);
    tip.addTerm(new Triangle(“LOW”, 0.000, 0.250, 0.500));
    tip.addTerm(new Triangle(“MEDIUM”, 0.250, 0.500, 0.750));
    tip.addTerm(new Triangle(“HIGH”, 0.500, 0.750, 1.000));
    engine.addOutputVariable(tip);

    RuleBlock ruleBlock = new RuleBlock();
    ruleBlock.addRule(Rule.parse(“if service is poor then Power is HIGH”, engine));
    ruleBlock.addRule(Rule.parse(“if service is good then Power is MEDIUM”, engine));
    ruleBlock.addRule(Rule.parse(“if service is excellent then Power is LOW”, engine));
    engine.addRuleBlock(ruleBlock);

    engine.configure(“”, “”, “Minimum”, “Maximum”, “Centroid”, null);
    engine.setInputValue(“service”,0.25);
    engine.process();
    return String.format(“0.3f”, engine.getOutputValue(“Power”));
    }

    #2598
    Unknown
    Member

    I need get output of Power?
    LOW or MEDIUM or HIGH

    #2600

    Hi,

    I think you should configure your engine with engine.configure(“”, “”, “Minimum”, “Maximum”, “Centroid”, "General");

    as for obtaining a linguistic result, you could do something like: engine.getOutputVariable("Power").highestActivatedTerm().getTerm().getName() It would be a good idea to check the source code of jfuzzylite. Specifically, the following:

    (1) OutputVariable: https://github.com/fuzzylite/jfuzzylite/blob/master/jfuzzylite/src/main/java/com/fuzzylite/variable/OutputVariable.java
    (2) The fuzzy output value in an OutputVariable is an Aggregated term:
    https://github.com/fuzzylite/jfuzzylite/blob/master/jfuzzylite/src/main/java/com/fuzzylite/term/Aggregated.java
    (3) The highestActivatedTerm is an Active term: https://github.com/fuzzylite/jfuzzylite/blob/master/jfuzzylite/src/main/java/com/fuzzylite/term/Activated.java

    Cheers.

    #2606
    Unknown
    Member

    Thank you for reply.but there is no
    engine.configure(“”, “”, “Minimum”, “Maximum”,”Centroid”, “General”);
    engine.getOutputVariable(“Power”).highestActivatedTerm().getTerm().getName(); such way

    under engine.getOutputVariable(“Power”) there is no highestActivatedTerm() fucntion.

    How can i get this??

    #2607
    Unknown
    Member

    public static String fuzzy() {

    Engine engine = new Engine();
    engine.setName(“simple-dimmer”);
    InputVariable service = new InputVariable();
    service.setName(“service”);
    service.setRange(0.000, 1.000);
    service.addTerm(new Triangle(“poor”, 0.000, 0.250, 0.500));
    service.addTerm(new Triangle(“good”, 0.250, 0.500, 0.750));
    service.addTerm(new Triangle(“excellent”, 0.500, 0.750, 1.000));
    engine.addInputVariable(service);

    OutputVariable snake = new OutputVariable();
    snake.setName(“snake”);
    snake.setRange(1, 3);
    snake.setDefaultValue(Double.NaN);
    snake.addTerm(new Constant(“Cobra”, 1));
    snake.addTerm(new Constant(“SEA”, 2));
    snake.addTerm(new Constant(“WIFE”, 3));
    engine.addOutputVariable(snake);

    RuleBlock ruleBlock = new RuleBlock();
    ruleBlock.setName(“rule”);
    ruleBlock.addRule(Rule.parse(“if service is poor then snake is Cobra”, engine));
    ruleBlock.addRule(Rule.parse(“if service is good then snake is SEA”, engine));
    ruleBlock.addRule(Rule.parse(“if service is excellent then snake is WIFE”, engine));
    engine.addRuleBlock(ruleBlock);

    engine.configure(“”, “”, “Minimum”, “Maximum”,”Centroid”, “General”);
    engine.setInputValue(“service”, .7);
    engine.process();
    engine.getOutputVariable(“snake”);
    System.out.print(engine.getOutputValue(“snake”));
    return String.format(“”, engine.getOutputValue(“snake”));
    }

    i need to get extract out put variable.
    Cobra or SEA or WIFE please help me to do that

    #2608

    Hi,

    I think you may be using version 5.0. Maybe you should take a look at the current version.

    https://github.com/fuzzylite/jfuzzylite/blob/master/jfuzzylite/src/main/java/com/fuzzylite/Engine.java#L124

    Cheers.

    #2609
    Unknown
    Member

    Thank you for reply i have used lib/jfuzzylite-6.0.1.jar is this old version.

    #2610
    Unknown
    Member

    Thank you for your reply.I found way to get it but some null point exception.

    line engine.getOutputVariable(“snake”).fuzzyOutput().highestActivatedTerm()
    //Exception in thread “main” java.lang.NullPointerException

    import com.fuzzylite.Engine;
    import com.fuzzylite.rule.Rule;
    import com.fuzzylite.rule.RuleBlock;
    import com.fuzzylite.term.Constant;
    import com.fuzzylite.term.Triangle;
    import com.fuzzylite.variable.InputVariable;
    import com.fuzzylite.variable.OutputVariable;
    import com.fuzzylite.term.Activated;

    public class Test {

    public static void main(String[] args) {

    String inputOne = “colorOne”;
    String inputTwo = “ColorTwo”;
    String out = fuzzy();
    System.out.println(out);
    }

    public static String fuzzy() {

    Engine engine = new Engine();
    engine.setName(“simple-dimmer”);
    InputVariable service = new InputVariable();
    service.setName(“service”);
    service.setRange(0.000, 1.000);
    service.addTerm(new Triangle(“poor”, 0.000, 0.250, 0.500));
    service.addTerm(new Triangle(“good”, 0.250, 0.500, 0.750));
    service.addTerm(new Triangle(“excellent”, 0.500, 0.750, 1.000));
    engine.addInputVariable(service);

    OutputVariable snake = new OutputVariable();
    snake.setName(“snake”);
    snake.setRange(1, 3);
    snake.setDefaultValue(Double.NaN);
    snake.addTerm(new Constant(“Cobra”, 1));
    snake.addTerm(new Constant(“SEA”, 2));
    snake.addTerm(new Constant(“WIFE”, 3));
    engine.addOutputVariable(snake);

    RuleBlock ruleBlock = new RuleBlock();
    ruleBlock.setName(“rule”);
    ruleBlock.addRule(Rule.parse(“if service is poor then snake is Cobra”, engine));
    ruleBlock.addRule(Rule.parse(“if service is good then snake is SEA”, engine));
    ruleBlock.addRule(Rule.parse(“if service is excellent then snake is WIFE”, engine));
    engine.addRuleBlock(ruleBlock);

    engine.configure(“”, “”, “Minimum”, “Maximum”,”Centroid”, “General”);
    engine.setInputValue(“service”,0.51 );
    engine.process();

    System.out.print(engine.getOutputVariable(“snake”).fuzzyOutputValue());
    // 0.000/Cobra + 0.960/SEA + 0.040/WIFE
    System.out.print(engine.getOutputVariable(“snake”).fuzzyOutput().highestActivatedTerm().getTerm().getName());
    //Exception in thread “main” java.lang.NullPointerException

    return String.format(“”, engine.getOutputVariable(“snake”).fuzzyOutputValue());
    }
    }

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