Exemplo n.º 1
0
 /**
  * It returns the algorithm classification output given an input example
  *
  * @param example double[] The input example
  * @return String the output generated by the algorithm
  */
 private String classificationOutput(double[] example) {
   String output = new String("?");
   /**
    * Here we should include the algorithm directives to generate the classification output from
    * the input example
    */
   int clas = ruleBase.FRM(example);
   if (clas >= 0) {
     output = train.getOutputValue(clas);
   }
   return output;
 }
Exemplo n.º 2
0
  @SuppressWarnings("rawtypes")
  boolean evalRules(Object asset) {
    StatelessSession session = ruleBase.newStatelessSession();
    StatelessSessionResult result = session.executeWithResults(asset);

    java.util.Iterator objects = result.iterateObjects();
    while (objects.hasNext()) {
      if (objects.next() instanceof Allow) {
        return true;
      }
    }
    return false;
  }
Exemplo n.º 3
0
  /** It launches the algorithm */
  public void execute() {
    if (somethingWrong) { // We do not execute the program
      System.err.println("An error was found, either the data-set has missing values.");
      System.err.println(
          "Please remove the examples with missing data or apply a MV preprocessing.");
      System.err.println("Aborting the program");
      // We should not use the statement: System.exit(-1);
    } else {
      // We do here the algorithm's operations

      nClasses = train.getnClasses();

      dataBase =
          new DataBase(
              train.getnInputs(), train.getRanges(), train.varNames(), train.getNominals());
      Population pobl =
          new Population(
              train,
              dataBase,
              populationSize,
              nRules,
              crossProb,
              ruleWeight,
              combinationType,
              inferenceType,
              p_DC,
              michProb);
      pobl.Generation(this.nGenerations);

      dataBase.writeFile(this.fileDB);
      ruleBase = pobl.bestRB();
      ruleBase.writeFile(this.fileBR);

      // Finally we should fill the training and test output files
      double accTra = doOutput(this.val, this.outputTr);
      double accTst = doOutput(this.test, this.outputTst);

      System.out.println("Accuracy obtained in training: " + accTra);
      System.out.println("Accuracy obtained in test: " + accTst);
      System.out.println("Algorithm Finished");
    }
  }
Exemplo n.º 4
0
 /** This method is for debug */
 public void debug() {
   R.debug();
 }
Exemplo n.º 5
0
 /**
  * This method defuzzified the output and return a value
  *
  * @param x The output
  * @return
  */
 public double output(double[] x) {
   return R.defuzzify(R.output(x), defuzType);
 }
Exemplo n.º 6
0
 /**
  * This method assign the values of the fuzzy rule to another one
  *
  * @param i The position of the rule
  * @param b A fuzzy rule
  */
 void setComponent(int i, FuzzyRule b) {
   R.setComponent(i, b.clone());
 }
Exemplo n.º 7
0
 /**
  * This method obtain the consequent and the weight of the rule
  *
  * @param n The position of the rule
  * @return
  */
 FuzzyRule getComponent(int n) {
   return R.getComponent(n);
 }
Exemplo n.º 8
0
 /**
  * This method return the number of consequents of the fuzzy model
  *
  * @return The number of consequents
  */
 int numConsequents() {
   return R.numConsequents();
 }
Exemplo n.º 9
0
 /**
  * This methos return the size of the fuzzy model
  *
  * @return The size of the fuzzy model
  */
 int size() {
   return R.size();
 }