def _test_model(name):
    modules = MODULES[name]
    assert_all_close([m.NAME for m in modules], err_msg='Model.__name__')
    EXAMPLES = [e for m in modules for e in m.EXAMPLES]
    for EXAMPLE in EXAMPLES:
        raw_shared = EXAMPLE['shared']
        shareds = [module.Shared.from_dict(raw_shared) for module in modules]
        dumped = [m.dump() for m in shareds]
        assert_all_close(dumped, err_msg='shared_dump')
Ejemplo n.º 2
0
def _test_model(name):
    modules = MODULES[name]
    assert_all_close([m.NAME for m in modules], err_msg='Model.__name__')
    EXAMPLES = [e for m in modules for e in m.EXAMPLES]
    for EXAMPLE in EXAMPLES:
        raw_shared = EXAMPLE['shared']
        shareds = [module.Shared.from_dict(raw_shared) for module in modules]
        dumped = [m.dump() for m in shareds]
        assert_all_close(dumped, err_msg='shared_dump')
Ejemplo n.º 3
0
def _test_model(name):
    MODELS = [m.Model for m in MODULES[name]]
    assert_all_close([m.__name__ for m in MODELS], err_msg='Model.__name__')
    EXAMPLES = [e for m in MODELS for e in m.EXAMPLES]
    for EXAMPLE in EXAMPLES:
        raw_model = EXAMPLE['model']
        models = [Model.model_load(raw_model) for Model in MODELS]
        dumped = [m.dump() for m in models]
        assert_all_close(dumped, err_msg='model_dump')
Ejemplo n.º 4
0
def _test_plus_group(name):
    MODELS = [m.Model for m in MODULES[name] if hasattr(m.Model, 'plus_group')]
    EXAMPLES = [e for m in MODELS for e in m.EXAMPLES]
    for EXAMPLE in EXAMPLES:
        raw_model = EXAMPLE['model']
        values = EXAMPLE['values']
        models = [Model.model_load(raw_model) for Model in MODELS]
        groups = [model.group_create(values) for model in models]
        dumped = [m.plus_group(g).dump() for m, g in zip(models, groups)]
        assert_all_close(dumped, err_msg='model._plus_group(group)')
Ejemplo n.º 5
0
def test_scorer(module, EXAMPLE):
    shared = module.Shared.from_dict(EXAMPLE['shared'])
    values = EXAMPLE['values']

    group = module.Group.from_values(shared)
    scorer1 = shared.scorer_create()
    scorer2 = shared.scorer_create(group)
    for value in values:
        score1 = shared.scorer_eval(scorer1, value)
        score2 = shared.scorer_eval(scorer2, value)
        score3 = group.score_value(shared, value)
        assert_all_close([score1, score2, score3])
def test_scorer(module, EXAMPLE):
    shared = module.Shared.from_dict(EXAMPLE['shared'])
    values = EXAMPLE['values']

    group = module.Group.from_values(shared)
    scorer1 = shared.scorer_create()
    scorer2 = shared.scorer_create(group)
    for value in values:
        score1 = shared.scorer_eval(scorer1, value)
        score2 = shared.scorer_eval(scorer2, value)
        score3 = group.score_value(shared, value)
        assert_all_close([score1, score2, score3])
Ejemplo n.º 7
0
def test_scorer(Model, EXAMPLE):
    model = Model.model_load(EXAMPLE['model'])
    values = EXAMPLE['values']

    group = model.group_create()
    scorer1 = model.scorer_create()
    scorer2 = model.scorer_create(group)
    for value in values:
        score1 = model.scorer_eval(scorer1, value)
        score2 = model.scorer_eval(scorer2, value)
        score3 = model.score_value(group, value)
        assert_all_close([score1, score2, score3])
def _test_plus_group(name):
    modules = MODULES[name]
    modules = [m for m in modules if hasattr(m.Shared, 'plus_group')]
    EXAMPLES = [e for m in modules for e in m.EXAMPLES]
    for EXAMPLE in EXAMPLES:
        raw_shared = EXAMPLE['shared']
        values = EXAMPLE['values']
        shareds = [module.Shared.from_dict(raw_shared) for module in modules]
        groups = [
            module.Group.from_values(shared, values)
            for module, shared in zip(modules, shareds)]
        dumped = [m.plus_group(g).dump() for m, g in zip(shareds, groups)]
        assert_all_close(dumped, err_msg='shared._plus_group(group)')
Ejemplo n.º 9
0
def _test_plus_group(name):
    modules = MODULES[name]
    modules = [m for m in modules if hasattr(m.Shared, 'plus_group')]
    EXAMPLES = [e for m in modules for e in m.EXAMPLES]
    for EXAMPLE in EXAMPLES:
        raw_shared = EXAMPLE['shared']
        values = EXAMPLE['values']
        shareds = [module.Shared.from_dict(raw_shared) for module in modules]
        groups = [
            module.Group.from_values(shared, values)
            for module, shared in zip(modules, shareds)
        ]
        dumped = [m.plus_group(g).dump() for m, g in zip(shareds, groups)]
        assert_all_close(dumped, err_msg='shared._plus_group(group)')
Ejemplo n.º 10
0
def _test_group(name):
    modules = MODULES[name]
    EXAMPLES = [e for m in modules for e in m.EXAMPLES]
    for EXAMPLE in EXAMPLES:
        values = EXAMPLE['values'][:]
        raw_shared = EXAMPLE['shared']
        temp_shared = modules[0].Shared.from_dict(raw_shared)
        for value in values:
            temp_shared.add_value(value)
        temp_shared.realize()
        raw_shared = temp_shared.dump()

        shareds = [module.Shared.from_dict(raw_shared) for module in modules]
        groups = [
            module.Group.from_values(shared)
            for module, shared in zip(modules, shareds)
        ]
        modules_shareds_groups = zip(modules, shareds, groups)

        for value in values:
            for module, shared, group in modules_shareds_groups:
                group.add_value(shared, value)
            dumped = [g.dump() for g in groups]
            assert_all_close(dumped, err_msg='group_dump')

        for module, shared, group in modules_shareds_groups:
            value = group.sample_value(shared)
            shared.add_value(value)
            values.append(value)

        for value in values:
            scores = [
                group.score_value(shared, value)
                for module, shared, group in modules_shareds_groups
            ]
            for module, shared, group in modules_shareds_groups:
                print "------------------"
                print module
                print shared.dump()
                print group.dump()
            print value
            assert_all_close(scores, err_msg='score_value')

        scores = [
            group.score_data(shared)
            for module, shared, group in modules_shareds_groups
        ]
        assert_all_close(scores, err_msg='score_data')

        for module, shared, group in modules_shareds_groups:
            dumped = group.dump()
            group.init(shared)
            group.load(dumped)

        scores = [
            group.score_data(shared)
            for module, shared, group in modules_shareds_groups
        ]
        assert_all_close(scores, err_msg='score_data')
def _test_group(name):
    modules = MODULES[name]
    EXAMPLES = [e for m in modules for e in m.EXAMPLES]
    for EXAMPLE in EXAMPLES:
        values = EXAMPLE['values'][:]
        raw_shared = EXAMPLE['shared']
        temp_shared = modules[0].Shared.from_dict(raw_shared)
        for value in values:
            temp_shared.add_value(value)
        temp_shared.realize()
        raw_shared = temp_shared.dump()

        shareds = [module.Shared.from_dict(raw_shared) for module in modules]
        groups = [
            module.Group.from_values(shared)
            for module, shared in zip(modules, shareds)]
        modules_shareds_groups = zip(modules, shareds, groups)

        for value in values:
            for module, shared, group in modules_shareds_groups:
                group.add_value(shared, value)
            dumped = [g.dump() for g in groups]
            assert_all_close(dumped, err_msg='group_dump')

        for module, shared, group in modules_shareds_groups:
            value = group.sample_value(shared)
            shared.add_value(value)
            values.append(value)

        for value in values:
            scores = [
                group.score_value(shared, value)
                for module, shared, group in modules_shareds_groups
            ]
            for module, shared, group in modules_shareds_groups:
                print "------------------"
                print module
                print shared.dump()
                print group.dump()
            print value
            assert_all_close(scores, err_msg='score_value')

        scores = [
            group.score_data(shared)
            for module, shared, group in modules_shareds_groups]
        assert_all_close(scores, err_msg='score_data')

        for module, shared, group in modules_shareds_groups:
            dumped = group.dump()
            group.init(shared)
            group.load(dumped)

        scores = [
            group.score_data(shared)
            for module, shared, group in modules_shareds_groups]
        assert_all_close(scores, err_msg='score_data')
Ejemplo n.º 12
0
def _test_group(name):
    MODELS = [m.Model for m in MODULES[name]]
    EXAMPLES = [e for m in MODELS for e in m.EXAMPLES]
    for EXAMPLE in EXAMPLES:
        raw_model = EXAMPLE['model']
        values = EXAMPLE['values'][:]
        models = [Model.model_load(raw_model) for Model in MODELS]

        groups = [model.group_create() for model in models]
        models_groups = zip(models, groups)

        for value in values:
            for model, group in models_groups:
                model.group_add_value(group, value)
            dumped = [g.dump() for g in groups]
            assert_all_close(dumped, err_msg='group_dump')

        for model, group in models_groups:
            values.append(model.sample_value(group))

        for value in values:
            scores = [
                model.score_value(group, value)
                for model, group in models_groups
            ]
            assert_all_close(scores, err_msg='score_value')

        scores = [model.score_group(group) for model, group in models_groups]
        assert_all_close(scores, err_msg='score_group')

        for model, group in models_groups:
            dumped = group.dump()
            model.group_init(group)
            group.load(dumped)

        scores = [model.score_group(group) for model, group in models_groups]
        assert_all_close(scores, err_msg='score_group')