/** * 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; }
@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; }
/** 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"); } }
/** This method is for debug */ public void debug() { R.debug(); }
/** * 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); }
/** * 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()); }
/** * 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); }
/** * This method return the number of consequents of the fuzzy model * * @return The number of consequents */ int numConsequents() { return R.numConsequents(); }
/** * This methos return the size of the fuzzy model * * @return The size of the fuzzy model */ int size() { return R.size(); }