Ejemplo n.º 1
0
    def _create_debug_database(self):
        """Create and populate a test database in a temporary file.
        """

        from tempfile import mktemp
        from pyanno.modelA import ModelA
        from pyanno.modelB import ModelB
        from pyanno.annotations import AnnotationsContainer

        # database filename
        tmp_filename = mktemp(prefix='tmp_pyanno_db_')
        db = PyannoDatabase(tmp_filename)

        def _create_new_entry(model, annotations, id):
            value = model.log_likelihood(annotations)
            ac = AnnotationsContainer.from_array(annotations, name=id)
            db.store_result(id, ac, model, value)

        # populate database
        model = ModelA.create_initial_state(5)
        annotations = model.generate_annotations(100)
        _create_new_entry(model, annotations, 'test_id')

        modelb = ModelB.create_initial_state(5, 8)
        _create_new_entry(modelb, annotations, 'test_id')

        annotations = model.generate_annotations(100)
        _create_new_entry(modelb, annotations, 'test_id2')

        self.database = db
    def _create_debug_database(self):
        """Create and populate a test database in a temporary file.
        """

        from tempfile import mktemp
        from pyanno.modelA import ModelA
        from pyanno.modelB import ModelB
        from pyanno.annotations import AnnotationsContainer

        # database filename
        tmp_filename = mktemp(prefix='tmp_pyanno_db_')
        db = PyannoDatabase(tmp_filename)

        def _create_new_entry(model, annotations, id):
            value = model.log_likelihood(annotations)
            ac = AnnotationsContainer.from_array(annotations, name=id)
            db.store_result(id, ac, model, value)

        # populate database
        model = ModelA.create_initial_state(5)
        annotations = model.generate_annotations(100)
        _create_new_entry(model, annotations, 'test_id')

        modelb = ModelB.create_initial_state(5, 8)
        _create_new_entry(modelb, annotations, 'test_id')

        annotations = model.generate_annotations(100)
        _create_new_entry(modelb, annotations, 'test_id2')

        self.database = db
Ejemplo n.º 3
0
def main():
    """ Entry point for standalone testing/debugging. """

    from tempfile import mktemp
    from contextlib import closing

    # database filename
    tmp_filename = mktemp(prefix='tmp_pyanno_db_')
    with closing(PyannoDatabase(tmp_filename)) as db:
        # populate database
        model = ModelA.create_initial_state(5)
        annotations = model.generate_annotations(100)
        _create_new_entry(model, annotations, 'test_id', db)

        modelb = ModelB.create_initial_state(5, 8)
        _create_new_entry(modelb, annotations, 'test_id', db)

        annotations = model.generate_annotations(100)
        _create_new_entry(modelb, annotations, 'test_id2', db)

        # create view
        database_view = DatabaseView(database=db)
        database_view.edit_traits(view='traits_view')

    return model, database_view
Ejemplo n.º 4
0
def main():
    """ Entry point for standalone testing/debugging. """

    from tempfile import mktemp
    from contextlib import closing

    # database filename
    tmp_filename = mktemp(prefix='tmp_pyanno_db_')
    with closing(PyannoDatabase(tmp_filename)) as db:
        # populate database
        model = ModelA.create_initial_state(5)
        annotations = model.generate_annotations(100)
        _create_new_entry(model, annotations, 'test_id', db)

        modelb = ModelB.create_initial_state(5, 8)
        _create_new_entry(modelb, annotations, 'test_id', db)

        annotations = model.generate_annotations(100)
        _create_new_entry(modelb, annotations, 'test_id2', db)

        # create view
        database_view = DatabaseView(database=db)
        database_view.edit_traits(view='traits_view')

    return model, database_view
Ejemplo n.º 5
0
    def _create_model_from_dialog(cls, dialog):
        # create prior alpha from user choice
        # prior strength multiplies the dirichlet parameters alpha
        alpha = (np.array(ALPHA_DEFAULT) - 1.) * dialog.prior_strength + 1.
        alpha = create_band_matrix(dialog.nclasses, alpha)

        model = ModelB.create_initial_state(dialog.nclasses,
                                            dialog.nannotators,
                                            alpha=alpha)
        return model
Ejemplo n.º 6
0
def main():
    """ Entry point for standalone testing/debugging. """

    from pyanno.models import ModelB

    model = ModelB.create_initial_state(4, 5)
    anno = model.generate_annotations(100)
    samples = model.sample_posterior_over_accuracy(anno, 10)

    model_view = ModelBView(model=model)
    model_view.plot_theta_samples(samples)
    model_view.configure_traits(view='traits_view')

    return model, model_view