Package com.ipeirotis.gal.core

Examples of com.ipeirotis.gal.core.ConfusionMatrix


    for (int i=1; i<5; i++) {
      Category c = new Category("cat"+i);
      categories.add(c);
    }
   
    cm = new ConfusionMatrix(categories);
    cm.empty();
   
    for (String from: cm.getCategoryNames()) {
      for (String to: cm.getCategoryNames()) {
        Double error = Math.random();
View Full Code Here


    String type = "Estimated";

    for (ClassificationMethod estimatedClasMethod : Datum.ClassificationMethod.values()) {
     
     
      ConfusionMatrix confMatrix = decorator.getEstimatedConfusionMatrix(estimatedClasMethod);

      reportTarget.println("%s Confusion Matrix (%s):", type, estimatedClasMethod.name());

      for (String from : confMatrix.getCategoryNames()) {
        for (String to : confMatrix.getCategoryNames()) {
          Double cm_entry = confMatrix.getErrorRate(from, to);
          String s_cm_entry = Double.isNaN(cm_entry) ? "---" : Helper.round(100 * cm_entry, 3).toString();
          reportTarget.print("P[%s->%s]=%s%%\t", from, to, s_cm_entry);
        }
        reportTarget.println("");
      }
      reportTarget.println("");
    }

    type = "Actual";

    // for each classification method, we need to create a confusion matrix
    for (ClassificationMethod clasMethod : Datum.ClassificationMethod.values()) {
      ConfusionMatrix confMatrix = decorator.getConfusionMatrix(clasMethod);

      reportTarget.println("%s Confusion Matrix (%s):", type, clasMethod.name());

      for (String from : confMatrix.getCategoryNames()) {
        for (String to : confMatrix.getCategoryNames()) {
          Double cm_entry = confMatrix.getErrorRate(from, to);
          String s_cm_entry = Double.isNaN(cm_entry) ? "---" : Helper.round(100 * cm_entry, 3).toString();
          reportTarget.print("P[%s->%s]=%s%%\t", from, to, s_cm_entry);
        }
        reportTarget.println("");
      }
View Full Code Here

    }
  }

 
  private void computeEvalConfusionMatrix(Worker w) {
    ConfusionMatrix eval_cm = new ConfusionMatrix(this.categories.values());
    eval_cm.empty();
    for (AssignedLabel l : w.getAssignedLabels()) {

      String objectName = l.getObjectName();
      Datum d = this.objects.get(objectName);
      assert (d != null);
      if (!d.isEvaluation())
        continue;

      String assignedCategory = l.getCategoryName();
      String correctCategory = d.getEvaluationCategory();

      // Double currentCount = eval_cm.getErrorRate(correctCategory,
      // assignedCategory);
      eval_cm.addError(correctCategory, assignedCategory, 1.0);
    }
    eval_cm.normalize();
    w.setEvalConfusionMatrix(eval_cm);
  }
View Full Code Here

   */
  private void updateWorkerConfusionMatrix(String workerName) {

    Worker w = this.workers.get(workerName);

    ConfusionMatrix cm = new ConfusionMatrix(this.categories.values());
    cm.empty();

    // Scan all objects and change the confusion matrix for each worker
    // using the class probability for each object
    for (AssignedLabel al : w.getAssignedLabels()) {

      // Get the name of the object and the category it
      // is classified from this worker.
      String objectName = al.getObjectName();
      String destination = al.getCategoryName();

      // We get the classification of the object
      // based on the votes of all the other workers
      // We treat this classification as the "correct" one
      HashMap<String, Double> probabilities = this
          .getObjectClassProbabilities(objectName, workerName);
      if (probabilities == null)
        continue; // No other worker labeled the object

      for (String source : probabilities.keySet()) {
        Double error = probabilities.get(source);
        cm.addError(source, destination, error);
      }

    }
    cm.normalize();

    w.setConfusionMatrix(cm);

  }
View Full Code Here

    super(wrapped);
  }

  public ConfusionMatrix getEstimatedConfusionMatrix(ClassificationMethod clasMethod) {

    ConfusionMatrix confMatrix = new ConfusionMatrix(object.getCategories().values());

    confMatrix.empty();
    for (Datum d : object.getObjects().values()) {
      populateConfusionMatrix(clasMethod, confMatrix, d);
    }
    confMatrix.normalize();

    return confMatrix;
  }
View Full Code Here

    return probEstimateMethod;
  }

  public ConfusionMatrix getConfusionMatrix(ClassificationMethod clasMethod) {

    ConfusionMatrix confMatrix = new ConfusionMatrix(object.getCategories().values());

    confMatrix.empty();

    for (Datum d : object.getObjects().values()) {
      if (!d.isEvaluation())
        continue;

      String fromCategory = d.getEvaluationCategory();
      Map<String, Double> toClassifiedAs = d.getProbabilityVector(clasMethod);

      for (String toCategory : toClassifiedAs.keySet()) {
        Double prob = toClassifiedAs.get(toCategory);

        confMatrix.addError(fromCategory, toCategory, prob);
      }
    }

    confMatrix.normalize();

    return confMatrix;
  }
View Full Code Here

TOP

Related Classes of com.ipeirotis.gal.core.ConfusionMatrix

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.