Package com.ipeirotis.gal.core

Examples of com.ipeirotis.gal.core.Datum


  private HashMap<String, Double> getObjectClassProbabilities(
      String objectName, String workerToIgnore) {

    HashMap<String, Double> result = new HashMap<String, Double>();

    Datum d = this.objects.get(objectName);

    // If this is a gold example, just put the probability estimate to be
    // 1.0
    // for the correct class
    if (d.isGold()) {
      for (String category : this.categories.keySet()) {
        String correctCategory = d.getGoldCategory();
        if (category.equals(correctCategory)) {
          result.put(category, 1.0);
        } else {
          result.put(category, 0.0);
        }
      }
      return result;
    }

    // Let's check first if we have any workers who have labeled this item,
    // except for the worker that we ignore
    Set<AssignedLabel> labels = d.getAssignedLabels();
    if (labels.isEmpty())
      return null;
    if (workerToIgnore != null && labels.size() == 1) {
      for (AssignedLabel al : labels) {
        if (al.getWorkerName().equals(workerToIgnore))
          return null;
      }
    }

    // If it is not gold, then we proceed to estimate the class
    // probabilities using the method of Dawid and Skene and we proceed as
    // usual with the M-phase of the EM-algorithm of Dawid&Skene

    // Estimate denominator for Eq 2.5 of Dawid&Skene, which is the same
    // across all categories
    Double denominator = 0.0;

    // To compute the denominator, we also compute the nominators across
    // all categories, so it saves us time to save the nominators as we
    // compute them
    HashMap<String, Double> categoryNominators = new HashMap<String, Double>();

    for (Category category : categories.values()) {

      // We estimate now Equation 2.5 of Dawid & Skene
      Double categoryNominator = category.getPrior();

      // We go through all the labels assigned to the d object
      for (AssignedLabel al : d.getAssignedLabels()) {
        Worker w = workers.get(al.getWorkerName());

        // If we are trying to estimate the category probability
        // distribution
        // to estimate the quality of a given worker, then we need to
View Full Code Here


    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);
    }
View Full Code Here

  public Integer countGoldTests(Set<AssignedLabel> labels) {
    Integer result = 0;
    for (AssignedLabel al : labels) {
      String name = al.getObjectName();
      Datum d = this.objects.get(name);
      if (d.isGold())
        result++;
    }
    return result;
  }
View Full Code Here

      this.updateObjectClassProbabilities(objectName);
    }
  }

  private void updateObjectClassProbabilities(String objectName) {
    Datum d = this.objects.get(objectName);
    HashMap<String, Double> probabilities = getObjectClassProbabilities(
        objectName, null);
    if (probabilities == null)
      return;
    for (String category : probabilities.keySet()) {
      Double probability = probabilities.get(category);
      d.setCategoryProbability(category, probability);
    }
  }
View Full Code Here

    double count = 0;
    boolean evalP = fieldAccessor instanceof EvalDatumFieldAccessor;
   
    for (T object : objects) {
      if (evalP) {
        Datum datum = ((Datum) object);
       
        if (! datum.isEvaluation())
          continue;
      }
     
     
      Double value = (Double) fieldAccessor.getValue(object);
View Full Code Here

    // If we already have the object, then just add the label
    // in the set of labels for the object.
    // If it is the first time we see the object, then create
    // the appropriate entry in the objects hashmap
    Datum d;
    if (this.objects.containsKey(objectName)) {
      d = this.objects.get(objectName);
    } else {
      d = new Datum(objectName, this);
      this.objects.put(objectName, d);
    }

    d.addAssignedLabel(al);

    // If we already have the worker, then just add the label
    // in the set of labels assigned by the worker.
    // If it is the first time we see the object, then create
    // the appropriate entry in the objects hashmap
View Full Code Here

  public void addCorrectLabel(CorrectLabel cl) {

    String objectName = cl.getObjectName();
    String correctCategory = cl.getCorrectCategory();

    Datum d = objects.get(objectName);

    if (null == d) {
      d = new Datum(objectName, this);
      this.objects.put(objectName, d);
    }

    d.setGold(true);
    d.setGoldCategory(correctCategory);
  }
View Full Code Here

  }

  public void addEvaluationLabel(CorrectLabel cl) {
    String objectName = cl.getObjectName();
    String correctCategory = cl.getCorrectCategory();
    Datum d = this.objects.get(objectName);
    assert (d != null); // All objects in the evaluation should be rated by
              // at least one worker
    d.setEvaluation(true);
    d.setEvaluationCategory(correctCategory);
    this.objects.put(objectName, d);
  }
View Full Code Here

      super(name, desc);
    }

    @Override
    public String getStringValue(Object _wrapped) {
      Datum wrapped = (Datum) _wrapped;

      if (wrapped.isEvaluation()) {
        Object v = super.getValue(wrapped);

        if (v instanceof Double) {
          Double value = (Double) v;
View Full Code Here

TOP

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

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.