@Test
  public void resultsSerializationTest() {
    ArrayList<String> categories = new ArrayList<String>();
    categories.add("category1");
    categories.add("category2");

    MemoryJobStorage js = new MemoryJobStorage();
    IResults<String, DatumResult, WorkerResult> results =
        js.getNominalResults("testid", categories);
    LObject<String> obj = new LObject<String>("obj");
    obj.setEvaluationLabel("category2");
    DatumResult dr = results.getOrCreateDatumResult(obj);
    Map<String, Double> categoryProb = new HashMap<String, Double>();
    categoryProb.put("category1", 0.3);
    categoryProb.put("category2", 0.7);
    dr.setCategoryProbabilites(categoryProb);
    results.addDatumResult(obj, dr);
    String serialized = gson.toJson(results);
    LObject<String> imaginaryObj = new LObject<String>("ImaginaryObj");
    Worker imaginaryWorker = new Worker("ImaginaryWorker");

    InMemoryResults<String, DatumResult, WorkerResult> deserialized =
        gson.fromJson(
            serialized,
            new TypeToken<InMemoryResults<String, DatumResult, WorkerResult>>() {}.getType());
    //		Assert.assertEquals(deserialized.getOrCreateDatumResult(imaginaryObj).getClass(),
    //				results.getOrCreateDatumResult(imaginaryObj).getClass());
    //		Assert.assertEquals(deserialized.getOrCreateWorkerResult(imaginaryWorker).getClass(),
    //				results.getOrCreateWorkerResult(imaginaryWorker).getClass());
    // ^^^ above doesn't work - it works when jsoned at job level
    Assert.assertNotNull(deserialized.getDatumResult(obj));
    DatumResult ddr = deserialized.getDatumResult(obj);
    Assert.assertEquals(ddr.getCategoryProbabilites(), dr.getCategoryProbabilites());
    Assert.assertEquals(gson.toJson(deserialized), serialized);
  }
Esempio n. 2
0
  protected void testMVResults(Results<String, DatumResult, WorkerResult> results) {
    double eps = 0.000001;
    double[] exp = new double[] {2. / 3, 1. / 3};
    for (int i = 0; i < nObjects; i++) {
      LObject<String> object = objects.get(i);
      DatumResult dr = results.getDatumResult(object);
      Map<String, Double> pd = dr.getCategoryProbabilites();
      int ii = i % 2;
      assertEquals(exp[ii], pd.get("AAA"), eps);
      assertEquals(exp[1 - ii], pd.get("BBB"), eps);
    }

    for (int i = 0; i < nGold; i++) {
      LObject<String> object = goldObjects.get(i);
      DatumResult dr = results.getDatumResult(object);
      Map<String, Double> pd = dr.getCategoryProbabilites();
      assertEquals(1., pd.get("AAA"), eps);
      assertEquals(0., pd.get("BBB"), eps);
    }
  }
 @Override
 public void newAssign(AssignedLabel<String> assign) {
   DatumResult dr = results.getOrCreateDatumResult(assign.getLobject());
   Map<String, Double> oldProbabilites = dr.getCategoryProbabilites();
   // update object class probabilites
   Map<String, Double> probabilities =
       getObjectClassProbabilities(assign.getLobject(), assign.getWorker());
   dr.setCategoryProbabilites(probabilities);
   results.addDatumResult(assign.getLobject(), dr);
   // update priors
   if (!data.arePriorsFixed()) {
     undoPriorInfluence(oldProbabilites);
     makePriorInfluence(probabilities);
   }
   // rebuild worker confusion matrices for all workers who assigned this object
   if (probabilities != null)
     for (AssignedLabel<String> al : data.getAssignsForObject(assign.getLobject())) {
       WorkerResult wr = results.getOrCreateWorkerResult(al.getWorker());
       for (Map.Entry<String, Double> e : probabilities.entrySet()) {
         wr.addError(e.getKey(), al.getLabel(), e.getValue());
       }
       results.addWorkerResult(al.getWorker(), wr);
     }
 }