Example #1
0
  /**
   * Query a regression algorithm using equilateral encoding.
   *
   * @param alg The algorithm being used.
   * @param theTrainingData The training data.
   * @param items The category items classified.
   * @param high The high value.
   * @param low The low value.
   */
  public static void queryEquilateral(
      final RegressionAlgorithm alg,
      final List<BasicData> theTrainingData,
      final Map<String, Integer> items,
      final double high,
      final double low) {
    // first, we need to invert the items.  Right now it maps from category to index.  We need index
    // to category.
    final Map<Integer, String> invMap = new HashMap<>();
    for (final Map.Entry<String, Integer> entry : items.entrySet()) {
      invMap.put(entry.getValue(), entry.getKey());
    }

    // now we can query
    final Equilateral eq = new Equilateral(items.size(), high, low);
    for (final BasicData data : theTrainingData) {
      final double[] output = alg.computeRegression(data.getInput());
      final int idealIndex = eq.decode(data.getIdeal());
      final int actualIndex = eq.decode(output);
      System.out.println(
          Arrays.toString(data.getInput())
              + " -> "
              + invMap.get(actualIndex)
              + ", Ideal: "
              + invMap.get(idealIndex));
    }
  }
Example #2
0
 /**
  * Query a regression algorithm and see how close it matches the training data.
  *
  * @param alg The algorithm to evaluate.
  * @param theTrainingData The training data.
  */
 public static void query(final RegressionAlgorithm alg, final List<BasicData> theTrainingData) {
   for (final BasicData data : theTrainingData) {
     final double[] output = alg.computeRegression(data.getInput());
     System.out.println(
         Arrays.toString(data.getInput())
             + " -> "
             + Arrays.toString(output)
             + ", Ideal: "
             + Arrays.toString(data.getIdeal()));
   }
 }