Exemplo n.º 1
0
def test_1(dismod, assert_correct=True):
    db = example_db.example_db(file_name, **db_kwds)
    success, db = dismod_tests.run_test(file_name, config, truth)

    if success: print('Dismod_AT succeeded -- that is the correct result.')
    if assert_correct:
        assert success
Exemplo n.º 2
0
def test_2(dismod, assert_correct=True):
    """
    Parent rate must be log-gaussian and subgroup random effect densities must be something other than uniform for this problem to solve
    With a log-gaussian prior, dismod converges well
    """

    prior['parent_density'] = 'log_gaussian'
    prior['parent_std'] = 100
    prior['parent_eta'] = 1e-5
    prior['subgroup_density'] = 'gaussian'
    prior['subgroup_std'] = 1000

    db_kwds.update({'prior': prior})
    db = example_db.example_db(file_name, **db_kwds)
    success, db = dismod_tests.run_test(file_name, config, truth)

    if not success:
        msg = 'Dismod_AT succeeded, but there is unresolvable ambiguity between the rate and group rate mulcov.'
        var = ((sum(
            (db.fit_var.fit_var_value - db.truth_var.truth_var_value)[:4]**2))
               **.5 < 1e-7)
        fit = ((sum(db.fit_data_subset.weighted_residual**2))**.5 < 1e-7)
        if not var:
            msg += '\nThe fit values for the unambiguous variables failed.'
        if not fit:
            msg += "\nData weighted residual errors are too large."
        if not (var and fit):
            msg += '\nDismod may be scaling this problem improperly.'
        assert var and fit, msg
Exemplo n.º 3
0
def test_1(dismod, capsys, assert_correct=True):
    """
    Parent rate and subgroup random effect densities must be something other than uniform for this problem to solve.
    With gaussian priors, there seems to be a scaling problem in dismod (see the initial objective function), 
    and dismod does not converge well.
    """

    prior['parent_density'] = 'gaussian'
    prior['parent_std'] = 100
    prior['subgroup_density'] = 'gaussian'
    prior['subgroup_std'] = 100

    db_kwds.update({'prior': prior})
    db = example_db.example_db(file_name, **db_kwds)
    run_dismod(db.path, 'set option print_level_fixed 0')
    success, db = dismod_tests.run_test(file_name, config, truth)

    if not success:
        msg = 'ERROR: Dismod_AT succeeded, but there is unresolvable ambiguity between the rate and group rate mulcov.'
        var = ((sum(
            (db.fit_var.fit_var_value - db.truth_var.truth_var_value)[:4]**2))
               **.5 < 1e-7)
        fit = ((sum(db.fit_data_subset.weighted_residual**2))**.5 < 1e-7)
        if not var:
            msg += '\n  The fit_var values do not match the truth.'
        if not fit:
            msg += '\n  Data weighted residual errors are too large.'
        if not (var and fit):
            msg += '\n  Dismod may be scaling this problem improperly.'
        if not (var and fit):
            with capsys.disabled():
                print('\n' + msg)
Exemplo n.º 4
0
def test_2(dismod, assert_correct = True):

    db = example_db.example_db(file_name, **db_kwds)
    success, db = dismod_tests.run_test(file_name, config, truth, test_asymptotic=True)

    if success: print ('Dismod_AT fit with setup for asymptotic statistics succeeded -- that is the correct result.')
    if assert_correct:
        assert success, 'Dismod_AT fit with asymptotic statistics failed -- that is not the correct result.'
Exemplo n.º 5
0
def test_1(dismod, assert_correct = True):

    db = example_db.example_db(file_name, **db_kwds)
    success, db = dismod_tests.run_test(file_name, config, truth, test_asymptotic=True)

    if not success: print ('Dismod_AT did not succeed Hessian problems -- that is the correct result.')
    if assert_correct: assert not success

    # For the Hessian to be positive, parent rate and subgroup random effect densities must be something other than uniform
    prior['parent_density'] = 'gaussian'
    prior['parent_std'] = 1000
    prior['subgroup_density'] = 'gaussian'
    prior['subgroup_std'] = 1000

    db_kwds.update(dict(prior=prior))
    example_db.example_db(file_name, **db_kwds)
    success, db = dismod_tests.run_test(file_name, config, truth, test_asymptotic=True)

    if success: print ('Dismod_AT asymptotic statistics succeeded -- that is the correct result.')
    if assert_correct: assert success
Exemplo n.º 6
0
def test_2(dismod, assert_correct=True):

    prior['subgroup_density'] = 'gaussian'
    prior['subgroup_std'] = 10000

    db_kwds.update({'prior': prior})
    db = example_db.example_db(file_name, **db_kwds)
    success, db = dismod_tests.run_test(file_name, config, truth)

    if success: print('Dismod_AT succeeded -- that is the correct result.')
    if assert_correct:
        assert success, 'Dismod_AT succeeded -- that is the correct result.'
Exemplo n.º 7
0
def test_2(dismod, assert_correct=True):
    # For the asymptotic statistics to work, the parent rate density must be something other than uniform
    prior['parent_density'] = 'gaussian'
    prior['parent_std'] = 1000
    db_kwds.update(dict(prior=prior))
    db = example_db.example_db(file_name, **db_kwds)
    success, db = dismod_tests.run_test(file_name,
                                        config,
                                        truth,
                                        test_asymptotic=True)

    if success:
        print(
            'Dismod_AT asymptotic statistics succeeded -- that is the correct result.'
        )
    if assert_correct:
        assert success
Exemplo n.º 8
0
def test_3(dismod, assert_correct=True):
    """
    Parent rate must be log-gaussian and subgroup random effect densities must be something other than uniform for this problem to solve
    Parent rate must have guidance for to resolve that ambiguity
    """

    # Give the parent rate guidance
    prior['parent_density'] = 'gaussian'
    prior['parent_mean'] = truth['iota_parent_true']
    prior['parent_std'] = 1e-10
    prior['subgroup_density'] = 'gaussian'
    prior['subgroup_std'] = 10000

    db_kwds.update({'prior': prior})
    db = example_db.example_db(file_name, **db_kwds)
    success, db = dismod_tests.run_test(file_name, config, truth)

    if assert_correct:
        assert success, 'Dismod_AT ran, but there is ambiguity between the rate and group rate mulcov in this test.'
Exemplo n.º 9
0
def test_4(dismod, capsys, assert_correct=True):
    """
    Parent rate must be log-gaussian and subgroup random effect densities must be something other than uniform for this problem to solve
    Parent rate must have guidance for to resolve that ambiguity
    With this configuration, the asymptotic statistics work fine
    """

    ignore, db = dismod_tests.run_test(file_name,
                                       config,
                                       truth,
                                       test_asymptotic=True)

    hes = abs(db.hes_fixed.hes_fixed_value.values).max()
    success = hes < 1e10

    if not success:
        with capsys.disabled():
            print(
                '\nERROR: Dismod_AT asymptotics failed. The Hessian identifies the presence of the ambiguity.'
            )