Exemplo n.º 1
0
def make_troia_job(job, gold_samples=[]):
    """
        Creates Troia job corresponding to passed Job object.
    """
    client = TroiaClient(settings.TROIA_HOST, None)
    job_id = make_job_id(job=job)
    TroiaJob.objects.create(job=job, troia_id=job_id)
    client.reset(job_id)
    client.load_categories(cost_matrix, job_id)
    client.load_gold_labels(gold_samples, job_id)
Exemplo n.º 2
0
def run_troia_on_data(cost_matrix, gold_samples, workers_labels):
    troia_client = TroiaClient(TROIA_SERVER_URL, TIMEOUT)
    # we create client instance

    ID = TUTORIAL_JOB_ID

    troia_client.reset(ID)
    # just to make sure that we don't interfere with some old data

    troia_client.load_categories(cost_matrix, ID)
    # we send cost matrix that contains all labels / categories

    troia_client.load_gold_labels(gold_samples, ID)
    # send samples for which we know correct label
    # we could also do this that way:
    # for object_id, label in gold_samples:
    #     troia_client.load_gold_label(object_id, label, ID)

    troia_client.load_worker_assigned_labels(workers_labels, ID)
    # send labels that worker assigned to objects
    # we could also do this that way:
    # for worker, object_id, label in workers_labels:
    #     troia_client.load_worker_assigned_label(worker, object_id, label, ID)

    troia_client.compute_blocking(ITERATIONS, ID)
    # we start actual calculations

    results = troia_client.get_dawid_skene(ID)
    # we collect results and stats

    # pprint.pprint(results)
    # and just print them with some formatting

    objects_data = results['objects'].items()
    # extracting data related to objects

    object_label_probabilities = [(object_id, params['categoryProbability'])
                                  for object_id, params in objects_data]
    # we extract label distributions for objects
    print "Object label probabilities:"
    pprint.pprint(sorted(object_label_probabilities))
    # and we print them

    # extracting data related to workers
    workers_summary = str(troia_client.print_worker_summary(True, ID))
    print
    print "Workers summary:"
    print workers_summary
Exemplo n.º 3
0
def run_simulation(opts):
    dsas = TroiaClient(url, None)
    dsas.reset(opts.ID)
    dsas.load_categories(
        [(labels[i], {labels[i]:0., labels[1 - i]:1.}) for i in xrange(2)], opts.ID)
    workers, objects, golds = gen_items(opts)
    start_time = time.time()
    for i in build_progressbar("Simulation iterations")(xrange(opts.it)):
        if (i + 1) % DUMP_FREQ == 0:
            current = time.time()
            duration = current - start_time
            log.info("Average speed: %s (labels/sec)  assigned labels: %s         ",
                                    str(float(DUMP_FREQ) / duration), str(i))
            start_time = current

        r = random.random()
        if r < opts.gratio and golds:
            obj = random.choice(golds)
            dsas.load_gold_label(obj, labels[1], opts.ID)
        else:
            obj = random.choice(objects)
        dsas.load_worker_assigned_label(random.choice(workers),
                                        obj, random.choice(labels), opts.ID)
Exemplo n.º 4
0
 def setUp(self):
     self.tc = TroiaClient(self.base_url)
     self.ID = "42"
     self.tc.load_categories(self._labels(), self.ID)