Пример #1
0
  /**
   * Name: createClassifier Goal: Evolves a fuzzy system according to given options and dataset
   *
   * @param train_data: the data used to compute performance of a system and provide data
   *     information
   * @param options: the options used to control the genetic algorithm
   * @return boolean: indicates if creation was successful or not
   */
  public boolean createClassifier(Object train_data, String options) {
    try {
      this.setOptions(weka.core.Utils.splitOptions(options));
    } catch (Exception e) {
      this.appendError(this.getClass().getName(), "Option not recognised: " + e.getMessage());
      System.out.println("option non reconnue:");
      System.out.println(e.getMessage());
      return false;
    }

    // construction du classificateur
    // les options sont separee pour plus de lisibilite en cas d'erreur
    Instances data = null;
    if (train_data instanceof String)
      data = DataLoader.loadData(null, null, (String) train_data, true, -1);
    else if (train_data instanceof Instances) data = (Instances) train_data;
    else {
      System.out.println("train data not supported!");
      this.appendError(this.getClass().getName(), "Training data format not supported");
      return false;
    }
    this.data = data;
    Coevolution ce =
        new Coevolution(
            data,
            mutation_rate,
            crossover_rate,
            selection_rate,
            pop_size,
            num_generations,
            is_binary,
            selection_algorithm,
            error_algorithm,
            elitism_rate,
            tournament_size,
            classification_weight,
            error_weight,
            rule_number_weight,
            var_per_rule_weight,
            rule_count);
    fs = ce.evolveSystem();
    fs.setData(data);
    best_fitnesses = ce.getBestFitnesses();
    if (getLogLevel() > 2)
      this.appendInfo(this.getClass().getName(), "Classifier was successfully created and trained");
    return true;
  } /*end createClassifier*/
Пример #2
0
  /**
   * Name: createClassifier Goal: Allows creation, option setting and training of a J48 classifier
   *
   * @param options: the options of the classifier to be set
   * @param train_data: training data for the classifier. May be the path to the file, the file or a
   *     set of instances
   * @return Classifier: returns the trained classifier or null if creation was unsuccessful
   */
  public boolean createClassifier(String options, Object train_data) {
    tree = new J48();
    // set des options
    try {
      String[] opts = weka.core.Utils.splitOptions(options);
      tree.setOptions(opts);
    } catch (Exception e) {
      this.appendError(this.getClass().getName(), "Option not recognised: " + e.getMessage());
      System.out.println("option non reconnue:");
      System.out.println(e.getMessage());
      return false;
    }

    // construction du classificateur
    // les options sont separee pour plus de lisibilite en cas d'erreur
    Instances data = null;
    if (train_data instanceof String)
      data = DataLoader.loadData(null, null, (String) train_data, true, -1);
    else if (train_data instanceof Instances) data = (Instances) train_data;
    else {
      System.out.println("train data not supported!");
      this.appendError(this.getClass().getName(), "Training data format not supported");
      return false;
    }
    try {

      tree.buildClassifier(data);
    } catch (Exception e) {
      this.appendError(
          this.getClass().getName(), "Classifier could not be created: " + e.getMessage());
      System.out.println("le classificateur n'a pas pu etre construit:");
      System.out.println(e.getMessage());
      return false;
    }
    if (getLogLevel() > 2)
      this.appendInfo(this.getClass().getName(), "Classifier was successfully created and trained");

    return true;
  } /*end createClassifier*/
Пример #3
0
  /**
   * Name: main Goal: example of JFuge's usage
   *
   * @param args: not used
   */
  public static void main(String[] args) {
    Instances train_data =
        DataLoader.loadData(
            null,
            null,
            "/Users/numa/NUMA/Dossier Ecole/HEIG/Semestre 7/PDB/code/PDB_Trezzini/src/org/cheminfo/scripting/data/iris_train.arff",
            true,
            -1);
    Instances test_data =
        DataLoader.loadData(
            null,
            null,
            "/Users/numa/NUMA/Dossier Ecole/HEIG/Semestre 7/PDB/code/PDB_Trezzini/src/org/cheminfo/scripting/data/iris_test.arff",
            true,
            -1);
    double mutation_rate = 0.1;
    double crossover_rate = 0.2;
    double selection_rate = -1;
    int num_generations = 100;
    String selection_algorithm = TOURNAMENT_SELECTION;
    String error_algorithm = ERROR_MSE;
    double elitism_rate = 0.1;
    int tournament_size = 10;
    int pop = 200;
    double classification_weight = 1;
    double error_weight = 0;
    double rule_number_weight = 0;
    double var_per_rule_weight = 0.1;
    int rule_count = 5;
    FuzzySystem fs = null;
    double max = 0;
    for (int i = 0; i < 1; i++) {
      Coevolution ce =
          new Coevolution(
              train_data,
              mutation_rate,
              crossover_rate,
              selection_rate,
              pop,
              num_generations,
              false,
              selection_algorithm,
              error_algorithm,
              elitism_rate,
              tournament_size,
              classification_weight,
              error_weight,
              rule_number_weight,
              var_per_rule_weight,
              rule_count);
      FuzzySystem best = ce.evolveSystem();
      System.out.println(best);
      if (best.getFitness() > max) {
        fs = best;
        max = best.getFitness();
      }
      // System.out.println(best);
      System.out.println(i + ": " + best.getFitness());
    }
    System.out.println(fs);
    System.out.println(max);
    double[] classif = fs.classifyInstances(test_data);
    double[][] distrib = fs.distributionForInstances(test_data);
    for (int i = 0; i < classif.length; i++) {
      System.out.println(classif[i]);
    }

    for (int i = 0; i < distrib.length; i++) {
      for (int j = 0; j < distrib[i].length; j++) {
        System.out.print(distrib[i][j] + " ");
      }
      System.out.println();
    }
  } /*end main*/