Esempio n. 1
0
def optimal_random_effect(fixed_effect):
    #
    # set start_var value for the fixed effects
    var_id = node_name2var_id['world']
    sql_cmd = 'UPDATE start_var SET start_var_value = ' + str(fixed_effect)
    sql_cmd += ' WHERE start_var_id == ' + str(var_id)
    new = False
    connection = dismod_at.create_connection(file_name, new)
    dismod_at.sql_command(connection, sql_cmd)
    connection.close()
    #
    # optimize the random effects
    dismod_at.system_command_prc([program, file_name, 'fit', 'random'])
    #
    # retrieve the optimal random effects
    new = False
    connection = dismod_at.create_connection(file_name, new)
    fit_var_table = dismod_at.get_table_dict(connection, 'fit_var')
    #
    var_id = node_name2var_id['child_0']
    uhat_0 = fit_var_table[var_id]['fit_var_value']
    #
    var_id = node_name2var_id['child_1']
    uhat_1 = fit_var_table[var_id]['fit_var_value']
    #
    uhat = numpy.array([uhat_0, uhat_1])
    return uhat
Esempio n. 2
0
        else:
            assert False
        #
        row_list.append([value])
    dismod_at.create_table(connection, tbl_name, col_name, col_type, row_list)
    connection.close()
    return


# ===========================================================================
# Run the init command to create the var table
file_name = 'example.db'
example_db(file_name)
#
program = '../../devel/dismod_at'
dismod_at.system_command_prc([program, file_name, 'init'])
# -----------------------------------------------------------------------
# create truth_var table
create_truth_var_table()
# -----------------------------------------------------------------------------
# create predict table
dismod_at.system_command_prc([program, file_name, 'predict', 'truth_var'])
# -----------------------------------------------------------------------------
# add data to data table
new = False
connection = dismod_at.create_connection(file_name, new)
predict_table = dismod_at.get_table_dict(connection, 'predict')
avgint_table = dismod_at.get_table_dict(connection, 'avgint')
density_table = dismod_at.get_table_dict(connection, 'density')
#
# get column names and types for data table
Esempio n. 3
0
                              covariate_table, avgint_table, data_table,
                              prior_table, smooth_table, nslist_table,
                              rate_table, mulcov_table, option_table)


# ---------------------------------------------------------------------------
# Fit Both
# ---------------------------------------------------------------------------
#
# create the database
file_name = 'example.db'
example_db(file_name)
#
# initialize the database
program = '../../devel/dismod_at'
dismod_at.system_command_prc([program, file_name, 'init'])
#
# fit both the fixed and random effects
dismod_at.system_command_prc([program, file_name, 'fit', 'both'])
# ---------------------------------------------------------------------------
# Compare Fit and Truth
# ---------------------------------------------------------------------------
#
# read var table and supporting information including the fit
new = False
connection = dismod_at.create_connection(file_name, new)
subgroup_table = dismod_at.get_table_dict(connection, 'subgroup')
node_table = dismod_at.get_table_dict(connection, 'node')
age_table = dismod_at.get_table_dict(connection, 'age')
var_table = dismod_at.get_table_dict(connection, 'var')
fit_var_table = dismod_at.get_table_dict(connection, 'fit_var')
Esempio n. 4
0
    # 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


# ===========================================================================
# create the database
file_name = 'example.db'
example_db(file_name)
#
program = '../../devel/dismod_at'
dismod_at.system_command_prc([program, file_name, 'init'])
dismod_at.system_command_prc(
    [program, file_name, 'set', 'option', 'max_num_iter_fixed', '1'])
dismod_at.system_command_prc([program, file_name, 'fit', 'both'])
dismod_at.system_command_prc(
    [program, file_name, 'set', 'scale_var', 'fit_var'])
dismod_at.system_command_prc(
    [program, file_name, 'set', 'option', 'max_num_iter_fixed', '30'])
dismod_at.system_command_prc(
    [program, file_name, 'set', 'option', 'warn_on_stderr', 'true'])
dismod_at.system_command_prc([program, file_name, 'fit', 'both'])
# -----------------------------------------------------------------------
# connect to database
new = False
connection = dismod_at.create_connection(file_name, new)
#
Esempio n. 5
0
		data_table,
		prior_table,
		smooth_table,
		nslist_table,
		rate_table,
		mulcov_table,
		option_table
	)
	# ----------------------------------------------------------------------
	n_smooth  = len( smooth_table )
# ===========================================================================
file_name  = 'example.db'
example_db(file_name)
#
program = '../../devel/dismod_at'
dismod_at.system_command_prc([ program, file_name, 'init' ])
dismod_at.system_command_prc([ program, file_name, 'fit', 'both' ])
dismod_at.system_command_prc(
	[ program, file_name, 'sample', 'asymptotic', 'both', '20' ]
)
# --------------------------------------------------------------------------
# BEGIN call plot_rate_fit
database   = file_name
rate_set   = { 'iota', 'chi' }
pdf_file   = 'example.pdf'
plot_title = 'Example Rate Plot'
plot_set   = dismod_at.plot_rate_fit(database, pdf_file, plot_title, rate_set)
assert plot_set == rate_set
# END call plot_rate_fit
# -----------------------------------------------------------------------
# connect to database
Esempio n. 6
0
		smooth_table,
		nslist_table,
		rate_table,
		mulcov_table,
		option_table
	)
	# ----------------------------------------------------------------------
	return
# ===========================================================================
# Create database
file_name = 'example.db'
example_db(file_name)
program = '../../devel/dismod_at'
#
# fit fixed
dismod_at.system_command_prc([ program, file_name, 'init' ])
dismod_at.system_command_prc([
	program, file_name, 'set', 'truth_var', 'prior_mean'
])
dismod_at.system_command_prc([ program, file_name, 'predict', 'truth_var' ])
#
#
new             = False
connection      = dismod_at.create_connection(file_name, new)
data_table      = dismod_at.get_table_dict(connection, 'data')
avgint_table    = dismod_at.get_table_dict(connection, 'avgint')
predict_table   = dismod_at.get_table_dict(connection, 'predict')
#
n_data =  len(data_table)
assert len(avgint_table) == n_data
assert len(predict_table) == n_data
Esempio n. 7
0
    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)


# ===========================================================================
file_name = 'example.db'
example_db(file_name)
#
program = '../../devel/dismod_at'
dismod_at.system_command_prc([program, file_name, 'init'])
dismod_at.system_command_prc([program, file_name, 'fit', 'both'])
dismod_at.system_command_prc(
    [program, file_name, 'sample', 'asymptotic', 'both',
     str(number_sample)])
# -----------------------------------------------------------------------
# get tables
new = False
connection = dismod_at.create_connection(file_name, new)
var_table = dismod_at.get_table_dict(connection, 'var')
node_table = dismod_at.get_table_dict(connection, 'node')
rate_table = dismod_at.get_table_dict(connection, 'rate')
fit_var_table = dismod_at.get_table_dict(connection, 'fit_var')
sample_table = dismod_at.get_table_dict(connection, 'sample')
hes_random_table = dismod_at.get_table_dict(connection, 'hes_random')
connection.close()
Esempio n. 8
0
                              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


# ===========================================================================
# Create database and run init, start, fit with just fixed effects
file_name = 'example.db'
example_db(file_name)
program = '../../devel/dismod_at'
#
# init
dismod_at.system_command_prc([program, file_name, 'init'])
#
# set
dismod_at.system_command_prc(
    [program, file_name, 'set', 'truth_var', 'prior_mean'])
#
# simulate
dismod_at.system_command_prc(
    [program, file_name, 'simulate',
     str(number_sample)])
#
# sample simulate
dismod_at.system_command_prc(
    [program, file_name, 'sample', 'simulate', 'both',
     str(number_sample)])
# -----------------------------------------------------------------------
Esempio n. 9
0
		prior_table,
		smooth_table,
		nslist_table,
		rate_table,
		mulcov_table,
		option_table
	)
# ---------------------------------------------------------------------------
# Step 1: Create fit_n1.db
# ---------------------------------------------------------------------------
file_name  = 'fit_n1.db'
example_db(file_name)
#
# init
program = '../../devel/dismod_at'
dismod_at.system_command_prc( [ program, file_name, 'init' ] )
# -----------------------------------------------------------------------------
# Step 2: Fit With n1 As Parent
# -----------------------------------------------------------------------------
dismod_at.system_command_prc( [ program, file_name, 'fit', 'both' ] )
#
# check e1
new              = False
connection       = dismod_at.create_connection(file_name, new)
rate_table       = dismod_at.get_table_dict(connection, 'rate')
node_table       = dismod_at.get_table_dict(connection, 'node')
age_table        = dismod_at.get_table_dict(connection, 'age')
var_table        = dismod_at.get_table_dict(connection, 'var')
fit_var_table    = dismod_at.get_table_dict(connection, 'fit_var')
covariate_table  = dismod_at.get_table_dict(connection, 'covariate')
n_var            = len(var_table)
Esempio n. 10
0
    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


# ===========================================================================
# Create database
file_name = 'example.db'
example_db(file_name)
#
program = '../../devel/dismod_at'
dismod_at.system_command_prc([program, file_name, 'init'])
dismod_at.system_command_prc(
    [program, file_name, 'bnd_mulcov',
     str(max_abs_effect), 'income'])
dismod_at.system_command_prc([program, file_name, 'fit', 'fixed'])
# -----------------------------------------------------------------------
# read database
new = False
connection = dismod_at.create_connection(file_name, new)
var_table = dismod_at.get_table_dict(connection, 'var')
fit_var_table = dismod_at.get_table_dict(connection, 'fit_var')
bnd_mulcov_table = dismod_at.get_table_dict(connection, 'bnd_mulcov')
mulcov_table = dismod_at.get_table_dict(connection, 'mulcov')
covariate_table = dismod_at.get_table_dict(connection, 'covariate')
connection.close()
#
Esempio n. 11
0
                              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


# ===========================================================================
# create the database
file_name = 'example.db'
example_db(file_name)
#
# fit data
program_cpp = '../../devel/dismod_at'
program_py = '../../../bin/dismodat.py'
dismod_at.system_command_prc([program_cpp, file_name, 'init'])
dismod_at.system_command_prc([program_cpp, file_name, 'fit', 'fixed'])
dismod_at.system_command_prc([program_py, file_name, 'db2csv'])
#
# weighted residuals
file_in = 'data.csv'
file_in = open(file_in, 'r')
reader = csv.DictReader(file_in)
time_r = list()
residual = list()
for row in reader:
    assert row['integrand'] == 'mtspecific'
    assert row['time_lo'] == row['time_up']
    time_r.append(float(row['time_lo']))
    residual.append(float(row['residual']))
residual_max = numpy.max(residual)
Esempio n. 12
0
		avgint_table,
		data_table,
		prior_table,
		smooth_table,
		nslist_table,
		rate_table,
		mulcov_table,
		option_table
	)
# ===========================================================================
file_name  = 'example.db'
example_db(file_name)
#
program   = '../../devel/dismod_at'
ns_string = str(number_sample)
dismod_at.system_command_prc([ program, file_name, 'init' ])
#
# Tables that are the same for both types of sampling
new           = False
connection    = dismod_at.create_connection(file_name, new)
var_table     = dismod_at.get_table_dict(connection, 'var')
node_table    = dismod_at.get_table_dict(connection, 'node')
rate_table    = dismod_at.get_table_dict(connection, 'rate')
connection.close()
assert len(var_table) == 3
#
# map from node name to variable id
node_name2var_id = dict()
for var_id in range(len(var_table) ) :
	row = var_table[var_id]
	assert row['var_type'] == 'rate'
Esempio n. 13
0
#
# import get_started_db example
sys.path.append(os.getcwd() + '/example/get_started')
import get_started_db
#
# change into the build/example/get_started directory
distutils.dir_util.mkpath('build/example/get_started')
os.chdir('build/example/get_started')
# ---------------------------------------------------------------------------
# create get_started.db
get_started_db.get_started_db()
# -----------------------------------------------------------------------
# create the var table
program = '../../devel/dismod_at'
file_name = 'get_started.db'
dismod_at.system_command_prc([program, file_name, 'init'])
# -----------------------------------------------------------------------
# connect to database
new = False
connection = dismod_at.create_connection(file_name, new)
# -----------------------------------------------------------------------
# get the variable information
var_table = dismod_at.get_table_dict(connection, 'var')
# -----------------------------------------------------------------------
# create a truth_var table with variables values to use during simulation
tbl_name = 'truth_var'
col_name = ['truth_var_value']
col_type = ['real']
row_list = list()
omega_world = 2e-2
income_multiplier = -1e-3
Esempio n. 14
0
import dismod_at
#
# change into the build/example/user directory
if not os.path.exists('build/example/user'):
    os.makedirs('build/example/user')
os.chdir('build/example/user')
#
# command
command = ['echo', 'system_command_prc: Test Output']
#
# result is stdout
result = dismod_at.system_command_prc(
    command,
    print_command=False,
    return_stdout=True,
    return_stderr=False,
    file_stdout=None,
    file_stderr=None,
    write_command=False,
)
assert result == command[1] + '\n'
#
# result is None
result = dismod_at.system_command_prc(
    command,
    print_command=False,
    return_stdout=False,
    return_stderr=False,
    file_stdout=None,
    file_stderr=None,
    write_command=False,
Esempio n. 15
0
		data_table,
		prior_table,
		smooth_table,
		nslist_table,
		rate_table,
		mulcov_table,
		option_table
	)
	# ----------------------------------------------------------------------
# ===========================================================================
# Create database and run init, start, fit with just fixed effects
file_name = 'example.db'
example_db(file_name)
#
program = '../../devel/dismod_at'
dismod_at.system_command_prc([ program, file_name, 'init' ])
dismod_at.system_command_prc([ program, file_name, 'fit', 'fixed' ])
#
# set start_var table equal to fit_var table
dismod_at.system_command_prc(
	[ program, file_name, 'set', 'start_var', 'fit_var' ]
)
#
# change the density from gaussian to students
integrand_name = 'Sincidence'
density_name   = 'students'
eta_str        = 'null'
nu_str         = str(nu)
dismod_at.system_command_prc([
	program, file_name, 'data_density',
	integrand_name, density_name, eta_str, nu_str
Esempio n. 16
0
#
# Drop group_id column from mulcov table
sql_cmd = 'ALTER TABLE mulcov RENAME COLUMN group_id TO not_used_one'
dismod_at.sql_command(connection, sql_cmd)
#
# Drop subgroup_smooth_id column from mulcov table
sql_cmd = 'ALTER TABLE mulcov RENAME COLUMN subgroup_smooth_id TO not_used_two'
dismod_at.sql_command(connection, sql_cmd)
#
# Rename group_smooth_id column to smooth_id in mulcov table
sql_cmd = 'ALTER TABLE mulcov RENAME COLUMN group_smooth_id TO smooth_id'
dismod_at.sql_command(connection, sql_cmd)
#
# close the database
connection.close()
#
# use old2new_command to restore the database
program   = '../../devel/dismod_at'
file_name = 'get_started.db'
command   = 'old2new'
dismod_at.system_command_prc( [ program, file_name, command ] )
#
# check that restore worked by running init command
command   = 'init'
dismod_at.system_command_prc( [ program, file_name, command ] )
#
# -----------------------------------------------------------------------
print('old2new_command: OK')
sys.exit(0)
# END PYTHON
Esempio n. 17
0
    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


# ===========================================================================
# Run the init command to create the var table
file_name = 'example.db'
example_db(file_name)
#
program = '../../devel/dismod_at'
dismod_at.system_command_prc([program, file_name, 'init'])
# -----------------------------------------------------------------------
# read database
new = False
connection = dismod_at.create_connection(file_name, new)
var_table = dismod_at.get_table_dict(connection, 'var')
rate_table = dismod_at.get_table_dict(connection, 'rate')
integrand_table = dismod_at.get_table_dict(connection, 'integrand')
covariate_table = dismod_at.get_table_dict(connection, 'covariate')
node_table = dismod_at.get_table_dict(connection, 'node')
# -----------------------------------------------------------------------
# truth table:
tbl_name = 'truth_var'
col_name = ['truth_var_value']
col_type = ['real']
row_list = list()
Esempio n. 18
0
    # ----------------------------------------------------------------------
    # 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)


# ===========================================================================
file_name = 'example.db'
example_db(file_name)
#
program = '../../devel/dismod_at'
na_string = str(number_sample)
dismod_at.system_command_prc([program, file_name, 'init'])
#
# -----------------------------------------------------------------------
# create truth_table
# -----------------------------------------------------------------------
# truth table:
new = False
connection = dismod_at.create_connection(file_name, new)
var_table = dismod_at.get_table_dict(connection, 'var')
rate_table = dismod_at.get_table_dict(connection, 'rate')
node_table = dismod_at.get_table_dict(connection, 'node')
assert len(var_table) == 3
#
tbl_name = 'truth_var'
col_name = ['truth_var_value']
col_type = ['real']
Esempio n. 19
0
                              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


# ===========================================================================
# create database
database = 'example.db'
example_db(database)
#
# init
program = '../../devel/dismod_at'
dismod_at.system_command_prc([program, database, 'init'])
#
# fit fixed
dismod_at.system_command_prc([program, database, 'fit', 'fixed'])
# -----------------------------------------------------------------------------
# read tables
#
new = False
connection = dismod_at.create_connection(database, new)
#
name_list = [
    'fit_var',
    'data',
]
table_list = dict()
for table_name in name_list:
Esempio n. 20
0
                              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


# ===========================================================================
# Create database
file_name = 'example.db'
example_db(file_name)
#
#
program = '../../devel/dismod_at'
dismod_at.system_command_prc([program, file_name, 'init'])
#
integrand = 'Sincidence'
#
# hold out all the data (as a test of putting it back in)
max_fit = "0"
dismod_at.system_command_prc(
    [program, file_name, 'hold_out', integrand, max_fit])
#
# hold out half of the data
max_fit = len_data_table / 2
dismod_at.system_command_prc(
    [program, file_name, 'hold_out', integrand,
     str(max_fit)])
# -----------------------------------------------------------------------
# read database
Esempio n. 21
0
		prior_table,
		smooth_table,
		nslist_table,
		rate_table,
		mulcov_table,
		option_table
	)
	# ----------------------------------------------------------------------
	return
# ===========================================================================
# Run the init command to create the var table
file_name = 'example.db'
example_db(file_name)
#
program = '../../devel/dismod_at'
dismod_at.system_command_prc([ program, file_name, 'init' ])
# -----------------------------------------------------------------------
# read database
new             = False
connection      = dismod_at.create_connection(file_name, new)
var_table        = dismod_at.get_table_dict(connection, 'var')
rate_table     = dismod_at.get_table_dict(connection, 'rate')
covariate_table= dismod_at.get_table_dict(connection, 'covariate')
# -----------------------------------------------------------------------
# truth table:
tbl_name     = 'truth_var'
col_name     = [ 'truth_var_value' ]
col_type     = [ 'real' ]
row_list     = list()
var_id2true  = list()
for var_id in range( len(var_table) ) :
Esempio n. 22
0
def exec_shell_cmd(cmd):
    program = '../../devel/dismod_at'
    command = [program, database] + cmd.split()
    dismod_at.system_command_prc(command)
Esempio n. 23
0
    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)
    # ----------------------------------------------------------------------


# ===========================================================================
# Create database and run init, start, fit with zero sum for random effects
file_name = 'example.db'
example_db(file_name)
#
from dismod_at import system_command_prc
program = '../../devel/dismod_at'
system_command_prc([program, file_name, 'init'])
system_command_prc([program, file_name, 'fit', 'fixed'])
system_command_prc([program, file_name, 'fit', 'both'])
# -----------------------------------------------------------------------
# connect to database
new = False
connection = dismod_at.create_connection(file_name, new)
# -----------------------------------------------------------------------
# check the zero random effects solution
#
# get variable and fit_var tables
var_table = dismod_at.get_table_dict(connection, 'var')
fit_var_table = dismod_at.get_table_dict(connection, 'fit_var')
rate_table = dismod_at.get_table_dict(connection, 'rate')
node_table = dismod_at.get_table_dict(connection, 'node')
time_table = dismod_at.get_table_dict(connection, 'time')
Esempio n. 24
0
get_started_db.get_started_db()
# -----------------------------------------------------------------------
# change into distribution directory to run sandbox version of dismodat.py
# return to test_dir when done.
os.chdir(dist_dir)
print(os.getcwd())
program = 'bin/dismodat.py'
file_name = test_dir + '/get_started.db'
command = 'modify'
table_name = 'data'  # table we are modifiying
column_name = 'density_id'  # column we are modifying
row_expression = 'data_id==0'  # row we are modifiying
value_expression = '6'  # value we are placeing in that row, column
system_cmd = [
    program, file_name, command, table_name, column_name, row_expression,
    value_expression
]
dismod_at.system_command_prc(system_cmd)
# -----------------------------------------------------------------------
# get data table
new = False
connection = dismod_at.create_connection(file_name, new)
data_table = dismod_at.get_table_dict(connection, 'data')
connection.close()
data_id = 0
column_name = 'density_id'
assert data_table[data_id][column_name] == 6
# -----------------------------------------------------------------------
print('modify_command.py: OK')
# END PYTHON
Esempio n. 25
0
		prior_table,
		smooth_table,
		nslist_table,
		rate_table,
		mulcov_table,
		option_table
	)
	# ----------------------------------------------------------------------
	return
# ===========================================================================
# Create database and run init, start, fit with just fixed effects
file_name = 'example.db'
example_db(file_name)
#
program = '../../devel/dismod_at'
dismod_at.system_command_prc([ program, file_name, 'init' ])
dismod_at.system_command_prc([ program, file_name, 'fit', 'fixed' ])
# -----------------------------------------------------------------------
# connect to database
new             = False
connection      = dismod_at.create_connection(file_name, new)
# -----------------------------------------------------------------------
# check the zero random effects solution
#
# get variable and fit_var tables
var_table     = dismod_at.get_table_dict(connection, 'var')
fit_var_table = dismod_at.get_table_dict(connection, 'fit_var')
rate_table    = dismod_at.get_table_dict(connection, 'rate')
node_table    = dismod_at.get_table_dict(connection, 'node')
#
# one age and two times for each of north_america, canada, unites_states
Esempio n. 26
0
    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


# ===========================================================================
# Create database
file_name = 'example.db'
example_db(file_name)
#
program = '../../devel/dismod_at'
dismod_at.system_command_prc([program, file_name, 'init'])
stdout = dismod_at.system_command_prc([program, file_name, 'fit', 'both'])
# -----------------------------------------------------------------------
# Check trace_init_fit_model results
check = 'Begin dismod_at: fit_model constructor\n'
check += 'Begin cppad_mixed::initialize\n'
check += 'init_ran_like_done_\n'
check += 'init_ran_jac_done_\n'
check += 'init_ran_hes_done_\n'
check += 'init_ldlt_ran_hes_done_\n'
check += 'init_hes_cross_done_\n'
check += 'init_fix_like_done_\n'
check += 'init_fix_con_done_\n'
check += 'End cppad_mixed::initialize\n'
check += 'End dismod_at: fit_model constructor\n'
check += 'Begin cppad_mixed::init_laplace_obj\n'
Esempio n. 27
0
    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


# ===========================================================================
# Create database and run init, start, fit with just fixed effects
file_name = 'example.db'
example_db(file_name)
#
program = '../../devel/dismod_at'
dismod_at.system_command_prc([program, file_name, 'init'])
dismod_at.system_command_prc([program, file_name, 'fit', 'random'])
# -----------------------------------------------------------------------
# connect to database
new = False
connection = dismod_at.create_connection(file_name, new)
# -----------------------------------------------------------------------
# check the zero random effects solution
#
# get variable and fit_var tables
var_table = dismod_at.get_table_dict(connection, 'var')
fit_var_table = dismod_at.get_table_dict(connection, 'fit_var')
rate_table = dismod_at.get_table_dict(connection, 'rate')
node_table = dismod_at.get_table_dict(connection, 'node')
#
# one age and two times for each of north_america, canada, unites_states
Esempio n. 28
0
import dismod_at
#
# import get_started_db example
sys.path.append(os.getcwd() + '/example/get_started')
import get_started_db
#
# change into the build/example/get_started directory
distutils.dir_util.mkpath(test_dir)
os.chdir(test_dir)
# ---------------------------------------------------------------------------
# create get_started.db
get_started_db.get_started_db()
# -----------------------------------------------------------------------
program = '../../devel/dismod_at'
file_name = 'get_started.db'
dismod_at.system_command_prc([program, file_name, 'init'])
dismod_at.system_command_prc([program, file_name, 'fit', 'both'])
#
# change into distribution directory to run sandbox version of dismodat.py
# return to test_dir when done.
os.chdir(dist_dir)
print(os.getcwd())
program = 'bin/dismodat.py'
file_name = test_dir + '/get_started.db'
dismod_at.system_command_prc([program, file_name, 'db2csv'])
os.chdir(test_dir)


# ---------------------------------------------------------------------------
# get_table
def get_table(name):
Esempio n. 29
0
    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)


# ===========================================================================
file_name = 'example.db'
example_db(file_name)
#
program = '../../devel/dismod_at'
dismod_at.system_command_prc([program, file_name, 'init'])
dismod_at.system_command_prc([program, file_name, 'fit', 'both'])
dismod_at.system_command_prc([program, file_name, 'predict', 'fit_var'])
# -----------------------------------------------------------------------
# connect to database
new = False
connection = dismod_at.create_connection(file_name, new)
predict_table = dismod_at.get_table_dict(connection, 'predict')
avgint_table = dismod_at.get_table_dict(connection, 'avgint')
node_table = dismod_at.get_table_dict(connection, 'node')
#
# check that all the avgint_table values were predicted (no subsetting)
assert len(predict_table) == 3
#
# S(a) = exp( - iota * a )
iota_canada = math.exp(canada_effect) * iota_north_america
Esempio n. 30
0
    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


# ===========================================================================
# Run the init command to create the var table
file_name = 'example.db'
example_db(file_name)
#
program = '../../devel/dismod_at'
dismod_at.system_command_prc([program, file_name, 'init'])
# -----------------------------------------------------------------------
# read database
new = False
connection = dismod_at.create_connection(file_name, new)
var_table = dismod_at.get_table_dict(connection, 'var')
rate_table = dismod_at.get_table_dict(connection, 'rate')
covariate_table = dismod_at.get_table_dict(connection, 'covariate')
# -----------------------------------------------------------------------
# truth table:
tbl_name = 'truth_var'
col_name = ['truth_var_value']
col_type = ['real']
row_list = list()
var_id2true = list()
for var_id in range(len(var_table)):