Example #1
0
  @Override
  public CategoricalResults classify(DataPoint data) {
    CategoricalResults cr = new CategoricalResults(predicting.getNumOfCategories());

    // Use a priority que so that we always pick the two lowest value class labels, makes indexing
    // into the oneVsOne array simple
    PriorityQueue<Integer> options = new PriorityQueue<Integer>(predicting.getNumOfCategories());
    for (int i = 0; i < cr.size(); i++) options.add(i);

    CategoricalResults subRes;
    int c1, c2;
    // We will now loop through and repeatedly pick two combinations, and eliminate the loser, until
    // there is one winer
    while (options.size() > 1) {
      c1 = options.poll();
      c2 = options.poll();

      subRes = oneVone[c1][c2 - c1 - 1].classify(data);

      if (subRes.mostLikely() == 0) // c1 wins, c2 no longer a candidate
      options.add(c1);
      else // c2 wins, c1 no onger a candidate
      options.add(c2);
    }

    cr.setProb(options.peek(), 1.0);

    return cr;
  }