コード例 #1
0
ファイル: sltbu_fl.java プロジェクト: maciek-slon/Fuzzy
  public static void main(String[] args) {
    Engine engine = new Engine();
    engine.setName("sltbu");

    InputVariable inputVariable1 = new InputVariable();
    inputVariable1.setEnabled(true);
    inputVariable1.setName("distance");
    inputVariable1.setRange(0.000, 25.000);
    inputVariable1.addTerm(new ZShape("near", 1.000, 2.000));
    inputVariable1.addTerm(new SShape("far", 1.000, 2.000));
    engine.addInputVariable(inputVariable1);

    InputVariable inputVariable2 = new InputVariable();
    inputVariable2.setEnabled(true);
    inputVariable2.setName("control1");
    inputVariable2.setRange(-0.785, 0.785);
    engine.addInputVariable(inputVariable2);

    InputVariable inputVariable3 = new InputVariable();
    inputVariable3.setEnabled(true);
    inputVariable3.setName("control2");
    inputVariable3.setRange(-0.785, 0.785);
    engine.addInputVariable(inputVariable3);

    OutputVariable outputVariable = new OutputVariable();
    outputVariable.setEnabled(true);
    outputVariable.setName("control");
    outputVariable.setRange(-0.785, 0.785);
    outputVariable.fuzzyOutput().setAccumulation(new Maximum());
    outputVariable.setDefuzzifier(new WeightedAverage());
    outputVariable.setDefaultValue(Double.NaN);
    outputVariable.setLockValidOutput(false);
    outputVariable.setLockOutputRange(false);
    outputVariable.addTerm(
        Linear.create("out1mf1", engine.getInputVariables(), 0.000, 0.000, 1.000, 0.000));
    outputVariable.addTerm(
        Linear.create("out1mf2", engine.getInputVariables(), 0.000, 1.000, 0.000, 0.000));
    engine.addOutputVariable(outputVariable);

    RuleBlock ruleBlock = new RuleBlock();
    ruleBlock.setEnabled(true);
    ruleBlock.setName("");
    ruleBlock.setConjunction(new AlgebraicProduct());
    ruleBlock.setDisjunction(new Maximum());
    ruleBlock.setActivation(new AlgebraicProduct());
    ruleBlock.addRule(Rule.parse("if distance is near then control is out1mf1", engine));
    ruleBlock.addRule(Rule.parse("if distance is far then control is out1mf2", engine));
    engine.addRuleBlock(ruleBlock);
  }
コード例 #2
0
ファイル: membrn1.java プロジェクト: 9468305/fuzzylite
  public static void main(String[] args) {
    Engine engine = new Engine();
    engine.setName("anfis");

    InputVariable inputVariable1 = new InputVariable();
    inputVariable1.setEnabled(true);
    inputVariable1.setName("in_n1");
    inputVariable1.setRange(1.000, 31.000);
    inputVariable1.addTerm(new Bell("in1mf1", 2.253, 16.220, 5.050));
    inputVariable1.addTerm(new Bell("in1mf2", 31.260, 15.021, 1.843));
    engine.addInputVariable(inputVariable1);

    InputVariable inputVariable2 = new InputVariable();
    inputVariable2.setEnabled(true);
    inputVariable2.setName("in_n2");
    inputVariable2.setRange(1.000, 31.000);
    inputVariable2.addTerm(new Bell("in2mf1", 0.740, 15.021, 1.843));
    inputVariable2.addTerm(new Bell("in2mf2", 29.747, 16.220, 5.050));
    engine.addInputVariable(inputVariable2);

    OutputVariable outputVariable = new OutputVariable();
    outputVariable.setEnabled(true);
    outputVariable.setName("out1");
    outputVariable.setRange(-0.334, 1.000);
    outputVariable.fuzzyOutput().setAccumulation(null);
    outputVariable.setDefuzzifier(new WeightedAverage("TakagiSugeno"));
    outputVariable.setDefaultValue(Double.NaN);
    outputVariable.setLockPreviousOutputValue(false);
    outputVariable.setLockOutputValueInRange(false);
    outputVariable.addTerm(Linear.create("out1mf1", engine, 0.026, 0.071, -0.615));
    outputVariable.addTerm(Linear.create("out1mf2", engine, -0.036, 0.036, -1.169));
    outputVariable.addTerm(Linear.create("out1mf3", engine, -0.094, 0.094, 2.231));
    outputVariable.addTerm(Linear.create("out1mf4", engine, -0.071, -0.026, 2.479));
    engine.addOutputVariable(outputVariable);

    RuleBlock ruleBlock = new RuleBlock();
    ruleBlock.setEnabled(true);
    ruleBlock.setName("");
    ruleBlock.setConjunction(new AlgebraicProduct());
    ruleBlock.setDisjunction(null);
    ruleBlock.setActivation(null);
    ruleBlock.addRule(
        Rule.parse("if in_n1 is in1mf1 and in_n2 is in2mf1 then out1 is out1mf1", engine));
    ruleBlock.addRule(
        Rule.parse("if in_n1 is in1mf1 and in_n2 is in2mf2 then out1 is out1mf2", engine));
    ruleBlock.addRule(
        Rule.parse("if in_n1 is in1mf2 and in_n2 is in2mf1 then out1 is out1mf3", engine));
    ruleBlock.addRule(
        Rule.parse("if in_n1 is in1mf2 and in_n2 is in2mf2 then out1 is out1mf4", engine));
    engine.addRuleBlock(ruleBlock);
  }
コード例 #3
0
  // Funcion para imprimir el Fenotipo por pantalla
  // Imprimimos tanto los puntos de las ecuaciones de la recta de cada valor para cada atributo como
  // las reglas del motor de logica borrosa
  public void printFenotipo() {
    System.out.println("Fenotipo: ");
    System.out.println(
        "Distancia - CERCA - ("
            + mCromosoma[0]
            + ","
            + mCromosoma[1]
            + ","
            + mCromosoma[2]
            + ","
            + mCromosoma[3]
            + ")");
    System.out.println(
        "Distancia - NORMAL - ("
            + mCromosoma[4]
            + ","
            + mCromosoma[5]
            + ","
            + mCromosoma[6]
            + ","
            + mCromosoma[7]
            + ")");
    System.out.println(
        "Distancia - LEJOR - ("
            + mCromosoma[8]
            + ","
            + mCromosoma[9]
            + ","
            + mCromosoma[10]
            + ","
            + mCromosoma[11]
            + ")");

    System.out.println(
        "Tiempo - CERCA - ("
            + mCromosoma[12]
            + ","
            + mCromosoma[13]
            + ","
            + mCromosoma[14]
            + ","
            + mCromosoma[15]
            + ")");
    System.out.println(
        "Tiempo - NORMAL - ("
            + mCromosoma[16]
            + ","
            + mCromosoma[17]
            + ","
            + mCromosoma[18]
            + ","
            + mCromosoma[19]
            + ")");
    System.out.println(
        "Tiempo - MUCHO - ("
            + mCromosoma[20]
            + ","
            + mCromosoma[21]
            + ","
            + mCromosoma[22]
            + ","
            + mCromosoma[23]
            + ")");

    System.out.println(
        "DistanciaPowerPills - CERCA - ("
            + mCromosoma[24]
            + ","
            + mCromosoma[25]
            + ","
            + mCromosoma[26]
            + ","
            + mCromosoma[27]
            + ")");
    System.out.println(
        "DistanciaPowerPills - NORMAL - ("
            + mCromosoma[28]
            + ","
            + mCromosoma[29]
            + ","
            + mCromosoma[30]
            + ","
            + mCromosoma[31]
            + ")");
    System.out.println(
        "DistanciaPowerPills - LEJOS - ("
            + mCromosoma[32]
            + ","
            + mCromosoma[33]
            + ","
            + mCromosoma[34]
            + ","
            + mCromosoma[35]
            + ")");

    RuleBlock reglas = mFenotipo.getRuleBlock(0);
    for (Rule regla : reglas.getRules()) {
      System.out.println(regla.toString());
    }
  }