/** Creates a new FeatureGenerator for a given function name. */
 public static FeatureGenerator createGeneratorForFunction(String functionName) {
   if (functionName == null) return null;
   Class genClass = generatorMap.get(functionName);
   if (genClass == null) {
     if (functionName.startsWith(ConstantGenerator.FUNCTION_NAME)) {
       FeatureGenerator gen = new ConstantGenerator();
       gen.setFunction(functionName);
       return gen;
     } else {
       return null;
     }
   } else {
     try {
       FeatureGenerator gen = (FeatureGenerator) genClass.newInstance();
       gen.setFunction(functionName);
       return gen;
     } catch (Exception e) {
       // LogService.getGlobal().log("Cannot instantiate '" + genClass.getName() + "'",
       // LogService.ERROR);
       LogService.getRoot()
           .log(
               Level.SEVERE,
               "com.rapidminer.generator.FeatureGenerator.instantiating_error",
               genClass.getName());
       return null;
     }
   }
 }
 /**
  * A FeatureGenerator equals another FeatureGenerator if its class is equal and its arguments are
  * equal and its function names are equal.
  */
 @Override
 public boolean equals(Object o) {
   if (o == null) // necessary here because otherwise the next line will throw a NPE
   return false;
   if (!this.getClass().equals(o.getClass())) return false;
   FeatureGenerator fg = (FeatureGenerator) o;
   if (!this.getFunction().equals(fg.getFunction())) return false;
   if (this.arguments.length != fg.arguments.length) return false;
   for (int i = 0; i < arguments.length; i++) {
     if (!this.arguments[i].equals(fg.arguments[i])) return false;
   }
   return true;
 }
  /**
   * Randomly selects a generator from the generator list. The probability of a generator to be
   * selected is proportional to its number of attribute combinations as delivered by {@link
   * #getInputCandidates(ExampleSet, String[])} method. Returns null if no generators are
   * applicable.
   *
   * @param generators List of {@link FeatureGenerator}s
   */
  public static FeatureGenerator selectGenerator(
      ExampleSet exampleSet, List generators, String[] functions, RandomGenerator random) {
    int combinationSum = 0;
    Iterator i = generators.iterator();
    double[] probs = new double[generators.size()];
    int k = 0;
    while ((i.hasNext())) {
      FeatureGenerator generator = (FeatureGenerator) i.next();
      // probs[k] =
      // generator.getNumberOfApplicableGenerations(exampleSet);
      probs[k] = generator.getInputCandidates(exampleSet, functions).size();
      combinationSum += probs[k];
      k++;
    }
    if (combinationSum == 0) return null;
    else {
      for (k = 0; k < probs.length; k++) probs[k] /= combinationSum;

      int index = random.randomIndex(probs);
      FeatureGenerator selected = (FeatureGenerator) generators.get(index);
      return selected;
    }
  }