Package net.sourceforge.jFuzzyLogic.rule

Examples of net.sourceforge.jFuzzyLogic.rule.Variable


      if( terms[i] == null ) {
        // Null function => Nothing to do
        values[i] = Double.NaN;
      } else if( terms[i] instanceof Variable ) {
        // Variable's value
        Variable var = ((Variable) terms[i]);
        if( var.isOutputVarable() ) throw new RuntimeException("Can't use an output variable '" + var.getName() + "' for a function (It may create a race condition)");
        values[i] = var.getValue();
      } else if( terms[i] instanceof String ) {
        // Variable's name
        String name = (String) terms[i];
        // Look it up
        Variable var = fuzzyRuleSet.getVariable(name);
        if( var == null ) throw new RuntimeException("Can't find variable '" + name + "' (Undefined variable or function)");
        if( var.isOutputVarable() ) throw new RuntimeException("Can't use an output variable '" + name + "' for a function (It may create a race condition)");
        // Get value
        values[i] = var.getValue();
      } else if( terms[i] instanceof Double ) {
        // Constant's value
        values[i] = ((Double) terms[i]).doubleValue();
      } else if( terms[i] instanceof MffFunction ) {
        // Function's value
View Full Code Here


    //---
    // Add variable's membership functions' parameters
    //---
    // Iterate over each variable
    for( Iterator<Variable> itVar = fuzzyRuleSet.variablesIterator(); itVar.hasNext(); ) {
      Variable variable = itVar.next();
      parameterListAddVariable(parameterList, variable);
    }

    //---
    // Add rule's weights
View Full Code Here

  /**
   * Inference method
   * Add membershipfunction to deffuzifier (using 'min' as inference)
   */
  public void imply(FuzzyRuleTerm fuzzyRuleTerm, double degreeOfSupport) {
    Variable variable = fuzzyRuleTerm.getVariable();
    Defuzzifier defuzzifier = variable.getDefuzzifier();
    MembershipFunction mf = fuzzyRuleTerm.getMembershipFunction();
    double membership, y, x, aggregated = 0;

    // Both are equal? (both discrete or both continuous?)
    if( mf.isDiscrete() != defuzzifier.isDiscrete() ) throw new RuntimeException("MembershipFunction and Defuzzifier are neither both discrete nor both continuous\n\tTerm: " + fuzzyRuleTerm + "\n\tMembership function: " + mf + "\n\tDefuzzifier: " + defuzzifier + "\n");

    if( mf.isDiscrete() ) {
      //---
      // Discrete case
      //---
      DefuzzifierDiscrete defuzzifierDiscrete = (DefuzzifierDiscrete) defuzzifier;
      MembershipFunctionDiscrete mfd = (MembershipFunctionDiscrete) mf;

      // Add membershipfunction to deffuzifier
      int i, size = mfd.size();
      for( i = 0; i < size; i++ ) {
        // Get 'x' value
        x = mfd.valueX(i);

        // Is term negated?
        if( fuzzyRuleTerm.isNegated() ) membership = 1 - mf.membership(x);
        else membership = mf.membership(x);

        y = imply(degreeOfSupport, membership); // Call to abstract implication method described above

        // Aggregate value
        aggregated = variable.getRuleAggregationMethod().aggregate(defuzzifierDiscrete.getDiscreteValue(x), y);
        defuzzifierDiscrete.setPoint(x, aggregated);
      }
    } else {
      //---
      // Continuous case
      //---
      DefuzzifierContinuous defuzzifierContinuous = (DefuzzifierContinuous) defuzzifier;
      x = defuzzifierContinuous.getMin();
      double step = defuzzifierContinuous.getStepSize();

      // Do some sanitychecks
      if( Double.isNaN(x) || Double.isInfinite(x) ) throw new RuntimeException("Universe minimum not calculated for term '" + fuzzyRuleTerm.getTermName() + "' : " + x);
      if( Double.isNaN(step) || Double.isInfinite(step) ) throw new RuntimeException("Step not calculated for term '" + fuzzyRuleTerm.getTermName() + "' : " + step);

      int i, length = defuzzifierContinuous.getLength();

      // Add membershipfunction to deffuzifier
      for( i = 0; i < length; i++, x += step ) {
        // Is term negated?
        if( fuzzyRuleTerm.isNegated() ) membership = 1 - mf.membership(x);
        else membership = mf.membership(x);

        y = imply(degreeOfSupport, membership); // Call to abstract implication method described above

        // Aggregate value
        aggregated = variable.getRuleAggregationMethod().aggregate(defuzzifierContinuous.getValue(i), y);
        defuzzifierContinuous.setValue(i, aggregated);
      }
    }
  }
View Full Code Here

    inputList=new ArrayList<MyNode>();
    outputList=new ArrayList<MyNode>();

    for ( Iterator<Variable> flavoursIter = item; flavoursIter.hasNext(); )
    {
        Variable var=flavoursIter.next();

        MyNode node = new MyNode();
        node.description=var.getName();

        if (var.isOutputVarable())
        {
          outputList.add(node);
        }else
        {
          inputList.add(node);
View Full Code Here

    if (o.equals(showGraphs))
    {

      for( Iterator<Variable> it = fuzzyRuleSet.variablesIterator(); it.hasNext(); )
      {
          Variable var = it.next();

          JFreeChart chart=var.chart(false);

          DialogChart frm=getChartDialog(var, null, 0);
          if (showGraphs.getValue())
          {
            if (frm==null)
            {
              String str="INPUT : ";
              if (var.isOutputVarable()) str="OUTPUT : ";
              frm = new DialogChart(null, false, str+var.getName() );
              frm.init(chart, var, null);
              liste.add(frm);
            }

View Full Code Here

  /**
   * Inference method
   * Add membershipfunction to deffuzifier (using 'min' as inference)
   */
  public void imply(RuleTerm fuzzyRuleTerm, RuleAccumulationMethod ruleAccumulationMethod, double degreeOfSupport) {
    Variable variable = fuzzyRuleTerm.getVariable();
    Defuzzifier defuzzifier = variable.getDefuzzifier();
    MembershipFunction mf = fuzzyRuleTerm.getMembershipFunction();
    double membership, y, x, aggregated = 0;

    // Both are equal? (both discrete or both continuous?)
    if( mf.isDiscrete() != defuzzifier.isDiscrete() ) throw new RuntimeException("MembershipFunction and Defuzzifier are neither both discrete nor both continuous\n\tTerm: " + fuzzyRuleTerm + "\n\tMembership function: " + mf + "\n\tDefuzzifier: " + defuzzifier + "\n");
View Full Code Here

   */
  public Variable getVariable(String varName) {
    FunctionBlock defaultFunctionBlock = getFunctionBlock(null);
    if( defaultFunctionBlock == null ) throw new RuntimeException("Default function block not found!");

    Variable var = defaultFunctionBlock.getVariable(varName);
    if( var == null ) throw new RuntimeException("Variable '" + varName + "' not found!");

    return var;
  }
View Full Code Here

   */
  public void setVariable(String varName, double value) {
    FunctionBlock defaultFunctionBlock = getFunctionBlock(null);
    if( defaultFunctionBlock == null ) throw new RuntimeException("Default function block not found!");

    Variable var = defaultFunctionBlock.getVariable(varName);
    if( var == null ) throw new RuntimeException("Variable '" + varName + "' not found!");

    var.setValue(value);
  }
View Full Code Here

  public static void main(String args[]) {
    FIS fis = FIS.load("fcl/cinthia.fcl", true);

    // Get Function block and Variables
    FunctionBlock fb = fis.getFunctionBlock(null);
    Variable meanGood = fb.getVariable("meanGood");
    Variable stdGood = fb.getVariable("stdGood");
    Variable inVar = fb.getVariable("inVar");

    // Change values
    for( double mean = 3, std = 3; mean < 8; mean += 1.0, std -= 0.5 ) {
      // Change variables => changes fuzzyfication function
      meanGood.setValue(mean);
      stdGood.setValue(std);

      inVar.chart(true); // Show
    }
  }
View Full Code Here

    Iterator<Variable> iter = vars.iterator();
    for( int ix = 0; ix < nx1; ix++ )
      for( int iy = 0; iy < ny1; iy++ ) {
        if( !iter.hasNext() ) return;
        Variable var = iter.next();

        rect.setFrame(ix * plotSizex, iy * plotSizey, plotSizex, plotSizey);
        chart(var).draw((Graphics2D) g, rect);

      }
View Full Code Here

TOP

Related Classes of net.sourceforge.jFuzzyLogic.rule.Variable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.