Esempio n. 1
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)
Esempio n. 2
0
def test_0(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, 'init')
    info = run_dismod(db.path, 'fit both')
    print(info.stdout)
    global stdout
    stdout = info.stdout

    lines = stdout.splitlines()
    for i, line in enumerate(lines):
        if 'iter' in line and 'objective' in line:
            break
    col_index = lines[i].split().index('objective')
    objective = float(lines[i + 1].split()[col_index])
    if not (objective > -1e-10):
        with capsys.disabled():
            print(
                f"\nERROR: Dismod scaled this fit both problem incorrectly, objective was {objective}."
            )
Esempio n. 3
0
    def __call__(self, index: int):
        self.index = index
        index_db = self.index_file_pattern.format(index=index)
        copy2(src=str(self.main_db), dst=str(index_db))

        # Set the seed to null so each process will have a unique random sequence
        run_dismod(str(index_db), "set option random_seed ''")
        return self._process(db=index_db)
def test_run_dismod_fit_predict(dismod, ihme):
    run = run_dismod(dm_file='temp.db', command='init')
    if run.exit_status:
        print(run.stderr)
    assert run.exit_status == 0
    run = run_dismod(dm_file='temp.db', command='fit fixed')
    if run.exit_status:
        print(run.stderr)
    assert run.exit_status == 0
    run = run_dismod(dm_file='temp.db', command='predict fit_var')
    if run.exit_status:
        print(run.stderr)
    assert run.exit_status == 0
Esempio n. 5
0
def test_default_init_with_null_weight_id(default_fill, weight_list):
    data_df = two_input_data_df.copy()
    data_df['weight_id'] = weight_list
    try:
        default_fill.data = data_df
        run = run_dismod(dm_file=str(default_fill.path), command='init')
        if run.exit_status:
            print(run.stdout)
            print(run.stderr)
        assert run.exit_status == 0
    except Exception:
        raise
    finally:
        default_fill.data = default_data_df
Esempio n. 6
0
def test_default_init_with_null_mulstd(default_fill, mulstd_value_prior_id):
    prior_smooth_df = default_fill.smooth.copy()
    smooth_df = default_fill.smooth.copy()
    smooth_df['mulstd_value_prior_id'] = mulstd_value_prior_id
    try:
        default_fill.smooth = smooth_df
        run = run_dismod(dm_file=str(default_fill.path), command='init')
        if run.exit_status:
            print(run.stdout)
            print(run.stderr)
        assert run.exit_status == 0
    except Exception:
        raise
    finally:
        default_fill.smooth = prior_smooth_df
Esempio n. 7
0
 def system(args):
     # run_dismod assumes that the execitable name is dmdismod
     # To make this code work with the dismod_at executable, make an executable simlink: dmdismod -> dismod_at
     program = args[0]
     db = args[1]
     cmd = ' '.join(args[2:])
     info = run_dismod(db, cmd)
     if info.stdout or info.stderr: print ('-'*30)
     if info.stdout: print (info.stdout)
     if info.stderr: print (info.stderr)
     # if info.stderr:
     #     raise Exception(f'ERROR: {info.stderr}')
     if ' step ' in info.stdout and ' f ' in info.stdout and ' grad ' in info.stdout:
         raise Exception (f'GRADIENT ERROR')
     if 'error' in info.stderr.lower() or info.exit_status:
         raise Exception(f'ERROR: {info.stderr}')
     if ' invalid number ' in info.stderr.lower():
         raise Exception(f'ERROR: {info.stderr}')
Esempio n. 8
0
def run_dmdismod(file, dm_commands: List[str]) -> None:
    """
    Runs commands on a dismod file.

    Parameters
    ----------
    file
        Filepath to a database
    dm_commands
        List of commands that dismod_at understands
    """
    for c in dm_commands:
        process = run_dismod(dm_file=file, command=c)
        if process.exit_status:
            LOG.error(f"{c} failed with exit_status {process.exit_status}:")
            LOG.error(f"{process.stderr}")
            raise
        else:
            print(process.stdout)
            print(process.stderr)
Esempio n. 9
0
def test_dmdismod_init(dm):
    run = run_dismod(dm_file=str(dm.path), command='init')
    if run.exit_status:
        print(run.stdout)
        print(run.stderr)
    assert run.exit_status == 0