Example #1
0
  /**
   * This method can be used to permute the data instances IDs in a collection. This should have a
   * similar effect to permuting class labels. It can be used for validation experiments.
   *
   * @param instances Data instances to be permuted
   * @param random Random number generator
   * @return Permuted data instances
   */
  public static HashMap<String, String> PermuteIDs(HashMap<String, String> map, Random random) {
    ArrayList<String> instanceIDs =
        ListUtilities.Shuffle(new ArrayList<String>(map.keySet()), random);
    ArrayList<String> values = new ArrayList<String>(map.values());

    HashMap<String, String> permutedInstances = new HashMap<String, String>();

    for (int i = 0; i < instanceIDs.size(); i++)
      permutedInstances.put(instanceIDs.get(i), values.get(i));

    return permutedInstances;
  }
Example #2
0
  /**
   * For a list of String values, this method calculates the frequency at which each unique value
   * occurred.
   *
   * @param values List of values to evaluate
   * @return Map between the values and their frequency of occurrence
   */
  public static HashMap<String, Integer> GetFrequencyMap(ArrayList<String> values) {
    HashMap<String, Integer> map = new HashMap<String, Integer>();

    for (String unique : ListUtilities.GetUniqueValues(values)) {
      int count = 0;
      for (String value : new ArrayList<String>(values))
        if (value != null && value.equals(unique)) count++;
      map.put(unique, count);
    }

    return map;
  }
Example #3
0
 public static <T> T[] toArray(Set<T> set) {
   return ListUtilities.toArray(toList(set));
 }