Exemplo n.º 1
0
    def initialize(self, file_name, to_csv=False):
        dismod_at.create_database(file_name, self.age_list, self.time_list,
                                  self.integrand_table, self.node_table,
                                  self.weight_table, self.covariate_table,
                                  self.avgint_table, self.data_table,
                                  self.prior_table, self.smooth_table, list(),
                                  self.rate_table, self.mulcov_table,
                                  self.option_table)

        if to_csv:
            flag = subprocess.call([program, file_name, 'init'])
            if flag != 0:
                sys.exit('command failed: flag = ' + str(flag))
            dismod_at.db2csv_command(file_name)
Exemplo n.º 2
0
    def init_database(self, db2csv: bool = True):

        dismod_at.create_database(self.path, self.age_list, self.time_list,
                                  self.integrand_table, self.node_table,
                                  self.weight_table, self.covariate_table,
                                  self.avgint_table, self.data_table,
                                  self.prior_table, self.smooth_table, list(),
                                  self.rate_table, self.mulcov_table,
                                  self.option_table)

        if not os.path.exists(self.path):
            os.mknod(self.path)

        command = [program, self.path, 'init']
        print(' '.join(command))
        flag = subprocess.call(command)
        if flag != 0:
            sys.exit('The dismod_at init command failed')
        if db2csv is True:
            dismod_at.db2csv_command(self.path)
Exemplo n.º 3
0
def example_db(file_name):
    from math import log

    def fun_iota_world(a, t):
        value = 'prior_iota_world_value'
        dage = 'prior_iota_world_smooth'
        return ('prior_iota_world_value', None, None)

    def fun_iota_child(a, t):
        return ('prior_iota_child_value', None, None)

    def fun_omega_world(a, t):
        return (omega_true['world'], None, None)

    def fun_omega_child_1(a, t):
        return (omega_true['child_1'], None, None)

    def fun_omega_child_2(a, t):
        return (omega_true['child_2'], None, None)

    # ----------------------------------------------------------------------
    # age table:
    age_list = [0.0, 100.0]
    #
    # time table:
    time_list = [1990.0, 2200.0]
    #
    # integrand table:
    integrand_table = [{'name': 'susceptible'}]
    #
    # node table:
    node_table = [{
        'name': 'world',
        'parent': ''
    }, {
        'name': 'child_1',
        'parent': 'world'
    }, {
        'name': 'child_2',
        'parent': 'world'
    }]
    #
    # weight table:
    weight_table = list()
    #
    # covariate table:
    covariate_table = list()
    #
    # mulcov table:
    mulcov_table = list()
    #
    # avgint table: empty
    avgint_table = list()
    # ----------------------------------------------------------------------
    # data table:
    data_table = list()
    # values that are the same for all data rows
    row = {
        'meas_value': 0.0,  # not used (will be simulated)
        'density': 'gaussian',
        'weight': '',
        'hold_out': False,
        'time_lower': 2000.,
        'time_upper': 2000.,
        'integrand': 'susceptible',
        'meas_std': 0.005,
        'subgroup': 'world'
    }
    # values that change between rows:
    node_name = ['world', 'child_1', 'child_2']
    age_value = [10, 100, 10, 100]
    time_value = [time_list[0], time_list[0], time_list[-1], time_list[-1]]
    for data_id in range(n_data):
        age = age_value[data_id % 4]
        time = time_value[data_id % 4]
        row['age_lower'] = age
        row['age_upper'] = age
        row['time_lower'] = time
        row['time_upper'] = time
        row['node'] = node_name[data_id % 3]
        data_table.append(copy.copy(row))
    #
    # ----------------------------------------------------------------------
    # prior_table
    prior_table = [
     { # prior_iota_world_value
      'name':     'prior_iota_world_value',
      'density':  'uniform',
      'lower':    iota_true['world'] / 10.,
      'upper':    iota_true['world'] * 10.,
      'mean':     iota_true['world'] * 2.0,
     },{ # prior_iota_child_value
      'name':     'prior_iota_child_value',
      'density':  'gaussian',
      'mean':     0.0,
      'std':      1.0
     },{ # prior_iota_world_smooth
      'name':     'prior_iota_world_smooth',
      'density':  'gaussian',
      'mean':     0.0,
      'std':      iota_true['world'] / 10.0
     }
    ]
    # ----------------------------------------------------------------------
    # smooth table
    smooth_table = [
        {  # smooth_iota_world
            'name': 'smooth_iota_world',
            'age_id': [0, 1],
            'time_id': [0, 1],
            'fun': fun_iota_world
        },
        {  # smooth_iota_child
            'name': 'smooth_iota_child',
            'age_id': [0],
            'time_id': [0],
            'fun': fun_iota_child
        },
        {  # smooth_omega_world
            'name': 'smooth_omega_world',
            'age_id': [0, 1],
            'time_id': [0, 1],
            'fun': fun_omega_world
        },
        {  # smooth_omega_child_1
            'name': 'smooth_omega_child_1',
            'age_id': [0],
            'time_id': [0],
            'fun': fun_omega_child_1
        },
        {  # smooth_omega_child_2
            'name': 'smooth_omega_child_2',
            'age_id': [0],
            'time_id': [0],
            'fun': fun_omega_child_2
        }
    ]
    #
    # nslist_table:
    nslist_table = dict()
    nslist_table['omega_nslist'] = [('child_1', 'smooth_omega_child_1'),
                                    ('child_2', 'smooth_omega_child_2')]
    # ----------------------------------------------------------------------
    # rate table:
    rate_table = [{
        'name': 'iota',
        'parent_smooth': 'smooth_iota_world',
        'child_smooth': 'smooth_iota_child',
    }, {
        'name': 'omega',
        'parent_smooth': 'smooth_omega_world',
        'child_nslist': 'omega_nslist',
    }]
    # ----------------------------------------------------------------------
    # option_table
    option_table = [{
        'name': 'rate_case',
        'value': 'iota_pos_rho_zero'
    }, {
        'name': 'parent_node_name',
        'value': 'world'
    }, {
        'name': 'ode_step_size',
        'value': '10.0'
    }, {
        'name': 'random_seed',
        'value': str(random_seed)
    }, {
        'name': 'quasi_fixed',
        'value': 'true'
    }, {
        'name': 'max_num_iter_fixed',
        'value': '50'
    }, {
        'name': 'print_level_fixed',
        'value': '0'
    }, {
        'name': 'tolerance_fixed',
        'value': '1e-8'
    }, {
        'name': 'max_num_iter_random',
        'value': '50'
    }, {
        'name': 'print_level_random',
        'value': '0'
    }, {
        'name': 'tolerance_random',
        'value': '1e-10'
    }, {
        'name': 'zero_sum_child_rate',
        'value': 'iota'
    }]
    # ----------------------------------------------------------------------
    # subgroup_table
    subgroup_table = [{'subgroup': 'world', 'group': 'world'}]
    # ----------------------------------------------------------------------
    # create database
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)
    # ----------------------------------------------------------------------
    return
Exemplo n.º 4
0
def example_db(file_name, meas_noise_effect):
    # ----------------------------------------------------------------------
    # age table:
    age_list = [0.0, 100.0]
    #
    # time table:
    time_list = [1990.0, 2200.0]
    #
    # integrand table:
    integrand_table = [{'name': 'Sincidence'}]
    #
    # node table:
    node_table = [{'name': 'world', 'parent': ''}]
    #
    # weight table:
    # The constant function 1.0, note any valid age and time id would work
    name = 'constant'
    fun = weight_fun
    age_id = 0
    time_id = 0
    weight_table = [{
        'name': name,
        'age_id': [age_id],
        'time_id': [time_id],
        'fun': fun
    }]
    #
    # covariate table:
    covariate_table = [{'name': 'one', 'reference': 0.0}]
    #
    # mulcov table:
    mulcov_table = [{
        'covariate': 'one',
        'type': 'meas_noise',
        'effected': 'Sincidence',
        'group': 'world',
        'smooth': 'smooth_gamma'
    }]
    #
    # avgint table: empty
    avgint_table = list()
    #
    # nslist_table:
    nslist_table = dict()
    # ----------------------------------------------------------------------
    # data table:
    data_table = list()
    # values that are the same for all data rows
    row = {
        'meas_value': 0.0,  # not used (will be simulated)
        'density': 'gaussian',
        'weight': 'constant',
        'hold_out': False,
        'time_lower': 2000.,
        'time_upper': 2000.,
        'integrand': 'Sincidence',
        'meas_std': data_std,
        'node': 'world',
        'subgroup': 'world',
        'one': 1.0
    }
    if meas_noise_effect == 'add_std_scale_all':
        delta = data_std * (1.0 + gamma_true_scale)
        gamma_true = gamma_true_scale
    elif meas_noise_effect == 'add_std_scale_log':
        delta = data_std * (1.0 + gamma_true_scale)
        gamma_true = gamma_true_scale * data_std
    elif meas_noise_effect == 'add_var_scale_all':
        delta = data_std * math.sqrt(1.0 + gamma_true_scale)
        gamma_true = gamma_true_scale
    else:
        assert meas_noise_effect == 'add_var_scale_log'
        delta = data_std * math.sqrt(1.0 + gamma_true_scale)
        gamma_true = gamma_true_scale * data_std * data_std
    # values that change between rows:
    for data_id in range(n_data):
        row['meas_value'] = random.gauss(iota_true, delta)
        fraction = data_id / float(n_data - 1)
        age = age_list[0] + (age_list[-1] - age_list[0]) * fraction
        row['age_lower'] = age
        row['age_upper'] = age
        data_table.append(copy.copy(row))
    #
    # ----------------------------------------------------------------------
    # prior_table
    prior_table = [
        {  # prior_iota
            'name': 'prior_iota',
            'density': 'uniform',
            'lower': iota_true / 100.0,
            'upper': 1.0,
            'mean': iota_true / 10.0
        },
        {  # prior_gamma
            'name': 'prior_gamma',
            'density': 'uniform',
            'lower': 0.0,
            'upper': 10.0 * gamma_true,
            'mean': gamma_true / 10.0
        }
    ]
    # ----------------------------------------------------------------------
    # smooth table
    name = 'smooth_iota'
    fun = fun_iota
    age_id = 0
    time_id = 0
    smooth_table = [{
        'name': name,
        'age_id': [age_id],
        'time_id': [time_id],
        'fun': fun
    }]
    name = 'smooth_iota'
    #
    name = 'smooth_gamma'
    fun = fun_gamma
    smooth_table.append({
        'name': name,
        'age_id': [age_id],
        'time_id': [time_id],
        'fun': fun
    })
    # ----------------------------------------------------------------------
    # rate table:
    rate_table = [{
        'name': 'iota',
        'parent_smooth': 'smooth_iota',
        'child_smooth': None
    }]
    # ----------------------------------------------------------------------
    # option_table
    option_table = [{
        'name': 'meas_noise_effect',
        'value': meas_noise_effect
    }, {
        'name': 'rate_case',
        'value': 'iota_pos_rho_zero'
    }, {
        'name': 'parent_node_name',
        'value': 'world'
    }, {
        'name': 'random_seed',
        'value': '0'
    }, {
        'name': 'zero_sum_child_rate',
        'value': 'iota'
    }, {
        'name': 'quasi_fixed',
        'value': 'false'
    }, {
        'name': 'derivative_test_fixed',
        'value': 'second-order'
    }, {
        'name': 'max_num_iter_fixed',
        'value': '100'
    }, {
        'name': 'print_level_fixed',
        'value': '0'
    }, {
        'name': 'tolerance_fixed',
        'value': '1e-10'
    }]
    # ----------------------------------------------------------------------
    # subgroup_table
    subgroup_table = [{'subgroup': 'world', 'group': 'world'}]
    # ----------------------------------------------------------------------
    # create database
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)
    # ----------------------------------------------------------------------
    return
Exemplo n.º 5
0
def example_db(file_name):
    def fun_rate_child(a, t):
        return ('prior_rate_child', None, 'prior_child_diff')

    def fun_rate_parent(a, t):
        return ('prior_rate_parent', None, 'prior_parent_diff')

    import dismod_at
    # ----------------------------------------------------------------------
    # age table
    age_list = [0.0, 50.0, 100.0]
    #
    # time table
    time_list = [1995.0, 2005.0, 2015.0]
    #
    # integrand table
    integrand_table = [{'name': 'Sincidence'}]
    #
    # node table: world -> north_america
    #             north_america -> (united_states, canada)
    node_table = [{
        'name': 'world',
        'parent': ''
    }, {
        'name': 'north_america',
        'parent': 'world'
    }, {
        'name': 'united_states',
        'parent': 'north_america'
    }, {
        'name': 'canada',
        'parent': 'north_america'
    }]
    #
    # weight table:
    weight_table = list()
    #
    # covariate table: no covriates
    covariate_table = list()
    #
    # mulcov table
    mulcov_table = list()
    #
    # avgint table:
    avgint_table = list()
    #
    # nslist_table:
    nslist_table = dict()
    # ----------------------------------------------------------------------
    # data table:
    data_table = list()
    # write out data
    row = {
        'density': 'gaussian',
        'weight': '',
        'hold_out': False,
        'time_lower': 2000.0,
        'time_upper': 2000.0,
        'age_lower': 50.0,
        'age_upper': 50.0,
        'integrand': 'Sincidence',
        'subgroup': 'world',
    }
    row['node'] = 'north_america'
    row['meas_value'] = iota_parent_true
    row['meas_std'] = row['meas_value'] * 1e-1
    data_table.append(copy.copy(row))
    #
    row['node'] = 'united_states'
    row['meas_value'] = iota_parent_true * exp(united_states_random_effect)
    row['meas_std'] = row['meas_value'] * 1e-1
    data_table.append(copy.copy(row))
    #
    row['node'] = 'canada'
    row['meas_value'] = iota_parent_true * exp(-united_states_random_effect)
    row['meas_std'] = row['meas_value'] * 1e-1
    data_table.append(copy.copy(row))
    # ----------------------------------------------------------------------
    # prior_table
    prior_table = [
     { # prior_rate_parent
      'name':     'prior_rate_parent',
      'density':  'uniform',
      'lower':    iota_parent_true / 100.,
      'upper':    iota_parent_true * 100.,
      # set prior so north_amaerica is set to value for united_states
      'mean':     iota_parent_true * exp( united_states_random_effect )
     },{ # prior_rate_child
      'name':     'prior_rate_child',
      'density':  'gaussian',
      'mean':     0.0,
      # std is very large so like a uniform distribution
      'std':      100.0,
     },{ # prior_parent_diff
      'name':     'prior_parent_diff',
      'density':  'log_gaussian',
      'mean':     0.0,
      'std':      0.1,
      'eta':      1e-8
     },{ # prior_child_diff
      'name':     'prior_child_diff',
      'density':  'gaussian',
      'mean':     0.0,
      'std':      0.1,
     }
    ]
    # ----------------------------------------------------------------------
    # smooth table
    last_time_id = 2
    smooth_table = [
        {  # smooth_rate_child
            'name': 'smooth_rate_child',
            'age_id': [0],
            'time_id': [0, last_time_id],
            'fun': fun_rate_child
        },
        {  # smooth_rate_parent
            'name': 'smooth_rate_parent',
            'age_id': [0],
            'time_id': [0, last_time_id],
            'fun': fun_rate_parent
        }
    ]
    # ----------------------------------------------------------------------
    # rate table
    rate_table = [{
        'name': 'iota',
        'parent_smooth': 'smooth_rate_parent',
        'child_smooth': 'smooth_rate_child',
    }]
    # ----------------------------------------------------------------------
    # option_table
    option_table = [{
        'name': 'parent_node_name',
        'value': 'north_america'
    }, {
        'name': 'derivative_test_random',
        'value': 'second-order'
    }, {
        'name': 'max_num_iter_random',
        'value': '100'
    }, {
        'name': 'tolerance_random',
        'value': '1e-10'
    }, {
        'name': 'method_random',
        'value': 'ipopt_solve'
    }]
    # ----------------------------------------------------------------------
    # subgroup_table
    subgroup_table = [{'subgroup': 'world', 'group': 'world'}]
    # ----------------------------------------------------------------------
    # create database
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)
    # ----------------------------------------------------------------------
    return
Exemplo n.º 6
0
def example_db(file_name):
    def fun_iota_parent(a, t):
        return ('prior_iota_parent_value', None, None)

    def fun_iota_child(a, t):
        return ('prior_iota_child', None, None)

    def fun_iota_group(a, t):
        return ('prior_iota_group', None, None)

    def fun_iota_subgroup(a, t):
        return ('prior_iota_subgroup', None, None)

    #
    # age_table
    age_list = [0.0, 100.0]
    #
    # time_table
    time_list = [1990.0, 2020.0]
    #
    # node_table
    node_table = [
        {
            'name': 'p1',
            'parent': ''
        },
        {
            'name': 'c1',
            'parent': 'p1'
        },
        {
            'name': 'c2',
            'parent': 'p1'
        },
    ]
    #
    # subgroup_table
    subgroup_table = [
        {
            'subgroup': 'none',
            'group': 'none'
        },
        {
            'subgroup': 's1',
            'group': 'g1'
        },
        {
            'subgroup': 's2',
            'group': 'g1'
        },
    ]
    # rate_table
    rate_table = [{
        'name': 'iota',
        'parent_smooth': 'smooth_iota_parent',
        'child_smooth': 'smooth_iota_child',
    }]
    # covariate_table
    covariate_table = [{'name': 'one', 'reference': 0.0}]
    # mulcov_table
    mulcov_table = [{
        'covariate': 'one',
        'type': 'rate_value',
        'effected': 'iota',
        'group': 'g1',
        'smooth': 'smooth_iota_group',
        'subsmooth': 'smooth_iota_subgroup',
    }]
    # prior_table
    prior_table = [
     {   # prior_iota_parent_value
      'name':    'prior_iota_parent_value',
      'density': 'uniform',
      'lower':   iota_parent_true / 100.0,
      'upper':   iota_parent_true * 100.0,
      'mean':    iota_parent_true / 2.0,
     },{ # prior_iota_child
      'name':    'prior_iota_child',
      'density': 'uniform',
      'mean':     1e-3,
     },{ # prior_iota_group
      'name':    'prior_iota_group',
      'density': 'uniform',
      'mean':     0.0,
     },{ # prior_iota_subgroup
      'name':    'prior_iota_subgroup',
      'density': 'uniform',
      'mean':     1e-3,
     }
    ]
    # smooth_table
    smooth_table = [
        {  # smooth_iota_parent
            'name': 'smooth_iota_parent',
            'age_id': [0],
            'time_id': [0],
            'fun': fun_iota_parent
        },
        {  # smooth_iota_child
            'name': 'smooth_iota_child',
            'age_id': [0],
            'time_id': [0],
            'fun': fun_iota_child
        },
        {  # smooth_iota_group
            'name': 'smooth_iota_group',
            'age_id': [0],
            'time_id': [0],
            'fun': fun_iota_group
        },
        {  # smooth_iota_subgroup
            'name': 'smooth_iota_subgroup',
            'age_id': [0],
            'time_id': [0],
            'fun': fun_iota_subgroup
        }
    ]
    # weight table:
    weight_table = list()
    # nslist_table
    nslist_table = dict()
    # option_table
    option_table = [
        {
            'name': 'parent_node_name',
            'value': 'p1'
        },
        {
            'name': 'rate_case',
            'value': 'iota_pos_rho_zero'
        },
        {
            'name': 'zero_sum_child_rate',
            'value': 'iota'
        },
        {
            'name': 'zero_sum_mulcov_group',
            'value': 'g1'
        },
        {
            'name': 'quasi_fixed',
            'value': 'false'
        },
        {
            'name': 'max_num_iter_fixed',
            'value': '100'
        },
        {
            'name': 'print_level_fixed',
            'value': '0'
        },
        {
            'name': 'tolerance_fixed',
            'value': '1e-12'
        },
        {
            'name': 'derivative_test_fixed',
            'value': 'adaptive'
        },
    ]
    # integrand_table
    integrand_table = [{'name': 'Sincidence'}]
    # ------------------------------------------------------------------------
    # data_table
    data_table = list()
    # values that are the same for all data points
    row = {
        'integrand': 'Sincidence',
        'density': 'gaussian',
        'weight': '',
        'hold_out': False,
        'age_lower': 50.0,
        'age_upper': 50.0,
        'time_lower': 2000.0,
        'time_upper': 2000.0,
        'one': 1.0,
    }
    for child in ['c1', 'c2']:
        for subgroup in ['s1', 's2', 'none']:
            # true value of iota for this child, subgroup
            iota = avg_integrand(child, subgroup)
            # measurement standard deviation is used during fittting
            meas_std = iota * meas_cv
            # for this example, measurements are simulated without any noise
            meas_value = iota
            #
            row['node'] = child
            row['subgroup'] = subgroup
            row['meas_value'] = meas_value
            row['meas_std'] = meas_std
            data_table.append(copy.copy(row))
    # ------------------------------------------------------------------------
    # avgint_table
    avgint_table = list()
    # ----------------------------------------------------------------------
    # create database
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)
Exemplo n.º 7
0
def example_db(file_name):
    def fun_meas_subgroup(a, t):
        return ('prior_meas_subgroup', None, 'prior_gauss_diff')

    def fun_rate_parent(a, t):
        return ('prior_rate_parent', None, 'prior_gauss_diff')

    import dismod_at
    # ----------------------------------------------------------------------
    # age list
    age_list = [0.0, 50.0, 100.0]
    #
    # time list
    time_list = [1990.0, 2010.0]
    #
    # integrand table
    integrand_table = [{'name': 'Sincidence'}, {'name': 'remission'}]
    #
    # node table: north_america -> (united_states, canada)
    node_table = [{
        'name': 'north_america',
        'parent': ''
    }, {
        'name': 'united_states',
        'parent': 'north_america'
    }, {
        'name': 'canada',
        'parent': 'north_america'
    }]
    #
    # subgroup_table
    subgroup_table = [
        {
            'subgroup': 'united_states',
            'group': 'north_america'
        },
        {
            'subgroup': 'canada',
            'group': 'north_america'
        },
    ]
    #
    # mulcov table
    mulcov_table = [
        {  # subgroup covariate multiplers effecting Sincidence
            'covariate': 'one',
            'type': 'meas_value',
            'effected': 'Sincidence',
            'group': 'north_america',
            'smooth': None,
            'subsmooth': 'smooth_meas_subgroup'
        },
        {  # subgroup covariate multipliers effecting remissions
            'covariate': 'one',
            'type': 'meas_value',
            'effected': 'remission',
            'group': 'north_america',
            'smooth': None,
            'subsmooth': 'smooth_meas_subgroup'
        }
    ]
    #
    # weight table:
    weight_table = list()
    #
    # covariate table: no covriates
    covariate_table = [{
        'name': 'one',
        'reference': 0.0,
        'max_difference': None
    }]
    #
    # avgint table: same order as list of integrands
    avgint_table = list()
    #
    # nslist_table:
    nslist_table = dict()
    # ----------------------------------------------------------------------
    # data table
    data_table = list()
    # write out data
    row = {
        'density': 'gaussian',
        'weight': '',
        'hold_out': False,
        'age_lower': 50.0,
        'age_upper': 50.0,
        'one': 1.0,
    }
    for data_id in range(number_data):
        if data_id % 2 == 0:
            row['node'] = 'united_states'
            row['subgroup'] = 'united_states'
            row['data_name'] = 'us_' + str(data_id / 2)
            effect_true = -subgroup_mulcov
        if data_id % 3 == 2:
            row['node'] = 'canada'
            row['subgroup'] = 'canada'
            row['data_name'] = 'ca_' + str(data_id / 2)
            effect_true = +subgroup_mulcov
        if data_id % 4 < 2:
            row['time_lower'] = 1990.0
            row['time_upper'] = 1990.0
        else:
            row['time_lower'] = 2010.0
            row['time_upper'] = 2010.0
        #
        if data_id < number_data / 2:
            rate_true = iota_parent
            row['integrand'] = 'Sincidence'
        else:
            rate_true = rho_parent
            row['integrand'] = 'remission'
        #
        meas_mean = math.exp(effect_true) * rate_true
        meas_std = meas_mean * measurement_cv
        row['meas_value'] = random.gauss(meas_mean, meas_std)
        row['meas_std'] = meas_std
        data_table.append(copy.copy(row))
    #
    # ----------------------------------------------------------------------
    # prior_table
    prior_table = [
     { # prior_rate_parent
      'name':     'prior_rate_parent',
      'density':  'uniform',
      'lower':    min(iota_parent, rho_parent) / 100.0,
      'upper':    max(iota_parent, rho_parent) * 100.0,
      'mean':     2.0 * max(iota_parent, rho_parent),
     },{ # prior_meas_subgroup
      'name':     'prior_meas_subgroup',
      'density':  'gaussian',
      'mean':     0.0,
      'std':      100.0, # very large so like uniform distribution
     },{ # prior_gauss_diff
      'name':     'prior_gauss_diff',
      'density':  'uniform',
      'mean':     0.0,
      'std':      100.0, # very large so like uniform distribution
     }
    ]
    # ----------------------------------------------------------------------
    # smooth table
    smooth_table = [
        {  # smooth_meas_subgroup
            'name': 'smooth_meas_subgroup',
            'age_id': [0],
            'time_id': [0, 1],
            'fun': fun_meas_subgroup
        },
        {  # smooth_rate_parent
            'name': 'smooth_rate_parent',
            'age_id': [0],
            'time_id': [0, 1],
            'fun': fun_rate_parent
        }
    ]
    # ----------------------------------------------------------------------
    # rate table
    rate_table = [{
        'name': 'iota',
        'parent_smooth': 'smooth_rate_parent',
        'child_smooth': None,
    }, {
        'name': 'rho',
        'parent_smooth': 'smooth_rate_parent',
        'child_smooth': None,
    }]
    # ----------------------------------------------------------------------
    # option_table
    option_table = [{
        'name': 'parent_node_name',
        'value': 'north_america'
    }, {
        'name': 'zero_sum_mulcov_group',
        'value': 'north_america'
    }, {
        'name': 'random_seed',
        'value': '0'
    }, {
        'name': 'ode_step_size',
        'value': '10.0'
    }, {
        'name': 'rate_case',
        'value': 'iota_pos_rho_pos'
    }, {
        'name': 'quasi_fixed',
        'value': 'true'
    }, {
        'name': 'derivative_test_fixed',
        'value': 'first-order'
    }, {
        'name': 'max_num_iter_fixed',
        'value': '100'
    }, {
        'name': 'print_level_fixed',
        'value': '0'
    }, {
        'name': 'tolerance_fixed',
        'value': '1e-7'
    }, {
        'name': 'derivative_test_random',
        'value': 'second-order'
    }, {
        'name': 'max_num_iter_random',
        'value': '100'
    }, {
        'name': 'print_level_random',
        'value': '0'
    }, {
        'name': 'tolerance_random',
        'value': '1e-10'
    }]
    # ----------------------------------------------------------------------
    # create database
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)
Exemplo n.º 8
0
def create_database():
    import dismod_at
    import copy
    #
    # file_name, age_list, time_list, integrand_table
    file_name = 'example.db'
    age_list = [50.0]
    time_list = [2000.0]
    integrand_table = [{'name': 'mtother', 'minimum_meas_cv': 0.0}]
    #
    # node_table
    node_table = [{
        'name': 'world',
        'parent': ''
    }, {
        'name': 'north_america',
        'parent': 'world'
    }, {
        'name': 'united_states',
        'parent': 'north_america'
    }, {
        'name': 'canada',
        'parent': 'north_america'
    }]
    # weight_table
    fun = constant_weight_fun
    weight_table = [{
        'name': 'constant',
        'age_id': [0],
        'time_id': [0],
        'fun': fun
    }]
    # covariate_table
    covariate_table = [{
        'name': 'sex',
        'reference': 0.0,
        'max_difference': 0.6
    }]
    # data_table
    data_table = []
    row = {
        'integrand': 'mtother',
        'density': 'log_gaussian',
        'weight': 'constant',
        'hold_out': False,
        'meas_std': 1e-5,
        'age_lower': 0.0,
        'age_upper': 100.0,
        'time_lower': 1990.0,
        'time_upper': 2010.0,
        'sex': 0.5,
        'subgroup': 'world',
    }
    row['data_name'] = 'one'
    row['node'] = 'north_america'
    row['meas_value'] = 1.0e-5
    data_table.append(copy.copy(row))
    row['data_name'] = 'two'
    row['node'] = 'united_states'
    row['meas_value'] = 1.5e-5
    data_table.append(copy.copy(row))
    row['data_name'] = 'three'
    row['node'] = 'canada'
    row['meas_value'] = 0.5e-5
    data_table.append(copy.copy(row))
    #
    # prior_table
    prior_table = [{
        'name': 'zero',
        'density': 'uniform',
        'lower': 0.0,
        'upper': 0.0,
        'mean': 0.0,
    }, {
        'name': 'one',
        'density': 'uniform',
        'lower': 1.0,
        'upper': 1.0,
        'mean': 1.0,
    }, {
        'name': 'uniform_01',
        'density': 'uniform',
        'lower': 0.0,
        'upper': 1.0,
        'mean': 0.1,
    }, {
        'name': 'gaussian_01',
        'density': 'gaussian',
        'mean': 0.0,
        'std': 1.0,
    }, {
        'name': 'log_gaussian',
        'density': 'log_gaussian',
        'mean': 0.0,
        'eta': 1e-6
    }]
    #
    # smooth list
    smooth_table = [{
        'name': 'uniform_01_constant',
        'age_id': [0],
        'time_id': [0],
        'mulstd_value_prior_name': None,
        'mulstd_dage_prior_name': None,
        'mulstd_dtime_prior_name': None,
        'fun': smooth_uniform_01_fun
    }, {
        'name': 'gaussian_01_constant',
        'age_id': [0],
        'time_id': [0],
        'mulstd_value_prior_name': None,
        'mulstd_dage_prior_name': None,
        'mulstd_dtime_prior_name': None,
        'fun': smooth_gaussian_01_fun
    }]
    #
    # rate_table
    rate_table = [{
        'name': 'pini',
        'parent_smooth': 'uniform_01_constant',
        'child_smooth': 'gaussian_01_constant',
        'child_nslist': None
    }, {
        'name': 'iota',
        'parent_smooth': 'uniform_01_constant',
        'child_smooth': 'gaussian_01_constant',
        'child_nslist': None
    }, {
        'name': 'rho',
        'parent_smooth': 'uniform_01_constant',
        'child_smooth': 'gaussian_01_constant',
        'child_nslist': None
    }, {
        'name': 'chi',
        'parent_smooth': 'uniform_01_constant',
        'child_smooth': 'gaussian_01_constant',
        'child_nslist': None
    }, {
        'name': 'omega',
        'parent_smooth': 'uniform_01_constant',
        'child_smooth': 'gaussian_01_constant',
        'child_nslist': None
    }]
    #
    # mulcov_table
    mulcov_table = [{
        'covariate': 'sex',
        'type': 'rate_value',
        'effected': 'omega',
        'group': 'world',
        'smooth': 'uniform_01_constant'
    }]
    #
    # option_table
    option_table = [{
        'name': 'parent_node_name',
        'value': 'world'
    }, {
        'name': 'ode_step_size',
        'value': '10.0'
    }, {
        'name': 'random_seed',
        'value': '0'
    }, {
        'name': 'rate_case',
        'value': 'iota_pos_rho_pos'
    }, {
        'name': 'tolerance',
        'value': '1e-8'
    }, {
        'name': 'max_num_iter',
        'value': '100'
    }, {
        'name': 'print_level',
        'value': '0'
    }, {
        'name': 'derivative_test',
        'value': 'second-order'
    }]
    # avgint_table
    avgint_table = []
    row = {
        'integrand': 'mtother',
        'weight': 'constant',
        'age_lower': 0.0,
        'age_upper': 100.0,
        'time_lower': 1990.0,
        'time_upper': 2010.0,
        'sex': 0.5,
        'subgroup': 'world',
    }
    row['node'] = 'north_america'
    avgint_table.append(copy.copy(row))
    row['node'] = 'united_states'
    avgint_table.append(copy.copy(row))
    row['node'] = 'canada'
    row['meas_value'] = 0.5e-5
    avgint_table.append(copy.copy(row))
    # nslist_table
    nslist_table = dict()
    #
    # ----------------------------------------------------------------------
    # subgroup_table
    subgroup_table = [{'subgroup': 'world', 'group': 'world'}]
    # ----------------------------------------------------------------------
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)
    # ----------------------------------------------------------------------
    # Check database
    # ----------------------------------------------------------------------
    #
    # connection
    new = False
    connection = dismod_at.create_connection(file_name, new)
    #
    # age_table
    tbl_name = 'age'
    col_name = ['age']
    row_list = dismod_at.get_row_list(connection, tbl_name, col_name)
    col_list = column_as_list(row_list, 0)
    assert col_list == age_list
    #
    # time_table
    tbl_name = 'time'
    col_name = ['time']
    row_list = dismod_at.get_row_list(connection, tbl_name, col_name)
    col_list = column_as_list(row_list, 0)
    assert col_list == time_list
    #
    # intergrand_table
    tbl_name = 'integrand'
    col_name = ['integrand_name']
    row_list = dismod_at.get_row_list(connection, tbl_name, col_name)
    check_list = [['mtother']]
    assert row_list == check_list
    #
    # weight_table
    tbl_name = 'weight'
    col_name = ['weight_name', 'n_age', 'n_time']
    row_list = dismod_at.get_row_list(connection, tbl_name, col_name)
    check_list = [['constant', 1, 1]]
    assert row_list == check_list
    #
    # weight_grid_table
    tbl_name = 'weight_grid'
    col_name = ['weight_id', 'age_id', 'time_id', 'weight']
    row_list = dismod_at.get_row_list(connection, tbl_name, col_name)
    check_list = [[0, 0, 0, 1.0]]
    assert row_list == check_list
    #
    # covariate_table
    tbl_name = 'covariate'
    col_name = ['covariate_name', 'reference']
    row_list = dismod_at.get_row_list(connection, tbl_name, col_name)
    check_list = [['sex', 0.0]]
    assert row_list == check_list
    #
    # node_table
    tbl_name = 'node'
    col_name = ['node_name', 'parent']
    row_list = dismod_at.get_row_list(connection, tbl_name, col_name)
    check_list = [['world', None], ['north_america', 0], ['united_states', 1],
                  ['canada', 1]]
    assert row_list == check_list
    #
    # data_table
    tbl_name = 'data'
    col_name = ['integrand_id', 'node_id', 'meas_value', 'meas_std']
    row_list = dismod_at.get_row_list(connection, tbl_name, col_name)
    check_list = [[0, 1, 1.0e-5, 1e-5], [0, 2, 1.5e-5, 1e-5],
                  [0, 3, 0.5e-5, 1e-5]]
    assert row_list == check_list
    #
    # prior_table
    tbl_name = 'prior'
    col_name = ['prior_name', 'density_id', 'lower', 'upper']
    row_list = dismod_at.get_row_list(connection, tbl_name, col_name)
    check_list = [['zero', 0, 0.0, 0.0], ['one', 0, 1.0, 1.0],
                  ['uniform_01', 0, 0.0, 1.0], ['gaussian_01', 1, None, None],
                  ['log_gaussian', 4, None, None]]
    assert row_list == check_list
    #
    # smooth_table
    tbl_name = 'smooth'
    col_name = [
        'smooth_name', 'n_age', 'n_time', 'mulstd_value_prior_id',
        'mulstd_dage_prior_id', 'mulstd_dtime_prior_id'
    ]
    row_list = dismod_at.get_row_list(connection, tbl_name, col_name)
    check_list = [['uniform_01_constant', 1, 1, None, None, None],
                  ['gaussian_01_constant', 1, 1, None, None, None]]
    assert row_list == check_list
    #
    # smooth_grid_table
    tbl_name = 'smooth_grid'
    col_name = [
        'smooth_id', 'age_id', 'time_id', 'value_prior_id', 'dage_prior_id',
        'dtime_prior_id'
    ]
    row_list = dismod_at.get_row_list(connection, tbl_name, col_name)
    check_list = [[0, 0, 0, 2, None, None], [1, 0, 0, 3, None, None]]
    assert row_list == check_list
    #
    # rate_table
    tbl_name = 'rate'
    col_name = ['rate_name', 'parent_smooth_id', 'child_smooth_id']
    row_list = dismod_at.get_row_list(connection, tbl_name, col_name)
    check_list = [['pini', 0, 1], ['iota', 0, 1], ['rho', 0, 1], ['chi', 0, 1],
                  ['omega', 0, 1]]
    assert row_list == check_list
    #
    # mulcov_table
    tbl_name = 'mulcov'
    col_name = [
        'mulcov_type', 'rate_id', 'integrand_id', 'covariate_id', 'group_id',
        'subgroup_smooth_id', 'group_smooth_id'
    ]
    row_list = dismod_at.get_row_list(connection, tbl_name, col_name)
    check_list = [['rate_value', 4, None, 0, 0, None, 0]]
    assert row_list == check_list
    #
    # option_table
    tbl_name = 'option'
    col_name = ['option_name', 'option_value']
    row_list = dismod_at.get_row_list(connection, tbl_name, col_name)
    check_list = [['parent_node_name', 'world'], ['ode_step_size', '10.0'],
                  ['random_seed', '0'], ['rate_case', 'iota_pos_rho_pos'],
                  ['tolerance', '1e-8'], ['max_num_iter', '100'],
                  ['print_level', '0'], ['derivative_test', 'second-order']]
    assert row_list == check_list
    #
    # avgint_table
    tbl_name = 'avgint'
    col_name = ['integrand_id', 'node_id', 'age_lower', 'age_upper']
    row_list = dismod_at.get_row_list(connection, tbl_name, col_name)
    check_list = [[0, 1, 0.0, 100.0], [0, 2, 0.0, 100.0], [0, 3, 0.0, 100.0]]
    assert row_list == check_list
    # ----------------------------------------------------------------------
    connection.close()
    print('create_database: OK')
Exemplo n.º 9
0
def example_db (file_name) :
	# ----------------------------------------------------------------------
	# age table:
	age_list    = [ 0.0, 5.0, 15.0, 35.0, 50.0, 75.0, 90.0, 100.0 ]
	#
	# time table:
	time_list   = [ 1990.0, 2000.0, 2010.0, 2200.0 ]
	#
	# integrand table:
	integrand_table = [
		 { 'name':'prevalence', 'minimum_meas_cv':0.0 }
	]
	#
	# node table:
	node_table = [ { 'name':'world', 'parent':'' } ]
	for i in range(n_children) :
		name = 'child_' + str(i + 1)
		node_table.append( { 'name':name, 'parent':'world' } )
	#
	# weight table:
	weight_table = list()
	#
	# covariate table:
	covariate_table = [
		{'name':'income', 'reference':0.5, 'max_difference':None}
	]
	#
	# mulcov table:
	mulcov_table = [
		{
			'covariate': 'income',
			'type':      'rate_value',
			'effected':  'iota',
			'group':     'world',
			'smooth':    'smooth_mulcov'
		}
	]
	# ----------------------------------------------------------------------
	# data table:
	data_table = list()
	#
	density_list = [ "gaussian", "students", "log_gaussian", "log_students" ]
	# values that are the same for all data rows
	row = {
		'meas_value':  1.,   # measurement is way off truth and not used
		'eta':         1e-6,
		'nu':          10,
		'weight':      '',
		'hold_out':     False,
		'time_lower':   2000.,
		'time_upper':   2000.,
		'subgroup':     'world',
	}
	# values that change between rows:
	for data_id in range( n_data ) :
		density          = density_list[ data_id % 4 ]
		row['density']   = density
		#
		# one percent coefficient of variation
		if density == 'gaussian' or density == 'students' :
			row['meas_std'] = iota_parent_true / 100.
		else :
			row['meas_std'] = row['meas_value'] / 100.
		fraction         = data_id / float(n_data-1)
		age              = age_list[0] + (age_list[-1] - age_list[0])*fraction
		row['age_lower'] = age
		row['age_upper'] = age
		row['node']      = 'child_' + str( (data_id % n_children) + 1 )
		row['income']    = fraction
		row['integrand'] = integrand_table[0]['name']
		data_table.append( copy.copy(row) )
	#
	# ----------------------------------------------------------------------
	# prior_table
	prior_table = [
		{   # prior_zero
			'name':     'prior_zero',
			'density':  'uniform',
			'lower':    0.0,
			'upper':    0.0,
			'mean':     0.0,
			'std':      None,
			'eta':      None
		}, { # prior_none
			'name':     'prior_none',
			'density':  'uniform',
			'lower':    None,
			'upper':    None,
			'mean':     0.0,
			'std':      None,
			'eta':      None
		},{ # prior_gauss_zero
			'name':     'prior_gauss_zero',
			'density':  'gaussian',
			'lower':    None,
			'upper':    None,
			'mean':     0.0,
			'std':      0.01,
			'eta':      None
		},{ # prior_loggauss_zero
			'name':     'prior_loggauss_zero',
			'density':  'log_gaussian',
			'lower':    None,
			'upper':    None,
			'mean':     0.0,
			'std':      0.1,
			'eta':      1e-6
		},{ # prior_iota_parent
			'name':     'prior_iota_parent',
			'density':  'uniform',
			'lower':    iota_parent_true / 100.,
			'upper':    iota_parent_true * 10.0,
			'mean':     iota_parent_true / 2.0,
			'std':      None,
			'eta':      None
		},{ # prior_mulcov
			'name':     'prior_mulcov',
			'density':  'uniform',
			'lower':    -2.0,
			'upper':    +2.0,
			'mean':     0.0,
			'std':      None,
			'eta':      None
		}
	]
	# ----------------------------------------------------------------------
	# smooth table
	name           = 'smooth_rate_child'
	fun            = fun_rate_child
	age_id         = int( len( age_list ) / 2 )
	time_id        = int( len( time_list ) / 2 )
	smooth_table = [
		{'name':name, 'age_id':[age_id], 'time_id':[time_id], 'fun':fun }
	]
	name = 'smooth_iota_parent'
	fun  = fun_iota_parent
	smooth_table.append(
		{'name':name, 'age_id':[age_id], 'time_id':[time_id], 'fun':fun }
	)
	name = 'smooth_mulcov'
	fun  = fun_mulcov
	smooth_table.append(
		{'name':name, 'age_id':[age_id], 'time_id':[time_id], 'fun':fun }
	)
	# no standard deviation multipliers
	for dictionary in smooth_table :
		for name in [ 'value' , 'dage', 'dtime' ] :
			key   = 'mulstd_' + name + '_prior_name'
			value = None
			dictionary[key] = value
	# ----------------------------------------------------------------------
	# rate table:
	rate_table = [
		{	'name':          'iota',
			'parent_smooth': 'smooth_iota_parent',
			'child_smooth':  'smooth_rate_child',
			'child_nslist':  None
		},
	]
	# ----------------------------------------------------------------------
	# option_table
	option_table = [
		{ 'name':'rate_case',              'value':'iota_pos_rho_zero' },
		{ 'name':'parent_node_name',       'value':'world'             },
		{ 'name':'ode_step_size',          'value':'10.0'              },
		{ 'name':'random_seed',            'value':random_seed_str     },
		{ 'name':'zero_sum_child_rate',    'value':'iota'              },

		{ 'name':'quasi_fixed',            'value':'true'              },
		{ 'name':'derivative_test_fixed',  'value':'none'              },
		{ 'name':'max_num_iter_fixed',     'value':'100'               },
		{ 'name':'print_level_fixed',      'value':'0'                 },
		{ 'name':'tolerance_fixed',        'value':'1e-6'              },

		{ 'name':'derivative_test_random', 'value':'none'              },
		{ 'name':'max_num_iter_random',    'value':'100'               },
		{ 'name':'print_level_random',     'value':'0'                 },
		{ 'name':'tolerance_random',       'value':'1e-8'              },
		{ 'name':'method_random',          'value':'ipopt_random'      }
	]
	# ----------------------------------------------------------------------
	# avgint table: empty
	avgint_table = list()
	# ----------------------------------------------------------------------
	# nslist_table:
	nslist_table = dict()
	# ----------------------------------------------------------------------
	# subgroup_table
	subgroup_table = [ { 'subgroup':'world', 'group':'world' } ]
	# ----------------------------------------------------------------------
	# create database
	dismod_at.create_database(
		file_name,
		age_list,
		time_list,
		integrand_table,
		node_table,
		subgroup_table,
		weight_table,
		covariate_table,
		avgint_table,
		data_table,
		prior_table,
		smooth_table,
		nslist_table,
		rate_table,
		mulcov_table,
		option_table
	)
	# ----------------------------------------------------------------------
	return
Exemplo n.º 10
0
def example_db (file_name) :
	def fun_rate_parent(a, t) :
		return ('prior_iota_parent', None, None)
	import dismod_at
	# ----------------------------------------------------------------------
	# age table
	age_list    = [    0.0, 50.0,    100.0 ]
	#
	# time table
	time_list   = [ 1995.0, 2005.0, 2015.0 ]
	#
	# integrand table
	integrand_table = [
		{ 'name':'Sincidence' }
	]
	#
	# node table: north_america -> (united_states, canada)
	node_table = [
		{ 'name':'north_america', 'parent':'' },
		{ 'name':'united_states', 'parent':'north_america' },
		{ 'name':'canada',        'parent':'north_america' }
	]
	#
	# weight table:
	weight_table = list()
	#
	# covariate table: no covriates
	covariate_table = list()
	#
	# mulcov table
	mulcov_table = list()
	#
	# avgint table: same order as list of integrands
	avgint_table = list()
	#
	# nslist_table:
	nslist_table = dict()
	# ----------------------------------------------------------------------
	# data table: same order as list of integrands
	data_table = list()
	meas_std = meas_cv * iota_true
	row = {
		'density':     'gaussian',
		'weight':      '',
		'hold_out':     False,
		'time_lower':   2000.0,
		'time_upper':   2000.0,
		'age_lower':    50.0,
		'age_upper':    50.0,
		'integrand':    'Sincidence',
		'meas_std':     meas_std,
		'nu':           nu
	}
	random.seed(random_seed)
	for data_id in range( n_data ):
		row['node'] = 'north_america'
		meas_value  = random.gauss(iota_true, meas_std)
		#
		if data_id < n_outlier :
			meas_value = random.gauss( 10.0 * iota_true, 2.0 * iota_true )
		row['meas_value']  = meas_value
		data_table.append( copy.copy(row) )
	#
	# ----------------------------------------------------------------------
	# prior_table
	prior_table = [
		{ # prior_iota_parent
			'name':     'prior_iota_parent',
			'density':  'uniform',
			'lower':    1e-4,
			'upper':    1.0,
			'mean':     0.1,
		}
	]
	# ----------------------------------------------------------------------
	# smooth table
	smooth_table = [
		{ # smooth_rate_parent
			'name':                     'smooth_rate_parent',
			'age_id':                   [ 0 ],
			'time_id':                  [ 0 ],
			'fun':                      fun_rate_parent
		}
	]
	# ----------------------------------------------------------------------
	# rate table
	rate_table = [
		{
			'name':          'iota',
			'parent_smooth': 'smooth_rate_parent',
		}
	]
	# ----------------------------------------------------------------------
	# option_table
	option_table = [
		{ 'name':'parent_node_name',       'value':'north_america'     },
		{ 'name':'ode_step_size',          'value':'10.0'              },
		{ 'name':'rate_case',              'value':'iota_pos_rho_zero' },

		{ 'name':'quasi_fixed',            'value':'false'             },
		{ 'name':'max_num_iter_fixed',     'value':'100'               },
		{ 'name':'print_level_fixed',      'value':'0'                 },
		{ 'name':'tolerance_fixed',        'value':'1e-11'             },
	]
	# ----------------------------------------------------------------------
	# subgroup_table
	subgroup_table = [ { 'subgroup':'world', 'group':'world' } ]
	# ----------------------------------------------------------------------
	# create database
	dismod_at.create_database(
		file_name,
		age_list,
		time_list,
		integrand_table,
		node_table,
		subgroup_table,
		weight_table,
		covariate_table,
		avgint_table,
		data_table,
		prior_table,
		smooth_table,
		nslist_table,
		rate_table,
		mulcov_table,
		option_table
	)
Exemplo n.º 11
0
def get_started_db():
    import dismod_at
    from math import exp
    # ----------------------------------------------------------------------
    # age list
    age_list = [0.0, 100.0]
    #
    # time list
    time_list = [1995.0, 2015.0]
    #
    # only one integrand in this example
    integrand_table = [{'name': 'susceptible'}]
    #
    # just the world (which has no parent)
    node_table = [{'name': 'world', 'parent': ''}]
    #
    # weight table is represented by one (age, time) point with value 1.0
    fun = constant_one_fun
    weight_table = [{
        'name': 'constant_one',
        'age_id': [0],
        'time_id': [0],
        'fun': fun
    }]
    #
    # covariate table: the reference value for income is zero
    covariate_table = [{'name': 'income', 'reference': 0.0}]
    # ---------------------------------------------------------------------
    # avgint table: predict the susceptible fraction for no income at age 100
    avgint_table = [{
        'avgint_info': 'a0',
        'integrand': 'susceptible',
        'node': 'world',
        'subgroup': 'world',
        'weight': 'constant_one',
        'age_lower': 100.0,
        'age_upper': 100.0,
        'time_lower': 2000.0,
        'time_upper': 2000.0,
        'income': 0.0,
    }]
    # ---------------------------------------------------------------------
    # data table: measure the susceptible fraction for income 1000 at age 50
    # (no noise in this simulated data, but modeled as having noise)
    adjusted_omega = unknown_omega_world * exp(
        known_income_multiplier * 1000.0)
    meas_value = exp(-adjusted_omega * 50.0)
    meas_std = meas_value / 20.
    data_table = [{
        'c_data_info': 'd1',
        'integrand': 'susceptible',
        'node': 'world',
        'subgroup': 'world',
        'weight': 'constant_one',
        'age_lower': 50.0,
        'age_upper': 50.0,
        'time_lower': 2000.0,
        'time_upper': 2000.0,
        'income': 1000.0,
        'density': 'gaussian',
        'hold_out': False,
        'meas_value': meas_value,
        'meas_std': meas_std,
    }]
    # ---------------------------------------------------------------------
    # prior_table
    prior_table = [
     {   # prior_not_used
      # (not used because there are no age or time differences)
      'name':     'prior_not_used',
      'density':  'uniform',
      'mean':     0.0,
     },{ # prior_omega_parent
      # omega for the parent is constant in (age, time) and
      # and is a uniform distribution on the interval [1e-4, 1.0].
      # Becasue the prior is uniform, its mean 1e-1 is only used to
      # start the optimization
      'name':     'prior_omega_parent',
      'density':  'uniform',
      'lower':    1e-4,
      'upper':    1.0,
      'mean':     1e-1,
     },{ # prior_income_multiplier
      # (constrained to be equal to know_income_multiplier)
      'name':     'prior_income_multiplier',
      'density':  'uniform',
      'lower':    known_income_multiplier,
      'upper':    known_income_multiplier,
      'mean':     known_income_multiplier,
     }
    ]
    # ---------------------------------------------------------------------
    # smooth table:
    smooth_table = [
        {  # smooth_omega_parent
            'name': 'smooth_omega_parent',
            'age_id': [0],
            'time_id': [0],
            'fun': fun_omega_parent
        },
        {  # smooth_income_multiplier
            'name': 'smooth_income_multiplier',
            'age_id': [0],
            'time_id': [0],
            'fun': fun_income_multiplier
        }
    ]
    # ---------------------------------------------------------------------
    # rate table
    rate_table = [{
        'name': 'omega',
        'parent_smooth': 'smooth_omega_parent',
    }]
    # -------------------------------------------------------------------
    # mulcov table: there is one covariate multiplier for income and it
    # affects the other cause mortality rate:
    mulcov_table = [{
        'covariate': 'income',
        'type': 'rate_value',
        'effected': 'omega',
        'group': 'world',
        'smooth': 'smooth_income_multiplier'
    }]
    # -------------------------------------------------------------------
    # option_table
    option_table = [{
        'name': 'parent_node_name',
        'value': 'world'
    }, {
        'name': 'ode_step_size',
        'value': '10.0'
    }, {
        'name': 'age_avg_split',
        'value': '5.0'
    }, {
        'name': 'rate_case',
        'value': 'iota_zero_rho_zero'
    }, {
        'name': 'avgint_extra_columns',
        'value': 'avgint_info'
    }, {
        'name': 'data_extra_columns',
        'value': 'c_data_info'
    }]
    # ---------------------------------------------------------------------
    # nslist_table:
    nslist_table = dict()
    # ----------------------------------------------------------------------
    # subgroup_table
    subgroup_table = [{'subgroup': 'world', 'group': 'world'}]
    # ----------------------------------------------------------------------
    # create database
    file_name = 'get_started.db'
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)
Exemplo n.º 12
0
def example_db(file_name):
    def fun_chi(a, t):
        return ('prior_chi', 'prior_dchi', None)

    # ----------------------------------------------------------------------
    # age table:
    age_list = [0.0, 100.0]
    #
    # time table:
    time_list = [1990.0, 2010.0]
    #
    # integrand table:
    integrand_table = [{'name': 'mtexcess'}]
    #
    # node table:
    node_table = [{'name': 'world', 'parent': ''}]
    #
    # weight table:
    weight_table = list()
    #
    # covariate table: empty
    covariate_table = list()
    #
    # mulcov table: empty
    mulcov_table = list()
    #
    # avgint table: empty
    avgint_table = list()
    #
    # nslist_table:
    nslist_table = dict()
    # ----------------------------------------------------------------------
    # data table:
    data_table = list()
    #
    # values that are the same for all data rows
    row = {
        'meas_value': chi_bar,
        'density': 'gaussian',
        'weight': '',
        'hold_out': False,
        'age_lower': age_list[0],
        'age_upper': age_list[0],
        'time_lower': 2000.,
        'time_upper': 2000.,
        'integrand': 'mtexcess',
        'meas_std': sigma,
        'node': 'world'
    }
    data_table.append(row)
    # ----------------------------------------------------------------------
    # prior_table
    prior_table = [
        {  # prior_chi
            'name': 'prior_chi',
            'density': 'uniform',
            'lower': 0.0,
            'upper': 1.0,
            'mean': 0.0
        },
        {  # prior_dchi
            'name': 'prior_dchi',
            'density': 'gaussian',
            'lower': None,
            'upper': None,
            'mean': 0.0,
            'std': delta
        }
    ]
    # ----------------------------------------------------------------------
    # smooth table
    name = 'smooth_chi'
    fun = fun_chi
    smooth_table = [{
        'name': name,
        'age_id': [0, 1],
        'time_id': [0],
        'fun': fun
    }]
    # ----------------------------------------------------------------------
    # rate table:
    rate_table = [{
        'name': 'chi',
        'parent_smooth': 'smooth_chi',
        'child_smooth': None
    }]
    # ----------------------------------------------------------------------
    # option_table
    option_table = [{
        'name': 'rate_case',
        'value': 'iota_zero_rho_zero'
    }, {
        'name': 'parent_node_name',
        'value': 'world'
    }, {
        'name': 'random_seed',
        'value': '0'
    }, {
        'name': 'quasi_fixed',
        'value': 'false'
    }, {
        'name': 'derivative_test_fixed',
        'value': 'second-order'
    }, {
        'name': 'max_num_iter_fixed',
        'value': '100'
    }, {
        'name': 'print_level_fixed',
        'value': '0'
    }, {
        'name': 'tolerance_fixed',
        'value': '1e-8'
    }]
    # ----------------------------------------------------------------------
    # subgroup_table
    subgroup_table = [{'subgroup': 'world', 'group': 'world'}]
    # ----------------------------------------------------------------------
    # create database
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)
    # ----------------------------------------------------------------------
    return
Exemplo n.º 13
0
def example_db(file_name):
    def fun_rate_parent(a, t):
        return ('prior_rate_parent', None, 'prior_gauss_zero')

    # ----------------------------------------------------------------------
    # age table
    age_list = [0.0, 50.0, 100.0]
    #
    # time table
    time_list = [1995.0, 2005.0, 2015.0]
    #
    # integrand table
    integrand_table = [{
        'name': 'prevalence'
    }, {
        'name': 'Sincidence'
    }, {
        'name': 'remission'
    }, {
        'name': 'mtexcess'
    }, {
        'name': 'mtother'
    }]
    #
    # node table: world -> north_america
    #             north_america -> (united_states, canada)
    node_table = [{
        'name': 'world',
        'parent': ''
    }, {
        'name': 'north_america',
        'parent': 'world'
    }, {
        'name': 'united_states',
        'parent': 'north_america'
    }, {
        'name': 'canada',
        'parent': 'north_america'
    }]
    #
    # weight table:
    weight_table = list()
    #
    # covariate table: no covriates
    covariate_table = list()
    #
    # mulcov table
    mulcov_table = list()
    #
    # nslist_table:
    nslist_table = dict()
    # ----------------------------------------------------------------------
    # avgint table: same order as list of integrands
    avgint_table = list()
    # values that are the same for all data rows
    row = {
        'node': 'canada',
        'subgroup': 'world',
        'weight': '',
        'time_lower': 2000.0,
        'time_upper': 2000.0,
        'age_lower': 0.0
    }
    # values that change between rows: (one data point for each integrand)
    for avgint_id in range(len(integrand_table)):
        integrand = integrand_table[avgint_id]['name']
        row['integrand'] = integrand
        if integrand == 'prevalence':
            # prevalence is measured at age zero
            row['age_upper'] = 0.0
        else:
            # other integrands are averaged from age zero to one hundred
            row['age_upper'] = 100.0
        avgint_table.append(copy.copy(row))
    # ----------------------------------------------------------------------
    # data table: same order as list of integrands
    data_table = list()
    # values that are the same for all data rows
    row = {
        'node': 'canada',
        'subgroup': 'world',
        'density': 'gaussian',
        'weight': '',
        'hold_out': False,
        'time_lower': 2000.0,
        'time_upper': 2000.0,
        'age_lower': 0.0
    }
    # values that change between rows: (one data point for each integrand)
    for integrand_id in range(len(integrand_table)):
        rate_id = integrand_id
        meas_value = 1e-2 * (rate_id + 1)
        meas_std = 0.2 * meas_value
        integrand = integrand_table[integrand_id]['name']
        row['meas_value'] = meas_value
        row['meas_std'] = meas_std
        row['integrand'] = integrand
        if integrand == 'prevalence':
            # prevalence is measured at age zero
            row['age_upper'] = 0.0
        else:
            # other integrands are averaged from age zero to one hundred
            row['age_upper'] = 100.0
        # data_id = rate_id = integand_id
        data_table.append(copy.copy(row))
    #
    # add one outlyer at end of data table with hold_out true
    row['hold_out'] = True  # if outlyer were false, fit would fail
    row['integrand'] = data_table[0]['integrand']
    row['meas_std'] = data_table[0]['meas_std']
    row['eta'] = None
    row['age_upper'] = data_table[0]['age_upper']
    row['meas_value'] = 10. * data_table[0]['meas_value']
    data_table.append(copy.copy(row))
    #
    # ----------------------------------------------------------------------
    # prior_table
    prior_table = [
     { # prior_rate_parent
      'name':     'prior_rate_parent',
      'density':  'uniform',
      'lower':    1e-4,
      'upper':    1.0,
      'mean':     1e-1,
     },{ # prior_gauss_zero
      'name':     'prior_gauss_zero',
      'density':  'gaussian',
      'mean':     0.0,
      'std':      1e-2,
     }
    ]
    # ----------------------------------------------------------------------
    # smooth table
    middle_age_id = 1
    last_time_id = 2
    smooth_table = [{  # smooth_rate_parent
        'name': 'smooth_rate_parent',
        'age_id': [middle_age_id],
        'time_id': [0, last_time_id],
        'fun': fun_rate_parent
    }]
    # ----------------------------------------------------------------------
    # rate table
    rate_table = [{
        'name': 'pini',
        'parent_smooth': 'smooth_rate_parent',
    }, {
        'name': 'iota',
        'parent_smooth': 'smooth_rate_parent',
    }, {
        'name': 'rho',
        'parent_smooth': 'smooth_rate_parent',
    }, {
        'name': 'chi',
        'parent_smooth': 'smooth_rate_parent',
    }, {
        'name': 'omega',
        'parent_smooth': 'smooth_rate_parent',
    }]
    # ----------------------------------------------------------------------
    # option_table
    option_table = [{
        'name': 'parent_node_name',
        'value': 'canada'
    }, {
        'name': 'ode_step_size',
        'value': '10.0'
    }, {
        'name': 'random_seed',
        'value': '0'
    }, {
        'name': 'rate_case',
        'value': 'iota_pos_rho_pos'
    }, {
        'name': 'quasi_fixed',
        'value': 'true'
    }, {
        'name': 'derivative_test_fixed',
        'value': 'first-order'
    }, {
        'name': 'max_num_iter_fixed',
        'value': '100'
    }, {
        'name': 'print_level_fixed',
        'value': '0'
    }, {
        'name': 'tolerance_fixed',
        'value': '1e-10'
    }, {
        'name': 'derivative_test_random',
        'value': 'second-order'
    }, {
        'name': 'max_num_iter_random',
        'value': '100'
    }, {
        'name': 'print_level_random',
        'value': '0'
    }, {
        'name': 'tolerance_random',
        'value': '1e-10'
    }]
    # ----------------------------------------------------------------------
    # subgroup_table
    subgroup_table = [{'subgroup': 'world', 'group': 'world'}]
    # ----------------------------------------------------------------------
    # create database
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)
    # ----------------------------------------------------------------------
    n_smooth = len(smooth_table)
    rate_true = []
    for rate_id in range(len(data_table)):
        # for this particular example
        data_id = rate_id
        meas_value = data_table[data_id]['meas_value']
        rate_true.append(meas_value)
    #
    return (n_smooth, rate_true)
Exemplo n.º 14
0
def example_db (file_name) :
	# ----------------------------------------------------------------------
	# time table
	time_list   = [ 1990.0, 2015.0 ]
	#
	# integrand table
	integrand_table = [
		{ 'name':'Sincidence', 'minimum_meas_cv':0.0 }
	]
	#
	# node table: world
	node_table = [
		{ 'name':'world',         'parent':'' }
	]
	#
	# weight table: The constant function 1.0 (one age and one time point)
	weight_table = [
		{ 'name':'weight_one',  'age_id':[1], 'time_id':[1], 'fun':fun_one }
	]
	#
	# covariate table:
	covariate_table = list()
	#
	# mulcov table
	mulcov_table = list()
	#
	# ----------------------------------------------------------------------
	# data table: order for value_list
	#	'integrand',  'density',    'node',      'weight',      'hold_out',
	#	'meas_value', 'meas_std',   'age_lower', 'age_upper',
	#   'time_lower', 'time_upper', 'sex',       'one',         'subgroup'
	data_table = list()
	#
	# Sincidence
	value_list = [
		'Sincidence', 'log_gaussian', 'world',    'weight_one',  0,
		4.0e-3,       2.0e-3,         1e-6,        40,          40,
		1995,         1995,           0.0,         1,           'world'
	]
	data_table.append( data_list2dict( value_list ) );
	#
	value_list = [
		'Sincidence', 'log_gaussian', 'world',    'weight_one',  0,
		4.0e-2,       2.0e-2,         1e-6,        100,          100,
		1995,         1995,           0.0,         1,           'world'
	]
	data_table.append( data_list2dict( value_list ) );
	#
	# ----------------------------------------------------------------------
	# prior_table
	prior_table = [
		{   # prior_zero
			'name':     'prior_zero',
			'density':  'uniform',
			'lower':    0.0,
			'upper':    0.0,
			'mean':     0.0,
			'std':      None,
			'eta':      None
		},{ # prior_rate
			'name':     'prior_rate',
			'density':  'log_gaussian',
			'lower':    1e-5,
			'upper':    1e+0,
			'mean':     1e-2,
			'std':      1e-0,
			'eta':      1e-6
		},{ # prior_difference
			'name':     'prior_difference',
			'density':  'log_gaussian',
			'lower':    None,
			'upper':    None,
			'mean':     0.0,
			'std':      1.0,
			'eta':      1e-6
		}
	]
	# ----------------------------------------------------------------------
	# smooth table
	middle_age_id  = 1
	last_time_id   = 2
	smooth_table = [
		{
		# smooth_rate
			'name':                     'smooth_rate',
			'age_id':                   range(len(age_list)),
			'time_id':                  [0],
			'mulstd_value_prior_name':  None,
			'mulstd_dage_prior_name':   None,
			'mulstd_dtime_prior_name':  None,
			'fun':                      fun_rate
		}
	]
	# ----------------------------------------------------------------------
	# rate table
	rate_table = [
		{
			'name':          'pini',
			'parent_smooth': None,
			'child_smooth':  None,
			'child_nslist':  None
		},{
			'name':          'iota',
			'parent_smooth': 'smooth_rate',
			'child_smooth':  None,
			'child_nslist':  None
		},{
			'name':          'rho',
			'parent_smooth': None,
			'child_smooth':  None,
			'child_nslist':  None
		},{
			'name':          'chi',
			'parent_smooth': None,
			'child_smooth':  None,
			'child_nslist':  None
		},{
			'name':          'omega',
			'parent_smooth': None,
			'child_smooth':  None,
			'child_nslist':  None
		}
	]
	# ----------------------------------------------------------------------
	# option_table
	option_table = [
		{ 'name':'parent_node_name',       'value':'world'             },
		{ 'name':'rate_case',              'value':'iota_pos_rho_zero' },
		#
		{ 'name':'quasi_fixed',            'value':'false'             },
		{ 'name':'derivative_test_fixed',  'value':'first-order'       },
		#
		{ 'name':'derivative_test_random', 'value':'second-order'      }
	]
	# ----------------------------------------------------------------------
	# avgint table: same order as list of integrands
	avgint_table = list()
	# ----------------------------------------------------------------------
	# nslist_table:
	nslist_table = dict()
	# ----------------------------------------------------------------------
	# subgroup_table
	subgroup_table = [ { 'subgroup':'world', 'group':'world' } ]
	# ----------------------------------------------------------------------
	# create database
	dismod_at.create_database(
		file_name,
		age_list,
		time_list,
		integrand_table,
		node_table,
		subgroup_table,
		weight_table,
		covariate_table,
		avgint_table,
		data_table,
		prior_table,
		smooth_table,
		nslist_table,
		rate_table,
		mulcov_table,
		option_table
	)
	return
Exemplo n.º 15
0
def example_db(file_name):
    def fun_prevalence(a, t):
        return ('prior_prevalence', 'prior_dage', 'prior_dtime')

    def fun_mulcov(a, t):
        return ('prior_mulcov', None, None)

    # ----------------------------------------------------------------------
    # age table:
    age_list = [0.0, 5.0, 10.0, 20.0, 40.0, 60.0, 80.0, 100.0]
    #
    # time table:
    time_list = [1990.0, 2200.0]
    #
    # integrand table:
    integrand_table = [{'name': 'remission'}]
    #
    # node table:
    node_table = [{'name': 'world', 'parent': ''}]
    #
    # weight table:
    weight_table = list()
    #
    # covariate table:
    covariate_table = [{'name': 'income', 'reference': income_reference}]
    #
    # mulcov table:
    if income_mulcov_type == 'rate_value':
        effected = 'rho'
    else:
        assert income_mulcov_type == 'meas_value'
        effected = 'remission'
    mulcov_table = [{
        'covariate': 'income',
        'type': income_mulcov_type,
        'effected': effected,
        'group': 'world',
        'smooth': 'smooth_mulcov'
    }]
    #
    # avgint table: empty
    avgint_table = list()
    #
    # nslist_table:
    nslist_table = dict()
    # ----------------------------------------------------------------------
    # data table:
    data_table = list()
    #
    # values that are the same for all data rows
    row = {
        'node': 'world',
        'subgroup': 'world',
        'integrand': 'remission',
        'density': 'log_gaussian',
        'weight': '',
        'hold_out': False,
        'time_lower': 2000.,
        'time_upper': 2000.,
        'eta': prevalence_eta
    }
    n_data = 2000
    n_income = 30
    for data_id in range(n_data):
        age = 100.0 * data_id / float(n_data - 1)
        income = (data_id % n_income) / float(n_income - 1)
        income_effect = (income - income_reference) * income_multiplier
        eta = prevalence_eta
        sigma = prevalence_sigma
        log_noise = random.gauss(0, sigma)
        y = exp(log_noise) * Prevalence(age) * exp(income_effect)
        delta = (exp(sigma) - 1) * (y + eta)
        row['age_lower'] = age
        row['age_upper'] = age
        row['income'] = income
        row['meas_value'] = y
        row['meas_std'] = delta
        data_table.append(copy.copy(row))
    #
    # ----------------------------------------------------------------------
    # prior_table
    prior_table = [
     { # prior_prevalence
      'name':     'prior_prevalence',
      'density':  'uniform',
      'lower':    0.0,
      'upper':    1.0,
      'mean':     0.01,
     },{ # prior_dage
      'name':     'prior_dage',
      'density':  'log_gaussian',
      'mean':     0.0,
      'std':      2.0,
      'eta':      prevalence_eta,
     },{ # prior_dtime
      'name':     'prior_dtime',
      'density':  'log_gaussian',
      'mean':     0.0,
      'std':      0.1,
      'eta':      prevalence_eta,
     }, { # prior_mulcov
      'name':     'prior_mulcov',
      'density':  'uniform',
      'lower':    -2.0,
      'upper':    +2.0,
      'mean':     0.0,
     }
    ]
    # ----------------------------------------------------------------------
    # smooth table
    smooth_table = list()
    #
    name = 'smooth_prevalence'
    fun = fun_prevalence
    age_id = range(len(age_list))
    time_id = range(len(time_list))
    smooth_table.append({
        'name': name,
        'age_id': age_id,
        'time_id': time_id,
        'fun': fun
    })
    name = 'smooth_mulcov'
    fun = fun_mulcov
    smooth_table.append({
        'name': name,
        'age_id': [0],
        'time_id': [0],
        'fun': fun
    })
    # ----------------------------------------------------------------------
    # rate table:
    rate_table = [{
        'name': 'rho',
        'parent_smooth': 'smooth_prevalence',
        'child_smooth': None,
    }]
    # ----------------------------------------------------------------------
    # option_table
    option_table = [{
        'name': 'rate_case',
        'value': 'no_ode'
    }, {
        'name': 'parent_node_name',
        'value': 'world'
    }, {
        'name': 'ode_step_size',
        'value': '5.0'
    }, {
        'name': 'random_seed',
        'value': random_seed
    }, {
        'name': 'quasi_fixed',
        'value': 'false'
    }, {
        'name': 'derivative_test_fixed',
        'value': 'first-order'
    }, {
        'name': 'max_num_iter_fixed',
        'value': '100'
    }, {
        'name': 'print_level_fixed',
        'value': '0'
    }, {
        'name': 'tolerance_fixed',
        'value': '1e-8'
    }, {
        'name': 'derivative_test_random',
        'value': 'second-order'
    }, {
        'name': 'max_num_iter_random',
        'value': '100'
    }, {
        'name': 'print_level_random',
        'value': '0'
    }, {
        'name': 'tolerance_random',
        'value': '1e-8'
    }]
    # ----------------------------------------------------------------------
    # subgroup_table
    subgroup_table = [{'subgroup': 'world', 'group': 'world'}]
    # ----------------------------------------------------------------------
    # create database
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)
    # ----------------------------------------------------------------------
    return
Exemplo n.º 16
0
def example_db(file_name):
    # note that the a, t values are not used for this case
    def fun_rate_child(a, t):
        return ('prior_gauss_zero', 'prior_gauss_zero', 'prior_gauss_zero')

    def fun_rate_parent(a, t):
        return ('prior_value_parent', 'prior_diff_parent', 'prior_diff_parent')

    # ----------------------------------------------------------------------
    # age table
    age_list = [0.0, 50.0, 100.0]
    #
    # time table
    time_list = [1995.0, 2005.0, 2015.0]
    #
    # integrand table
    integrand_table = [{
        'name': 'Sincidence'
    }, {
        'name': 'remission'
    }, {
        'name': 'mtexcess'
    }, {
        'name': 'mtother'
    }]
    #
    # node table: world         -> north_america
    #             north_america -> (united_states, canada)
    node_table = [{
        'name': 'world',
        'parent': ''
    }, {
        'name': 'north_america',
        'parent': 'world'
    }, {
        'name': 'united_states',
        'parent': 'north_america'
    }, {
        'name': 'canada',
        'parent': 'north_america'
    }]
    #
    # weight table:
    weight_table = list()
    #
    # covariate table: no covriates
    covariate_table = list()
    #
    # mulcov table
    mulcov_table = list()
    #
    # avgint table: empty
    avgint_table = list()
    #
    # nslist_table:
    nslist_table = dict()
    # ----------------------------------------------------------------------
    # data table: same order as list of integrands
    data_table = list()
    # values that are the same for all data rows
    row = {
        'node': 'world',
        'subgroup': 'world',
        'density': 'gaussian',
        'weight': '',
        'hold_out': False,
        'time_lower': 1995.0,
        'time_upper': 1995.0,
        'age_lower': 0.0,
        'age_upper': 0.0
    }
    # values that change between rows: (one data point for each integrand)
    for integrand_id in range(len(integrand_table)):
        rate_id = integrand_id
        meas_value = 0.05
        meas_std = 0.2 * meas_value
        integrand = integrand_table[integrand_id]['name']
        row['meas_value'] = meas_value
        row['meas_std'] = meas_std
        row['integrand'] = integrand
        # data_id = rate_id = integand_id
        data_table.append(copy.copy(row))
    #
    # ----------------------------------------------------------------------
    # prior_table
    prior_table = [
     { # prior_gauss_zero
      'name':     'prior_gauss_zero',
      'density':  'gaussian',
      'mean':     0.0,
      'std':      0.01,
     },{ # prior_value_parent
      'name':     'prior_value_parent',
      'density':  'uniform',
      'lower':    0.01,
      'upper':    1.00,
      'mean':     0.1,
     },{ # prior_diff_parent
      'name':     'prior_diff_parent',
      'density':  'gaussian',
      'lower':    0.01,
      'upper':    1.0,
      'mean':     0.01,
      'std':      0.01,
     }
    ]
    # ----------------------------------------------------------------------
    # smooth table
    middle_age_id = 1
    middle_time_id = 1
    last_age_id = 2
    last_time_id = 2
    smooth_table = [
        {  # smooth_rate_child
            'name': 'smooth_rate_child',
            'age_id': [0, last_age_id],
            'time_id': [0, last_time_id],
            'fun': fun_rate_child
        },
        {  # smooth_rate_parent
            'name': 'smooth_rate_parent',
            'age_id': [0, last_age_id],
            'time_id': [0, last_time_id],
            'fun': fun_rate_parent
        }
    ]
    # ----------------------------------------------------------------------
    # rate table
    rate_table = [{
        'name': 'iota',
        'parent_smooth': 'smooth_rate_parent',
        'child_smooth': 'smooth_rate_child',
    }, {
        'name': 'rho',
        'parent_smooth': 'smooth_rate_parent',
        'child_smooth': 'smooth_rate_child',
    }, {
        'name': 'chi',
        'parent_smooth': 'smooth_rate_parent',
        'child_smooth': 'smooth_rate_child',
    }, {
        'name': 'omega',
        'parent_smooth': 'smooth_rate_parent',
        'child_smooth': 'smooth_rate_child',
    }]
    # ----------------------------------------------------------------------
    # option_table
    option_table = [{
        'name': 'parent_node_name',
        'value': 'world'
    }, {
        'name': 'ode_step_size',
        'value': '10.0'
    }, {
        'name': 'random_seed',
        'value': '0'
    }, {
        'name': 'rate_case',
        'value': 'iota_pos_rho_pos'
    }, {
        'name': 'quasi_fixed',
        'value': 'true'
    }, {
        'name': 'derivative_test_fixed',
        'value': 'first-order'
    }, {
        'name': 'max_num_iter_fixed',
        'value': '100'
    }, {
        'name': 'print_level_fixed',
        'value': '0'
    }, {
        'name': 'tolerance_fixed',
        'value': '1e-10'
    }, {
        'name': 'derivative_test_random',
        'value': 'second-order'
    }, {
        'name': 'max_num_iter_random',
        'value': '100'
    }, {
        'name': 'print_level_random',
        'value': '0'
    }, {
        'name': 'tolerance_random',
        'value': '1e-10'
    }]
    # ----------------------------------------------------------------------
    # subgroup_table
    subgroup_table = [{'subgroup': 'world', 'group': 'world'}]
    # ----------------------------------------------------------------------
    # create database
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)
Exemplo n.º 17
0
    def initDatabase(self, max_iter=500):
        if len(self.age_list) == 0:
            max_age = -float('inf')
            min_age = float('inf')
            for i in range(self.n):
                max_age = max(max_age, self.data.loc[i, 'age_end'])
                min_age = min(min_age, self.data.loc[i, 'age_start'])
            age_list = [int(round(x)) for x in np.linspace(min_age,max_age,\
                        round((max_age-min_age)/5)+1)]
            age_list = sorted(list(set(age_list)))
            #if len(age_list) == 1:
            #    age_list.insert(0,age_list[0]-1)
            self.age_list = age_list
        if len(self.time_list) == 0:
            max_time = -float('inf')
            min_time = float('inf')
            for i in range(self.n):
                max_time = max(max_time, self.data.loc[i, 'year_end'])
                min_time = min(min_time, self.data.loc[i, 'year_start'])
            time_list = [int(round(x)) for x in np.linspace(min_time, max_time,\
                         round((max_time - min_time)/3+1))]
            time_list = sorted(list(set(time_list)))
            self.time_list = time_list
        #print(self.age_list)
        #print(self.time_list)

        avgint_table = list()
        nslist_table = dict()  # smoothing
        integrand_table = []
        for intg in self.integrand:
            integrand_table.append({'name': intg})

        node_table = [{'name': 'world', 'parent': ''}]

        weight_table = [{
            'name': 'constant',
            'age_id': range(len(self.age_list)),
            'time_id': range(len(self.time_list)),
            'fun': lambda a, t: 1.0
        }]

        rate_table = list()
        for rate in self.rates:
            rate_table.append({
                'name': rate,
                'parent_smooth': 'smooth_rate_' + rate
            })

        covariate_table = list()
        for cov in self.covariates:
            covariate_table.append({'name': cov['name'], 'reference': 0.0})
        mulcov_table = list()
        for cov in self.covariates:
            mulcov_table.append({
                'covariate': cov['name'],
                'type': cov['type'],
                'effected': cov['effected'],
                'smooth': 'smooth_mulcov_' + cov['name']
            })

        smooth_table = list()
        for rate in self.rates:
            smooth_table.append({
                'name':
                'smooth_rate_' + rate,
                'age_id':
                range(len(self.age_list)),
                'time_id':
                range(len(self.time_list)),
                'fun':
                lambda a, t, r=rate:
                ('value_prior_' + r, 'dage_prior_' + r, 'dtime_prior_' + r)
            })
        for cov in self.covariates:
            name = cov['name']
            smooth_table.append({
                'name':
                'smooth_mulcov_' + cov['name'],
                'age_id':
                range(len(self.age_list)),
                'time_id':
                range(len(self.time_list)),
                'fun':
                lambda a, t, name=name: ('value_prior_' + name, 'dage_prior_' +
                                         name, 'dtime_prior_' + name)
            })
        #for row in smooth_table:
        #    print(row['fun'](0,0))

        prior_table = []
        for i in range(len(self.rates)):
            prior_table.append({'name': 'value_prior_' + self.rates[i]})
            prior_table[-1].update(self.rate_priors[i][0])
            prior_table.append({'name': 'dage_prior_' + self.rates[i]})
            prior_table[-1].update(self.rate_priors[i][1])
            prior_table.append({'name': 'dtime_prior_' + self.rates[i]})
            prior_table[-1].update(self.rate_priors[i][2])
        for i in range(len(self.covariates)):
            prior_table.append(
                {'name': 'value_prior_' + self.covariates[i]['name']})
            prior_table[-1].update(self.cov_priors[i][0])
            prior_table.append(
                {'name': 'dage_prior_' + self.covariates[i]['name']})
            prior_table[-1].update(self.cov_priors[i][1])
            prior_table.append(
                {'name': 'dtime_prior_' + self.covariates[i]['name']})
            prior_table[-1].update(self.cov_priors[i][2])

        data_table = list()
        row = {
            'node': 'world',
            'weight': 'constant',
            'hold_out': False,
        }
        row.update(self.meas_noise_density)
        for data_id in range(self.n):
            if self.data.loc[data_id, 'measure'] in self.integrand:
                row['integrand'] = self.data.loc[data_id, 'measure']
                for k, v in self.meas_noise_density[row['integrand']].items():
                    row[k] = v
                row['meas_value'] = self.data.loc[data_id, 'meas_value']
                row['meas_std'] = self.data.loc[data_id, 'meas_std']
                row['age_lower'] = self.data.loc[data_id, 'age_start']
                row['age_upper'] = self.data.loc[data_id, 'age_end']
                row['time_lower'] = self.data.loc[data_id, 'year_start']
                row['time_upper'] = self.data.loc[data_id, 'year_end']
                for cov in self.covariates:
                    row[cov['name']] = self.data.loc[data_id, cov['name']]
                data_table.append(copy.copy(row))

        option_table = [
            {
                'name': 'parent_node_name',
                'value': 'world'
            },
            {
                'name': 'ode_step_size',
                'value': '10.0'
            },
            {
                'name': 'quasi_fixed',
                'value': 'false'
            },
            {
                'name': 'max_num_iter_fixed',
                'value': max_iter
            },
            {
                'name': 'print_level_fixed',
                'value': '5'
            },
            {
                'name': 'tolerance_fixed',
                'value': '1e-8'
            },
        ]
        if self.integrand == ['Sincidence']:
            option_table.append({
                'name': 'rate_case',
                'value': 'iota_pos_rho_zero'
            })
        elif self.integrand == 'remission':
            option_table.append({
                'name': 'rate_case',
                'value': 'iota_zero_rho_pos'
            })
        else:
            option_table.append({
                'name': 'rate_case',
                'value': 'iota_pos_rho_pos'
            })

        option_name_id = {}
        for i in range(len(option_table)):
            option_name_id[option_table[i]['name']] = i
        for option in self.options:
            if option['name'] in option_name_id:
                option_table[option_name_id[
                    option['name']]]['value'] = option['value']
            else:
                option_table.append(option)

        dismod_at.create_database(self.path, self.age_list, self.time_list,
                                  integrand_table, node_table, weight_table,
                                  covariate_table, avgint_table, data_table,
                                  prior_table, smooth_table, nslist_table,
                                  rate_table, mulcov_table, option_table)

        command = [program, self.path, 'init']
        print(' '.join(command))
        flag = subprocess.call(command)
        if flag != 0:
            sys.exit('The dismod_at init command failed')
        dismod_at.db2csv_command(self.path)
Exemplo n.º 18
0
def example_db(file_name):
    # note that the a, t values are not used for this case
    def fun_iota(a, t):
        return ('prior_iota', None, None)

    def fun_gamma(a, t):
        return ('prior_gamma', None, None)

    # ----------------------------------------------------------------------
    # age table:
    age_list = [0.0, 100.0]
    #
    # time table:
    time_list = [1990.0, 2010.0]
    #
    # integrand table:
    integrand_table = [{'name': 'Sincidence'}]
    #
    # node table:
    node_table = [{'name': 'world', 'parent': ''}]
    #
    # weight table:
    weight_table = list()
    #
    # covariate table:
    covariate_table = [{'name': 'one', 'reference': 0.0}]
    #
    # mulcov table:
    mulcov_table = [{
        'covariate': 'one',
        'type': 'meas_noise',
        'effected': 'Sincidence',
        'group': 'world',
        'smooth': 'smooth_gamma'
    }]
    #
    # avgint table: empty
    avgint_table = list()
    #
    # nslist_table:
    nslist_table = dict()
    # ----------------------------------------------------------------------
    # data table:
    data_table = list()
    # values that are the same for all data rows
    row = {
        'weight': '',
        'hold_out': False,
        'node': 'world',
        'subgroup': 'world',
        'one': 1.0,
        'age_lower': 50.0,
        'age_upper': 50.0,
        'time_lower': 2000.,
        'time_upper': 2000.,
        'integrand': 'Sincidence',
        'density': data_density,
        'meas_std': meas_std,
        'eta': iota_true / 100.0,
        'nu': 10
    }
    # values that change between rows:
    for data_id in range(n_data):
        if data_id % 2 == 0:
            row['meas_value'] = 0.9 * iota_true
        else:
            row['meas_value'] = 1.1 * iota_true
        data_table.append(copy.copy(row))
    #
    # ----------------------------------------------------------------------
    # prior_table
    prior_table = [
        {  # prior_iota
            'name': 'prior_iota',
            'density': 'uniform',
            'lower': iota_true / 100.0,
            'upper': 1.0,
            'mean': iota_true / 10.0
        },
        {  # prior_gamma
            'name': 'prior_gamma',
            'density': 'uniform',
            'lower': 0.0,
            'upper': 10.0 * gamma_true(),
            'mean': gamma_true() / 10.0
        }
    ]
    # ----------------------------------------------------------------------
    # smooth table
    name = 'smooth_iota'
    fun = fun_iota
    age_id = 0
    time_id = 0
    smooth_table = [{
        'name': name,
        'age_id': [age_id],
        'time_id': [time_id],
        'fun': fun
    }]
    name = 'smooth_iota'
    #
    name = 'smooth_gamma'
    fun = fun_gamma
    smooth_table.append({
        'name': name,
        'age_id': [age_id],
        'time_id': [time_id],
        'fun': fun
    })
    # ----------------------------------------------------------------------
    # rate table:
    rate_table = [{
        'name': 'iota',
        'parent_smooth': 'smooth_iota',
        'child_smooth': None
    }]
    # ----------------------------------------------------------------------
    # option_table
    option_table = [
        {
            'name': 'meas_noise_effect',
            'value': meas_noise_effect
        },
        {
            'name': 'rate_case',
            'value': 'iota_pos_rho_zero'
        },
        {
            'name': 'parent_node_name',
            'value': 'world'
        },
        {
            'name': 'random_seed',
            'value': '0'
        },
    ]
    # ----------------------------------------------------------------------
    # subgroup_table
    subgroup_table = [{'subgroup': 'world', 'group': 'world'}]
    # ----------------------------------------------------------------------
    # create database
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)
    # ----------------------------------------------------------------------
    return
Exemplo n.º 19
0
def example_db (file_name) :
	# note that the a, t values are not used for this case
	def fun_rate_child(a, t) :
		return ('prior_iota_child', None, None)
	def fun_iota_parent(a, t) :
		return ('prior_iota_parent', None, None)
	def fun_mulcov(a, t) :
		return ('prior_mulcov', None, None)
	# ----------------------------------------------------------------------
	# age table:
	age_list    = [ 0.0, 5.0, 15.0, 35.0, 50.0, 75.0, 90.0, 100.0 ]
	#
	# time table:
	time_list   = [ 1990.0, 2000.0, 2010.0, 2200.0 ]
	#
	# integrand table:
	integrand_table = [
		 { 'name':'prevalence' }
	]
	#
	# node table:
	node_table = [ { 'name':'world', 'parent':'' } ]
	for i in range(n_children) :
		name = 'child_' + str(i + 1)
		node_table.append( { 'name':name, 'parent':'world' } )
	#
	# weight table:
	weight_table = list()
	#
	# covariate table:
	covariate_table = [
		{'name':'income', 'reference':0.5}
	]
	#
	# mulcov table:
	mulcov_table = [
		{
			'covariate': 'income',
			'type':      'rate_value',
			'effected':  'iota',
			'group':     'world',
			'smooth':    'smooth_mulcov'
		}
	]
	#
	# avgint table: empty
	avgint_table = list()
	#
	# nslist_table:
	nslist_table = dict()
	# ----------------------------------------------------------------------
	# data table:
	data_table = list()
	# values that are the same for all data rows
	row = {
		'meas_value':  0.0,             # not used (will be simulated)
		'density':     'gaussian',
		'weight':      '',
		'hold_out':     False,
		'time_lower':   2000.,
		'time_upper':   2000.
	}
	# values that change between rows:
	for data_id in range( n_data ) :
		fraction         = data_id / float(n_data-1)
		age              = age_list[0] + (age_list[-1] - age_list[0])*fraction
		row['age_lower'] = age
		row['age_upper'] = age
		row['node']      = 'child_' + str( (data_id % n_children) + 1 )
		row['income']    = fraction
		row['integrand'] = integrand_table[0]['name']
		row['meas_std']  = 1e-3
		data_table.append( copy.copy(row) )
	#
	# ----------------------------------------------------------------------
	# prior_table
	prior_table = [
		{	# prior_iota_child
			'name':     'prior_iota_child',
			'density':  'gaussian',
			'mean':     0.0,
			'std':      0.5,
		},{ # prior_iota_parent
			'name':     'prior_iota_parent',
			'density':  'uniform',
			'lower':    iota_parent_true / 100.,
			'upper':    1.0,
			'mean':     0.1,
		},{ # prior_mulcov
			'name':     'prior_mulcov',
			'density':  'uniform',
			'lower':    -2.0,
			'upper':    +2.0,
			'mean':     0.0,
		}
	]
	# ----------------------------------------------------------------------
	# smooth table
	name           = 'smooth_rate_child'
	fun            = fun_rate_child
	age_id         = int( len( age_list ) / 2 )
	time_id        = int( len( time_list ) / 2 )
	smooth_table = [
		{'name':name, 'age_id':[age_id], 'time_id':[time_id], 'fun':fun }
	]
	name = 'smooth_iota_parent'
	fun  = fun_iota_parent
	smooth_table.append(
		{'name':name, 'age_id':[age_id], 'time_id':[time_id], 'fun':fun }
	)
	name = 'smooth_mulcov'
	fun  = fun_mulcov
	smooth_table.append(
		{'name':name, 'age_id':[age_id], 'time_id':[time_id], 'fun':fun }
	)
	# no standard deviation multipliers
	for dictionary in smooth_table :
		for name in [ 'value' , 'dage', 'dtime' ] :
			key   = 'mulstd_' + name + '_prior_name'
			value = None
			dictionary[key] = value
	# ----------------------------------------------------------------------
	# rate table:
	rate_table = [
		{	'name':          'iota',
			'parent_smooth': 'smooth_iota_parent',
			'child_smooth':  'smooth_rate_child',
		}
	]
	# ----------------------------------------------------------------------
	# option_table
	option_table = [
		{ 'name':'rate_case',              'value':'iota_pos_rho_zero' },
		{ 'name':'parent_node_name',       'value':'world'        },
		{ 'name':'ode_step_size',          'value':'10.0'         },
		{ 'name':'random_seed',            'value':'0'            },
		{ 'name':'zero_sum_child_rate',    'value':'iota'         },

		{ 'name':'quasi_fixed',            'value':'true'         },
		{ 'name':'derivative_test_fixed',  'value':'first-order'  },
		{ 'name':'max_num_iter_fixed',     'value':'100'          },
		{ 'name':'print_level_fixed',      'value':'0'            },
		{ 'name':'tolerance_fixed',        'value':'1e-8'         },

		{ 'name':'derivative_test_random', 'value':'second-order' },
		{ 'name':'max_num_iter_random',    'value':'100'          },
		{ 'name':'print_level_random',     'value':'0'            },
		{ 'name':'tolerance_random',       'value':'1e-8'         }
	]
	# ----------------------------------------------------------------------
	# subgroup_table
	subgroup_table = [ { 'subgroup':'world', 'group':'world' } ]
	# ----------------------------------------------------------------------
	# create database
	dismod_at.create_database(
		file_name,
		age_list,
		time_list,
		integrand_table,
		node_table,
		subgroup_table,
		weight_table,
		covariate_table,
		avgint_table,
		data_table,
		prior_table,
		smooth_table,
		nslist_table,
		rate_table,
		mulcov_table,
		option_table
	)
	# ----------------------------------------------------------------------
	return
Exemplo n.º 20
0
def example_db(file_name):
    def fun_income(a, t):
        return ('prior_income_value', 'prior_income_dage',
                'prior_income_dtime')

    def fun_iota_parent(a, t):
        return ('prior_iota_parent', None, None)

    # ----------------------------------------------------------------------
    # age table
    #
    # time table
    node_table = [
        {
            'name': 'north_america',
            'parent': ''
        },
    ]
    #
    # weight table:
    weight_table = list()
    # integrand table
    integrand_table = [{'name': 'Sincidence'}, {'name': 'mulcov_0'}]
    #
    # covariate table:
    covariate_table = [{'name': 'income', 'reference': income_reference}]
    #
    # mulcov table: one multiplier with mulcov_id = 0
    mulcov_table = [{
        'covariate': 'income',
        'type': 'rate_value',
        'effected': 'iota',
        'group': 'world',
        'smooth': 'smooth_income'
    }]
    #
    # nslist_table:
    nslist_table = dict()
    # ----------------------------------------------------------------------
    # prior_table
    prior_table = [
     { # prior_iota_parent
      'name':     'prior_iota_parent',
      'density':  'uniform',
      'lower':    iota_reference,
      'upper':    iota_reference,
      'mean':     iota_reference,
     },{ # prior_income_value
      'name':     'prior_income_value',
      'density':  'uniform',
      'mean':     0.0,
      'lower':   -1.0,
      'upper':   +1.0,
     },{ # prior_income_dage
      'name':     'prior_income_dage',
      'density':  'uniform',
      'mean':     0.0,
     },{ # prior_income_dtime
      'name':     'prior_income_dtime',
      'density':  'uniform',
      'mean':     0.0,
     }
    ]
    # ----------------------------------------------------------------------
    # smooth table
    smooth_table = [
        {  # smooth_iota_parent
            'name': 'smooth_iota_parent',
            'age_id': [0],
            'time_id': [0],
            'fun': fun_iota_parent
        },
        {  # smooth_income
            'name': 'smooth_income',
            'age_id': [0, 1],
            'time_id': [0, 1],
            'fun': fun_income
        }
    ]
    # ----------------------------------------------------------------------
    # rate table
    rate_table = [{
        'name': 'iota',
        'parent_smooth': 'smooth_iota_parent',
    }]
    # --------------------------------------------------------------------
    # option_table
    option_table = [
        {
            'name': 'parent_node_name',
            'value': 'north_america'
        },
        {
            'name': 'rate_case',
            'value': 'iota_pos_rho_zero'
        },
        {
            'name': 'quasi_fixed',
            'value': 'true'
        },
        {
            'name': 'max_num_iter_fixed',
            'value': '30'
        },
        {
            'name': 'print_level_fixed',
            'value': '0'
        },
        {
            'name': 'tolerance_fixed',
            'value': '1e-10'
        },
    ]
    # ----------------------------------------------------------------------
    # data table:
    data_table = list()
    row = {
        'node': 'north_america',
        'subgroup': 'world',
        'density': 'gaussian',
        'weight': '',
        'hold_out': False,
        'integrand': 'Sincidence',
        'income': 2.0,
    }
    for age in age_list:
        for time in time_list:
            alpha = alpha_true(age, time)
            effect = alpha * (row['income'] - income_reference)
            iota = iota_reference * math.exp(effect)
            row['age_lower'] = age
            row['age_upper'] = age
            row['time_lower'] = time
            row['time_upper'] = time
            row['meas_value'] = iota
            row['meas_std'] = iota / 10.0
            data_table.append(copy.copy(row))
    # ----------------------------------------------------------------------
    # avgint table:
    avgint_table = list()
    # values that are the same for all rows
    does_not_matter = 5.0
    row = {
        'node': 'north_america',
        'subgroup': 'world',
        'integrand': 'mulcov_0',
        'weight': '',
        'income': does_not_matter,
    }
    for age in age_list:
        for time in time_list:
            row['age_lower'] = age
            row['age_upper'] = age
            row['time_lower'] = time
            row['time_upper'] = time
            avgint_table.append(copy.copy(row))
    # ----------------------------------------------------------------------
    # subgroup_table
    subgroup_table = [{'subgroup': 'world', 'group': 'world'}]
    # ----------------------------------------------------------------------
    # create database
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)
Exemplo n.º 21
0
def example_db (file_name) :
	# note that the a, t values are not used for this case
	def fun_iota(a, t) :
		if (a, t) == (0, 2000) :
			return ('prior_value_0_2000', 'prior_diff', 'prior_diff')
		elif (a, t) == (100, 2000) :
			return ('prior_value_100_2000', 'prior_diff', 'prior_diff')
		elif (a, t) == (0, 2020) :
			return ('prior_value_0_2020', 'prior_diff', 'prior_diff')
		elif (a, t) == (100, 2020) :
			return ('prior_value_100_2020', 'prior_diff', 'prior_diff')
		else :
			assert False
	# ----------------------------------------------------------------------
	# age table:
	age_list    = [ 0.0, 100.0 ]
	#
	# time table:
	time_list   = [ 2000.0, 2020.0 ]
	#
	# integrand table:
	integrand_table = [
		 { 'name': 'Sincidence' },
		 { 'name': 'prevalence' },
	]
	#
	# node table:
	node_table = [ { 'name':'world', 'parent':'' } ]
	#
	# weight table:
	weight_table = list()
	#
	# covariate table:
	covariate_table = list()
	#
	# mulcov table:
	mulcov_table = list()
	#
	# nslist_table:
	nslist_table = dict()
	# ----------------------------------------------------------------------
	# data table:
	data_table = list()
	# values that are the same for all data rows
	age_lower  = 10.0
	age_upper  = 90.0
	time_lower = 2000.0
	time_upper = 2020.0
	row = {
		'weight':      '',
		'hold_out':     False,
		'node':        'world',
		'subgroup':    'world',
		'density':     'gaussian',
		'meas_std':     0.01,
		'age_lower':    age_lower,
		'age_upper' :   age_upper,
		'time_lower' :  time_lower,
		'time_upper' :  time_upper,
	}
	#
	max_step  = 1.0
	age_grid  = uniform_grid(age_lower, age_upper, max_step)
	time_grid = uniform_grid(time_lower, time_upper, max_step)
	grid      = { 'age' : age_grid, 'time' : time_grid }
	#
	# Sincidence
	meas_value = average_integrand('Sincidence', grid)
	row['integrand']  = 'Sincidence'
	row['meas_value'] = meas_value
	data_table.append( copy.copy(row) )
	#
	# prevalence
	meas_value = average_integrand('prevalence', grid)
	row['integrand']  = 'prevalence'
	row['meas_value'] = meas_value
	data_table.append( copy.copy(row) )
	#
	# avgint table:
	avgint_table = data_table
	#
	# ----------------------------------------------------------------------
	# prior_table
	prior_table = [
		{ # prior_value_0_2000
			'name':     'prior_value_0_2000',
			'density':  'uniform',
			'lower':    iota_true(0, 2000) / 100.0,
			'upper':    iota_true(0, 2000)  * 100.0,
			'mean':     iota_true(0, 2000)
		},{ # prior_value_100_2000
			'name':     'prior_value_100_2000',
			'density':  'uniform',
			'lower':    iota_true(100, 2000) / 100.0,
			'upper':    iota_true(100, 2000)  * 100.0,
			'mean':     iota_true(100, 2000)
		},{ # prior_value_0_2020
			'name':     'prior_value_0_2020',
			'density':  'uniform',
			'lower':    iota_true(0, 2020) / 100.0,
			'upper':    iota_true(0, 2020)  * 100.0,
			'mean':     iota_true(0, 2020)
		},{ # prior_value_100_2020
			'name':     'prior_value_100_2020',
			'density':  'uniform',
			'lower':    iota_true(100, 2020) / 100.0,
			'upper':    iota_true(100, 2020)  * 100.0,
			'mean':     iota_true(100, 2020)
		},{ # prior_diff
			'name':     'prior_diff',
			'density':  'uniform',
			'mean':     0.0
		}
	]
	# ----------------------------------------------------------------------
	# smooth table
	name           = 'smooth_iota'
	fun            = fun_iota
	age_id         = [0, 1]
	time_id        = [0, 1]
	smooth_table = [
		{'name':name, 'age_id':age_id, 'time_id':time_id, 'fun':fun }
	]
	name = 'smooth_iota'
	# ----------------------------------------------------------------------
	# rate table:
	rate_table = [
		{	'name':          'iota',
			'parent_smooth': 'smooth_iota',
			'child_smooth':  None
		}
	]
	# ----------------------------------------------------------------------
	# option_table
	option_table = [
		{ 'name':'rate_case',              'value':'iota_pos_rho_zero'  },
		{ 'name':'parent_node_name',       'value':'world'              },
		{ 'name':'ode_step_size',          'value':'1.0'                },

	]
	# ----------------------------------------------------------------------
	# subgroup_table
	subgroup_table = [ { 'subgroup':'world', 'group':'world' } ]
	# ----------------------------------------------------------------------
	# create database
	dismod_at.create_database(
		file_name,
		age_list,
		time_list,
		integrand_table,
		node_table,
		subgroup_table,
		weight_table,
		covariate_table,
		avgint_table,
		data_table,
		prior_table,
		smooth_table,
		nslist_table,
		rate_table,
		mulcov_table,
		option_table
	)
	# ----------------------------------------------------------------------
	return
Exemplo n.º 22
0
def example_db(file_name):
    def fun_rate_world(a, t):
        return ('prior_rate_world', None, 'prior_world_diff')

    import dismod_at
    # ----------------------------------------------------------------------
    # age table
    age_list = [0.0, 100.0]
    #
    # time table
    time_list = [1995.0, 2015.0]
    #
    # integrand table
    integrand_table = list()
    #
    # node table:
    node_table = [{'name': 'world', 'parent': ''}]
    #
    # weight table
    weight_table = list()
    #
    # covariate table: no covriates
    covariate_table = list()
    #
    # mulcov table
    mulcov_table = list()
    #
    # avgint table: same order as list of integrands
    avgint_table = list()
    #
    # nslist_table:
    nslist_table = dict()
    #
    # data table:
    data_table = list()
    # ----------------------------------------------------------------------
    # prior_table
    prior_table = [
        {  # prior_rate_world
            'name': 'prior_rate_world',
            'density': 'gaussian',
            'mean': omega_world_mean,
            'std': omega_world_mean
        },
        {  # prior_world_diff
            'name': 'prior_world_diff',
            'density': 'gaussian',
            'mean': 0.0,
            'std': omega_world_mean
        }
    ]
    # ----------------------------------------------------------------------
    # smooth table
    last_time_id = len(time_list) - 1
    smooth_table = [{  # smooth_rate_world
        'name': 'smooth_rate_world',
        'age_id': [0],
        'time_id': [0, last_time_id],
        'fun': fun_rate_world
    }]
    # ----------------------------------------------------------------------
    # rate table
    rate_table = [{
        'name': 'omega',
        'parent_smooth': 'smooth_rate_world',
        'child_smooth': None,
    }]
    # ----------------------------------------------------------------------
    # option_table
    option_table = [{
        'name': 'parent_node_name',
        'value': 'world'
    }, {
        'name': 'rate_case',
        'value': 'iota_zero_rho_zero'
    }, {
        'name': 'quasi_fixed',
        'value': 'true'
    }, {
        'name': 'derivative_test_fixed',
        'value': 'first-order'
    }, {
        'name': 'max_num_iter_fixed',
        'value': '100'
    }, {
        'name': 'print_level_fixed',
        'value': '0'
    }, {
        'name': 'tolerance_fixed',
        'value': '1e-11'
    }, {
        'name': 'derivative_test_random',
        'value': 'second-order'
    }, {
        'name': 'max_num_iter_random',
        'value': '100'
    }, {
        'name': 'print_level_random',
        'value': '0'
    }, {
        'name': 'tolerance_random',
        'value': '1e-11'
    }]
    # ----------------------------------------------------------------------
    # subgroup_table
    subgroup_table = [{'subgroup': 'world', 'group': 'world'}]
    # ----------------------------------------------------------------------
    # create database
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)
    # ----------------------------------------------------------------------
    return
Exemplo n.º 23
0
def example_db (file_name) :
	def fun_rate_parent(a, t) :
		return ('prior_rate_parent', 'prior_none', 'prior_none')
	# ----------------------------------------------------------------------
	# age table
	age_list    = list( range(0, 101, 10) )
	age_index   = list( range(1, len(age_list) - 1, 1) )
	#
	# time table
	time_list   = list( range(1980, 2021, 10) )
	time_index  = list( range(1, len(time_list) - 1, 1) )
	#
	# integrand table
	integrand_table = [
		{ 'name':'Sincidence' },
		{ 'name':'remission' },
		{ 'name':'mtexcess' },
	]
	#
	# node table: world -> north_america
	#             north_america -> (united_states, canada)
	node_table = [
		{ 'name':'world',         'parent':'' },
		{ 'name':'north_america', 'parent':'world' },
		{ 'name':'united_states', 'parent':'north_america' },
		{ 'name':'canada',        'parent':'north_america' }
	]
	#
	# weight table:
	weight_table = list()
	#
	# covariate table: no covriates
	covariate_table = list()
	#
	# mulcov table
	mulcov_table = list()
	#
	# nslist_table:
	nslist_table = dict()
	#
	# avgint table:
	avgint_table = list()
	# ----------------------------------------------------------------------
	# data table: same order as list of integrands
	data_table = list()
	# values that are the same for all data rows
	row = {
		'node':        'canada',
		'subgroup':    'world',
		'density':     'gaussian',
		'weight':      '',
		'hold_out':     False,
	}
	# values that change between rows: (one data point for each integrand)
	for integrand_id in range( len(integrand_table) ) :
		integrand_name    = integrand_table[integrand_id]['name']
		rate_name         = integrand2rate[integrand_name]
		#
		for age_id in age_index :
			for time_id in time_index :
				age        = age_list[age_id]
				time       = time_list[time_id]
				true_value = rate_true(rate_name, age, time)
				meas_std          = meas_cv * true_value
				row['age_lower']  = age
				row['age_upper']  = age
				row['time_lower'] = time
				row['time_upper'] = time
				row['integrand']  = integrand_name
				row['meas_value'] = true_value
				row['meas_std']   = true_value * 0.2
				data_table.append( copy.copy(row) )
	#
	# ----------------------------------------------------------------------
	# prior_table
	prior_table = [
		{	# prior_rate_parent
			'name':     'prior_rate_parent',
			'density':  'uniform',
			'lower':    1e-4,
			'upper':    1.0,
			'mean':     0.1,
		},{ # prior_none
			'name':     'prior_none',
			'density':  'uniform',
			'mean':     0.0,
		}
	]
	# ----------------------------------------------------------------------
	# smooth table
	last_time_id   = len(time_list) - 1
	smooth_table = [
		{ # smooth_rate_parent
			'name':                     'smooth_rate_parent',
			'age_id':                   age_index,
			'time_id':                  time_index,
			'fun':                      fun_rate_parent
		}
	]
	# ----------------------------------------------------------------------
	# rate table
	rate_table = [
		{
			'name':          'iota',
			'parent_smooth': 'smooth_rate_parent',
		},{
			'name':          'rho',
			'parent_smooth': 'smooth_rate_parent',
		},{
			'name':          'chi',
			'parent_smooth': 'smooth_rate_parent',
		}
	]
	# ----------------------------------------------------------------------
	# option_table
	option_table = [
		{ 'name':'parent_node_name',       'value':'canada'       },
		{ 'name':'random_seed',            'value':random_seed    },
		{ 'name':'rate_case',              'value':'iota_pos_rho_pos' },

		{ 'name':'quasi_fixed',            'value':'false'        },
		{ 'name':'derivative_test_fixed',  'value':'first-order'  },
		{ 'name':'max_num_iter_fixed',     'value':'30'           },
		{ 'name':'print_level_fixed',      'value':'5'            },
		{ 'name':'tolerance_fixed',        'value':'1e-12'        },

		{ 'name':'derivative_test_random', 'value':'second-order' },
		{ 'name':'max_num_iter_random',    'value':'100'          },
		{ 'name':'print_level_random',     'value':'0'            },
		{ 'name':'tolerance_random',       'value':'1e-12'        }
	]
	# ----------------------------------------------------------------------
	# subgroup_table
	subgroup_table = [ { 'subgroup':'world', 'group':'world' } ]
	# ----------------------------------------------------------------------
	# create database
	dismod_at.create_database(
		file_name,
		age_list,
		time_list,
		integrand_table,
		node_table,
		subgroup_table,
		weight_table,
		covariate_table,
		avgint_table,
		data_table,
		prior_table,
		smooth_table,
		nslist_table,
		rate_table,
		mulcov_table,
		option_table
	)
	# ----------------------------------------------------------------------
	n_smooth  = len( smooth_table )
Exemplo n.º 24
0
def example_db(file_name):
    def fun_iota_parent(a, t):
        return ('prior_iota_parent', 'prior_gauss_zero', 'prior_gauss_zero')

    # ----------------------------------------------------------------------
    # age_list
    age_list = [0.0, 100.0]
    #
    # time_list
    time_list = [1990.0, 2200.0]
    #
    # integrand table:
    integrand_table = [
        {
            'name': 'Sincidence'
        },
    ]
    #
    # node table:
    node_table = [{'name': 'world', 'parent': ''}]
    #
    # weight table:
    weight_table = list()
    #
    # covariate table:
    covariate_table = list()
    #
    # mulcov table:
    mulcov_table = list()
    # -----------------------------------------------------------------------
    # data table:
    data_table = list()
    #
    # values that are the same for all data rows
    row = {
        'integrand': 'Sincidence',
        'density': 'gaussian',
        'weight': '',
        'hold_out': False,
        'age_lower': 50.0,
        'age_upper': 50.0,
        'time_lower': 2000.0,
        'time_upper': 2000.0,
        'node': 'world',
        'subgroup': 'world',
    }
    # N = 2, y_0 = iota_true - noise , y1 = iota_true + noise
    noise = 0.9 * iota_true
    Sincidence = [
        iota_true - noise,
        iota_true + noise,
    ]
    for meas_value in Sincidence:
        row['meas_value'] = meas_value
        row['meas_std'] = meas_value  # 100 % coefficient of variation
        data_table.append(copy.copy(row))
    #
    # ----------------------------------------------------------------------
    # prior_table
    prior_table = [
     { # prior_gauss_zero
      'name':     'prior_gauss_zero',
      'density':  'gaussian',
      'mean':     0.0,
      'std':      0.01,
     },{ # prior_iota_parent
      'name':     'prior_iota_parent',
      'density':  'uniform',
      'lower':    1e-19,
      'upper':    1.0,
      'mean':     1.01e-06,
     }
    ]
    #
    # smooth table
    name = 'smooth_iota_parent'
    fun = fun_iota_parent
    age_grid = [0]
    time_grid = [0]
    smooth_table = [{
        'name': name,
        'age_id': age_grid,
        'time_id': time_grid,
        'fun': fun
    }]
    #
    # rate table:
    rate_table = [{
        'name': 'iota',
        'parent_smooth': 'smooth_iota_parent',
        'child_smooth': None,
    }]
    #
    # option_table
    option_table = [
        {
            'name': 'rate_case',
            'value': 'iota_pos_rho_zero'
        },
        {
            'name': 'parent_node_name',
            'value': 'world'
        },
        {
            'name': 'quasi_fixed',
            'value': 'false'
        },
        {
            'name': 'print_level_fixed',
            'value': '0'
        },
        {
            'name': 'tolerance_fixed',
            'value': '1e-9'
        },
        {
            'name': 'tolerance_random',
            'value': '1e-10'
        },
    ]
    #
    # avgint table: empty
    avgint_table = list()
    #
    # nslist_table:
    nslist_table = dict()
    #
    # subgroup_table
    subgroup_table = [{'subgroup': 'world', 'group': 'world'}]
    #
    # create database
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)
    # ----------------------------------------------------------------------
    return
Exemplo n.º 25
0
def example_db(file_name):
    def fun_rate_parent(a, t):
        return ('prior_rate_parent', 'prior_gauss_zero', None)

    # ----------------------------------------------------------------------
    # age table
    age_list = [0.0, 50.0, 100.0]
    #
    # time table
    time_list = [1995.0, 2005.0, 2015.0]
    #
    # integrand table
    integrand_table = [{'name': 'Sincidence'}]
    #
    # node table: world -> north_america
    #             north_america -> (united_states, canada)
    node_table = [{
        'name': 'world',
        'parent': ''
    }, {
        'name': 'north_america',
        'parent': 'world'
    }, {
        'name': 'united_states',
        'parent': 'north_america'
    }, {
        'name': 'canada',
        'parent': 'north_america'
    }]
    #
    # weight table:
    weight_table = list()
    #
    # covariate table: no covriates
    covariate_table = list()
    #
    # mulcov table
    mulcov_table = list()
    #
    # nslist_table:
    nslist_table = dict()
    #
    # avgint_table
    avgint_table = list()
    # ----------------------------------------------------------------------
    # data table: same order as age_list
    data_table = list()
    # values that are the same for all data rows
    row = {
        'node': 'canada',
        'subgroup': 'world',
        'density': 'gaussian',
        'weight': '',
        'hold_out': False,
        'time_lower': 2000.0,
        'time_upper': 2000.0,
        'integrand': 'Sincidence',
        'age_lower': 0.0
    }
    # values that change between rows: (one data point for each integrand)
    for age_id in range(len(age_list)):
        age = age_list[age_id]
        meas_value = 1e-4 * (50.0 + age)
        row['meas_value'] = meas_value
        row['meas_std'] = 1e-4 * (50.0 + age_list[0])
        row['age_lower'] = age
        row['age_upper'] = age
        data_table.append(copy.copy(row))
    #
    # ----------------------------------------------------------------------
    # prior_table
    prior_table = [
     { # prior_rate_parent
      'name':     'prior_rate_parent',
      'density':  'uniform',
      'lower':    1e-4,
      'upper':    1.0,
      'mean':     0.01,
     },{ # prior_gauss_zero
      'name':     'prior_gauss_zero',
      'density':  'gaussian',
      'mean':     0.0,
      'std':      1e-6,
     }
    ]
    # ----------------------------------------------------------------------
    # smooth table
    smooth_table = [{  # smooth_rate_parent
        'name': 'smooth_rate_parent',
        'age_id': range(len(age_list)),
        'time_id': [0],
        'fun': fun_rate_parent
    }]
    # ----------------------------------------------------------------------
    # rate table
    rate_table = [{
        'name': 'iota',
        'parent_smooth': 'smooth_rate_parent',
    }]
    # ----------------------------------------------------------------------
    # option_table: max_num_iter_fixed will be set later
    option_table = [{
        'name': 'parent_node_name',
        'value': 'canada'
    }, {
        'name': 'ode_step_size',
        'value': '10.0'
    }, {
        'name': 'random_seed',
        'value': '0'
    }, {
        'name': 'rate_case',
        'value': 'iota_pos_rho_zero'
    }, {
        'name': 'warn_on_stderr',
        'value': 'false'
    }, {
        'name': 'quasi_fixed',
        'value': 'true'
    }, {
        'name': 'derivative_test_fixed',
        'value': 'first-order'
    }, {
        'name': 'print_level_fixed',
        'value': '0'
    }, {
        'name': 'tolerance_fixed',
        'value': '1e-12'
    }, {
        'name': 'derivative_test_random',
        'value': 'second-order'
    }, {
        'name': 'max_num_iter_random',
        'value': '100'
    }, {
        'name': 'print_level_random',
        'value': '0'
    }, {
        'name': 'tolerance_random',
        'value': '1e-10'
    }]
    # ----------------------------------------------------------------------
    # subgroup_table
    subgroup_table = [{'subgroup': 'world', 'group': 'world'}]
    # ----------------------------------------------------------------------
    # create database
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)
    return
Exemplo n.º 26
0
def example_db(file_name):
    import copy
    import dismod_at
    import math
    # ----------------------------------------------------------------------
    # age table
    age_list = [0.0, 100.0]
    #
    # time table
    time_list = [1995.0, 2015.0]
    #
    # integrand table
    integrand_table = [{'name': 'Sincidence', 'minimum_meas_cv': 0.0}]
    #
    # node table: world -> north_america
    #             north_america -> (united_states, canada)
    node_table = [{
        'name': 'world',
        'parent': ''
    }, {
        'name': 'north_america',
        'parent': 'world'
    }, {
        'name': 'united_states',
        'parent': 'north_america'
    }, {
        'name': 'canada',
        'parent': 'north_america'
    }]
    #
    # weight table: The constant function 1.0 (one age and one time point)
    fun = constant_weight_fun
    weight_table = [{
        'name': 'constant',
        'age_id': [0],
        'time_id': [0],
        'fun': fun
    }]
    #
    # covariate table:
    covariate_table = list()
    #
    # mulcov table
    mulcov_table = list()
    # ----------------------------------------------------------------------
    # data table:
    data_table = list()
    # values that are the same for all data rows
    row = {
        'density': 'gaussian',
        'weight': 'constant',
        'hold_out': False,
        'time_lower': time_list[0],
        'time_upper': time_list[-1],
        'age_lower': age_list[0],
        'age_upper': age_list[-1],
        'meas_value': iota_true,
        'meas_std': iota_true * 0.1,
        'eta': None,
        'integrand': 'Sincidence',
        'subgroup': 'world',
    }
    # values that change between rows:
    for data_id in range(n_data):
        if data_id % 2 == 0:
            row['node'] = 'north_america'
        else:
            row['node'] = 'canada'
        data_table.append(copy.copy(row))
    #
    # ----------------------------------------------------------------------
    # prior_table
    prior_table = [
        {  # prior_zero
            'name': 'prior_zero',
            'density': 'uniform',
            'lower': 0.0,
            'upper': 0.0,
            'mean': 0.0,
            'std': None,
            'eta': None
        },
        {  # prior_none
            'name': 'prior_none',
            'density': 'uniform',
            'lower': None,
            'upper': None,
            'mean': 0.0,
            'std': None,
            'eta': None
        },
        {  # prior_gauss_zero
            'name': 'prior_gauss_zero',
            'density': 'gaussian',
            'lower': None,
            'upper': None,
            'mean': 0.0,
            'std': 0.1,
            'eta': None
        },
        {  # prior_iota_parent
            'name': 'prior_iota_parent',
            'density': 'gaussian',
            'lower': iota_lower,
            'upper': iota_upper,
            'mean': iota_initial,
            'std': 0.1,
            'eta': 1e-6
        }
    ]
    # ----------------------------------------------------------------------
    # smooth table
    smooth_table = [
        {  # smooth_rate_child
            'name': 'smooth_rate_child',
            'age_id': [0],
            'time_id': [0],
            'mulstd_value_prior_name': None,
            'mulstd_dage_prior_name': None,
            'mulstd_dtime_prior_name': None,
            'fun': fun_rate_child
        },
        {  # smooth_rate_parent
            'name': 'smooth_rate_parent',
            'age_id': [0],
            'time_id': [0],
            'mulstd_value_prior_name': None,
            'mulstd_dage_prior_name': None,
            'mulstd_dtime_prior_name': None,
            'fun': fun_iota_parent
        },
        {  # smooth_zero
            'name': 'smooth_zero',
            'age_id': [0],
            'time_id': [0],
            'mulstd_value_prior_name': None,
            'mulstd_dage_prior_name': None,
            'mulstd_dtime_prior_name': None,
            'fun': fun_zero
        }
    ]
    # ----------------------------------------------------------------------
    # rate table
    rate_table = [{
        'name': 'pini',
        'parent_smooth': None,
        'child_smooth': None,
        'child_nslist': None
    }, {
        'name': 'iota',
        'parent_smooth': 'smooth_rate_parent',
        'child_smooth': 'smooth_rate_child',
        'child_nslist': None
    }, {
        'name': 'rho',
        'parent_smooth': None,
        'child_smooth': None,
        'child_nslist': None
    }, {
        'name': 'chi',
        'parent_smooth': None,
        'child_smooth': None,
        'child_nslist': None
    }, {
        'name': 'omega',
        'parent_smooth': None,
        'child_smooth': None,
        'child_nslist': None
    }]
    # ----------------------------------------------------------------------
    # option_table
    # use very large tolerance_fixed to avoid warning during test.
    option_table = [{
        'name': 'parent_node_name',
        'value': 'north_america'
    }, {
        'name': 'rate_case',
        'value': 'iota_pos_rho_zero'
    }, {
        'name': 'quasi_fixed',
        'value': 'true'
    }, {
        'name': 'max_num_iter_fixed',
        'value': '0'
    }, {
        'name': 'print_level_fixed',
        'value': '0'
    }, {
        'name': 'tolerance_fixed',
        'value': '1e+10'
    }, {
        'name': 'bound_frac_fixed',
        'value': str(bound_frac)
    }]
    # ----------------------------------------------------------------------
    # avgint table: empty
    avgint_table = list()
    # ----------------------------------------------------------------------
    # nslist_table:
    nslist_table = dict()
    # ----------------------------------------------------------------------
    # subgroup_table
    subgroup_table = [{'subgroup': 'world', 'group': 'world'}]
    # ----------------------------------------------------------------------
    # create database
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)
    # ----------------------------------------------------------------------
    n_smooth = len(smooth_table)
    return
Exemplo n.º 27
0
def example_db(file_name):
    def fun_iota_n1(a, t):
        return ('prior_iota_n1_value', None, None)

    def fun_iota_child(a, t):
        return ('prior_iota_child', None, None)

    def fun_iota_subgroup(a, t):
        return ('prior_iota_subgroup', None, None)

    #
    # node_table
    node_table = [
        {
            'name': 'n1',
            'parent': ''
        },
        {
            'name': 'n11',
            'parent': 'n1'
        },
        {
            'name': 'n12',
            'parent': 'n1'
        },
        {
            'name': 'n111',
            'parent': 'n11'
        },
        {
            'name': 'n112',
            'parent': 'n11'
        },
        {
            'name': 'n121',
            'parent': 'n12'
        },
        {
            'name': 'n122',
            'parent': 'n12'
        },
    ]
    # age_table
    age_list = [0.0, 100.0]
    # time_table
    time_list = [1990.0, 2020.0]
    # rate_table
    rate_table = [{
        'name': 'iota',
        'parent_smooth': 'smooth_iota_n1',
        'child_smooth': 'smooth_iota_child',
    }]
    #
    # subgroup_table
    subgroup_table = [
        {
            'subgroup': 'none',
            'group': 'none'
        },
        {
            'subgroup': 'n111',
            'group': 'n11'
        },
        {
            'subgroup': 'n112',
            'group': 'n11'
        },
        {
            'subgroup': 'n121',
            'group': 'n12'
        },
        {
            'subgroup': 'n122',
            'group': 'n12'
        },
    ]
    # covariate_table
    covariate_table = [{'name': 'one', 'reference': 0.0}]
    # mulcov_table
    mulcov_table = [{
        'covariate': 'one',
        'type': 'rate_value',
        'effected': 'iota',
        'group': 'n11',
        'smooth': None,
        'subsmooth': 'smooth_iota_subgroup',
    }, {
        'covariate': 'one',
        'type': 'rate_value',
        'effected': 'iota',
        'group': 'n12',
        'smooth': None,
        'subsmooth': 'smooth_iota_subgroup',
    }]
    # prior_table
    prior_table = [
     {   # prior_iota_n1_value
      'name':    'prior_iota_n1_value',
      'density': 'uniform',
      'lower':   iota_n1(0)   / 100.0,
      'upper':   iota_n1(100) * 100.0,
      'mean':    iota_n1(50) / 2.0,
     },{ # prior_iota_child
      'name':    'prior_iota_child',
      'density': 'uniform',
      'mean':     0.0,
     },{ # prior_iota_subgroup
      'name':    'prior_iota_subgroup',
      'density': 'uniform',
      'mean':     0.0,
     }
    ]
    # smooth_table
    smooth_table = [
        {  # smooth_iota_n1
            'name': 'smooth_iota_n1',
            'age_id': [0, 1],
            'time_id': [0],
            'fun': fun_iota_n1
        },
        {  # smooth_iota_child
            'name': 'smooth_iota_child',
            'age_id': [0],
            'time_id': [0],
            'fun': fun_iota_child
        },
        {  # smooth_iota_subgroup
            'name': 'smooth_iota_subgroup',
            'age_id': [0],
            'time_id': [0],
            'fun': fun_iota_subgroup
        }
    ]
    # weight table:
    weight_table = list()
    # nslist_table
    nslist_table = dict()
    # option_table
    option_table = [
        {
            'name': 'parent_node_name',
            'value': 'n1'
        },
        {
            'name': 'rate_case',
            'value': 'iota_pos_rho_zero'
        },
        {
            'name': 'zero_sum_child_rate',
            'value': 'iota'
        },
        {
            'name': 'quasi_fixed',
            'value': 'false'
        },
        {
            'name': 'max_num_iter_fixed',
            'value': '100'
        },
        {
            'name': 'print_level_fixed',
            'value': '0'
        },
        {
            'name': 'tolerance_fixed',
            'value': '1e-12'
        },
    ]
    # integrand_table
    integrand_table = [{'name': 'Sincidence'}]
    # ------------------------------------------------------------------------
    # data_table
    data_table = list()
    # values that are the same for all data points
    row = {
        'integrand': 'Sincidence',
        'density': 'gaussian',
        'weight': '',
        'hold_out': False,
        'time_lower': 2000.0,
        'time_upper': 2000.0,
        'one': 1.0,
    }
    random.seed(random_seed)
    for age_id in range(len(age_list)):
        age = age_list[age_id]
        for node in ['n1', 'n11', 'n12', 'n111', 'n112', 'n121', 'n122']:
            for i in range(data_per_node):
                iota = avg_integrand(age, node)
                meas_std = iota * meas_cv
                meas_value = random.gauss(iota, meas_std)
                if node in ['n1', 'n11', 'n12']:
                    row['subgroup'] = 'none'
                else:
                    row['subgroup'] = node
                row['node'] = node
                row['meas_value'] = meas_value
                row['meas_std'] = meas_std
                row['age_lower'] = age
                row['age_upper'] = age
                data_table.append(copy.copy(row))
    # ------------------------------------------------------------------------
    # avgint_table
    avgint_table = list()
    # ----------------------------------------------------------------------
    # create database
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)
Exemplo n.º 28
0
def example_db (file_name) :
	def constant_weight_fun(a, t) :
		return 1.0
	def fun_iota_parent(a, t) :
		return ('prior_iota_parent', None, None)
	# ----------------------------------------------------------------------
	# age table
	age_list    = [    0.0, 50.0,    100.0 ]
	#
	# time table
	time_list   = [ 1995.0, 2005.0, 2015.0 ]
	#
	# integrand table
	integrand_table = [
		{ 'name':'Sincidence' }
	]
	#
	# node table: world -> north_america
	#             north_america -> (united_states, canada)
	node_table = [
		{ 'name':'world',         'parent':'' },
	]
	#
	# weight table: The constant function 1.0 (one age and one time point)
	fun = constant_weight_fun
	weight_table = [
		{ 'name':'constant',  'age_id':[1], 'time_id':[1], 'fun':fun }
	]
	#
	# covariate table:
	covariate_table = list()
	#
	# mulcov table
	mulcov_table = list()
	#
	# avgint table: empty
	avgint_table = list()
	#
	# nslist_table:
	nslist_table = dict()
	# ----------------------------------------------------------------------
	# data table:
	data_table = list()
	# Values that are the same for all data rows
	# (because the simultion censors the data)
	meas_std   = iota_true;
	eta        = iota_true / 2.0 # large so get zeros for log scaled cases
	row = {
		'node':        'world',
		'subgroup':    'world',
		'integrand':   'Sincidence',
		'density':     density_name,
		'weight':      'constant',
		'hold_out':     False,
		'age_lower':    0.0,
		'age_upper':    0.0,
		'time_lower':   1995.0,
		'time_upper':   1995.0,
		'eta':          eta
	}
	sigma = meas_std
	mu    = iota_true
	if density_name in [ 'cen_log_gaussian', 'cen_log_laplace' ] :
		sigma  = math.log(iota_true + eta + meas_std)
		sigma -= math.log(iota_true + eta)
		mu     = math.log(iota_true + eta )
	scale = sigma / math.sqrt(2.0)
	for data_id in range( n_data ) :
		# simulate the data for distribution without censoring
		if density_name in [ 'cen_laplace', 'cen_log_laplace' ] :
			meas_value  = numpy.random.laplace(mu, scale)
		else :
			meas_value  = numpy.random.normal(mu, sigma)
		# check for log transform case
		if density_name in [ 'cen_log_gaussian', 'cen_log_laplace' ] :
			meas_value = math.exp(meas_value) - eta
		# censor the data; i.e., replace negative values by zero values.
		meas_value        = max(meas_value, 0.0)
		row['meas_value'] = meas_value
		#
		delta    = meas_std
		if density_name in [ 'cen_log_gaussian', 'cen_log_laplace' ] :
			# sigma = log(meas_value + eta + delta) - log(meas_value + eta)
			delta = (math.exp(sigma) - 1.0) * (meas_value + eta)
		row['meas_std'] = delta
		#
		data_table.append( copy.copy(row) )
	#
	# ----------------------------------------------------------------------
	# prior_table
	prior_table = [
		{ # prior_iota_parent
			'name':     'prior_iota_parent',
			'density':  'uniform',
			'lower':    0.001,
			'upper':    1.00,
			'mean':     0.1,
		}
	]
	# ----------------------------------------------------------------------
	# smooth table
	smooth_table = [
		{ # smooth_iota_parent
			'name':                     'smooth_iota_parent',
			'age_id':                   [ 0 ],
			'time_id':                  [ 0 ],
			'fun':                      fun_iota_parent
		}
	]
	# ----------------------------------------------------------------------
	# rate table
	rate_table = [
		{
			'name':          'iota',
			'parent_smooth': 'smooth_iota_parent',
		}
	]
	# ----------------------------------------------------------------------
	# option_table
	option_table = [
		{ 'name':'random_seed',            'value':str(random_seed)    },
		{ 'name':'parent_node_name',       'value':'world'             },
		{ 'name':'rate_case',              'value':'iota_pos_rho_zero' },

		{ 'name':'quasi_fixed',            'value':'false'        },
		{ 'name':'max_num_iter_fixed',     'value':'100'          },
		{ 'name':'print_level_fixed',      'value':'0'            },
		{ 'name':'tolerance_fixed',        'value':'1e-13'        },
	]
	# ----------------------------------------------------------------------
	# subgroup_table
	subgroup_table = [ { 'subgroup':'world', 'group':'world' } ]
	# ----------------------------------------------------------------------
	# create database
	dismod_at.create_database(
		file_name,
		age_list,
		time_list,
		integrand_table,
		node_table,
		subgroup_table,
		weight_table,
		covariate_table,
		avgint_table,
		data_table,
		prior_table,
		smooth_table,
		nslist_table,
		rate_table,
		mulcov_table,
		option_table
	)
	# ----------------------------------------------------------------------
	return
Exemplo n.º 29
0
def example_db(file_name):
    def fun_iota_child(a, t):
        return ('prior_iota_child', None, None)

    def fun_iota_parent(a, t):
        return ('prior_iota_parent', None, None)

    # ----------------------------------------------------------------------
    # age table
    age_list = [0.0, 100.0]
    #
    # time table
    time_list = [1995.0, 2015.0]
    node_table = [{
        'name': 'north_america',
        'parent': ''
    }, {
        'name': 'united_states',
        'parent': 'north_america'
    }, {
        'name': 'canada',
        'parent': 'north_america'
    }]
    #
    # weight table:
    weight_table = list()
    # integrand table
    integrand_table = [{'name': 'Sincidence'}, {'name': 'susceptible'}]
    #
    # covariate table: no covriates
    covariate_table = list()
    #
    # mulcov table
    mulcov_table = list()
    #
    # nslist_table:
    nslist_table = dict()
    # ----------------------------------------------------------------------
    # prior_table
    prior_table = [
     { # prior_iota_parent
      'name':     'prior_iota_parent',
      'density':  'uniform',
      'lower':    iota_north_america / 100.0,
      'upper':    iota_north_america * 100.0,
      'mean':     iota_north_america * 3.0,
     },{ # prior_iota_child
      'name':     'prior_iota_child',
      'density':  'uniform',
      'mean':     0.0,
     }
    ]
    # ----------------------------------------------------------------------
    # smooth table
    smooth_table = [
        {  # smooth_iota_parent
            'name': 'smooth_iota_parent',
            'age_id': [0],
            'time_id': [0],
            'fun': fun_iota_parent
        },
        {  # smooth_iota_child
            'name': 'smooth_iota_child',
            'age_id': [0],
            'time_id': [0],
            'fun': fun_iota_child
        }
    ]
    # ----------------------------------------------------------------------
    # rate table
    rate_table = [{
        'name': 'iota',
        'parent_smooth': 'smooth_iota_parent',
        'child_smooth': 'smooth_iota_child',
    }]
    # --------------------------------------------------------------------
    # option_table
    option_table = [
        {
            'name': 'parent_node_name',
            'value': 'north_america'
        },
        {
            'name': 'ode_step_size',
            'value': '1.0'
        },
        {
            'name': 'rate_case',
            'value': 'iota_pos_rho_zero'
        },
        {
            'name': 'quasi_fixed',
            'value': 'true'
        },
        {
            'name': 'max_num_iter_fixed',
            'value': '30'
        },
        {
            'name': 'print_level_fixed',
            'value': '0'
        },
        {
            'name': 'tolerance_fixed',
            'value': '1e-10'
        },
    ]
    # ----------------------------------------------------------------------
    # data table:
    data_table = list()
    row = {
        'density': 'log_gaussian',
        'eta': '0.0',
        'weight': '',
        'hold_out': False,
        'time_lower': 2000.0,
        'time_upper': 2000.0,
        'age_lower': 0.0,
        'age_upper': 100.0,
        'integrand': 'Sincidence',
        'subgroup': 'world',
    }
    # north_america
    row['node'] = 'north_america'
    row['meas_value'] = iota_north_america
    row['meas_std'] = row['meas_value'] / 10.0
    data_table.append(copy.copy(row))
    # canada
    row['node'] = 'canada'
    row['meas_value'] = math.exp(canada_effect) * iota_north_america
    row['meas_std'] = row['meas_value'] / 10.0
    data_table.append(copy.copy(row))
    # united_states
    row['node'] = 'united_states'
    row['meas_value'] = math.exp(united_states_effect) * iota_north_america
    row['meas_std'] = row['meas_value'] / 10.0
    data_table.append(copy.copy(row))
    # ----------------------------------------------------------------------
    # avgint table:
    avgint_table = list()
    # values that are the same for all data rows
    row = {
        'integrand': 'susceptible',
        'weight': '',
        'time_lower': 2000.0,
        'time_upper': 2000.0,
        'age_lower': 50.0,
        'age_upper': 50.0,
        'subgroup': 'world'
    }
    row['node'] = 'north_america'
    avgint_table.append(copy.copy(row))
    row['node'] = 'canada'
    avgint_table.append(copy.copy(row))
    row['node'] = 'united_states'
    avgint_table.append(copy.copy(row))
    # ----------------------------------------------------------------------
    # subgroup_table
    subgroup_table = [{'subgroup': 'world', 'group': 'world'}]
    # ----------------------------------------------------------------------
    # create database
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)
Exemplo n.º 30
0
def example_db(file_name):
    def fun_rate_child(a, t):
        return ('prior_gauss_zero', None, None)

    def fun_rate_parent(a, t):
        return ('prior_rate_parent', None, None)

    # ----------------------------------------------------------------------
    # age table
    age_list = [0.0, 100.0]
    #
    # time table
    time_list = [1995.0, 2015.0]
    #
    # integrand table
    integrand_table = [{'name': 'Sincidence'}]
    #
    node_table = [
        {
            'name': 'world',
            'parent': ''
        },
        {
            'name': 'child_0',
            'parent': 'world'
        },
        {
            'name': 'child_1',
            'parent': 'world'
        },
    ]
    #
    # weight table:
    weight_table = list()
    #
    # covariate table: no covriates
    covariate_table = list()
    #
    # mulcov table
    mulcov_table = list()
    #
    # avgint table:
    avgint_table = list()
    #
    # nslist_table:
    nslist_table = dict()
    # ----------------------------------------------------------------------
    # data table:
    data_table = list()
    row = {
        'node': 'child_0',
        'subgroup': 'world',
        'density': 'gaussian',
        'weight': '',
        'hold_out': False,
        'time_lower': 2000.0,
        'time_upper': 2000.0,
        'age_lower': 50.0,
        'age_upper': 50.0,
        'integrand': 'Sincidence',
        'meas_value': y_0,
        'meas_std': standard_dev,
    }
    data_table.append(copy.copy(row))
    #
    row['node'] = 'child_1'
    row['meas_value'] = y_1
    data_table.append(copy.copy(row))
    #
    # ----------------------------------------------------------------------
    # prior_table
    prior_table = [
     { # prior_rate_parent
      'name':     'prior_rate_parent',
      'density':  'uniform',
      'lower':    1e-2 * theta_true,
      'upper':    1e+2 * theta_true,
      'mean':     theta_true / 3.0, # only used for start and scale
     },{ # prior_gauss_zero
      'name':     'prior_gauss_zero',
      'density':  'gaussian',
      'mean':     0.0,
      'std':      standard_dev,
     }
    ]
    # ----------------------------------------------------------------------
    # smooth table
    smooth_table = [
        {  # smooth_rate_parent
            'name': 'smooth_rate_parent',
            'age_id': [0],
            'time_id': [0],
            'fun': fun_rate_parent
        },
        {  # smooth_rate_child
            'name': 'smooth_rate_child',
            'age_id': [0],
            'time_id': [0],
            'fun': fun_rate_child
        }
    ]
    # ----------------------------------------------------------------------
    # rate table
    rate_table = [{
        'name': 'iota',
        'parent_smooth': 'smooth_rate_parent',
        'child_smooth': 'smooth_rate_child',
    }]
    # ----------------------------------------------------------------------
    # option_table
    option_table = [{
        'name': 'parent_node_name',
        'value': 'world'
    }, {
        'name': 'ode_step_size',
        'value': '10.0'
    }, {
        'name': 'random_seed',
        'value': str(random_seed)
    }, {
        'name': 'rate_case',
        'value': 'iota_pos_rho_zero'
    }, {
        'name': 'quasi_fixed',
        'value': 'true'
    }, {
        'name': 'derivative_test_fixed',
        'value': 'none'
    }, {
        'name': 'max_num_iter_fixed',
        'value': '100'
    }, {
        'name': 'print_level_fixed',
        'value': '0'
    }, {
        'name': 'tolerance_fixed',
        'value': '1e-12'
    }, {
        'name': 'derivative_test_random',
        'value': 'none'
    }, {
        'name': 'max_num_iter_random',
        'value': '100'
    }, {
        'name': 'print_level_random',
        'value': '0'
    }, {
        'name': 'tolerance_random',
        'value': '1e-12'
    }]
    # ----------------------------------------------------------------------
    # subgroup_table
    subgroup_table = [{'subgroup': 'world', 'group': 'world'}]
    # ----------------------------------------------------------------------
    # create database
    dismod_at.create_database(file_name, age_list, time_list, integrand_table,
                              node_table, subgroup_table, weight_table,
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)