Exemple #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
 def updateMeasNoiseDensity(self, density_name: str, params: Dict[str,
                                                                  Any]):
     connection = dismod_at.create_connection(self.path, False)
     density_table = dismod_at.get_table_dict(connection, 'density')
     command = 'UPDATE data SET density_id = ' \
         + str(self.density_dict[density_name])
     print(command)
     dismod_at.sql_command(connection, command)
     for k, v in params.items():
         command = 'UPDATE data SET ' + k + ' = ' + str(v)
         dismod_at.sql_command(connection, command)
         print(command)
     connection.close()
Exemple #3
0
file_name = 'get_started.db'
connection = dismod_at.create_connection(file_name, new)
option_table = dismod_at.get_table_dict(connection, 'option')
node_table = dismod_at.get_table_dict(connection, 'node')
parent_node_id = None
for row in option_table:
    if row['option_name'] == 'parent_node_name':
        name = row['option_value']
        for node_id in range(len(node_table)):
            if node_table[node_id]['node_name'] == name:
                assert parent_node_id == None
                parent_node_id = str(node_id)
assert parent_node_id != None
cmd = "INSERT INTO option ('option_name', 'option_value')"
cmd += " VALUES('parent_node_id', '" + parent_node_id + "')"
dismod_at.sql_command(connection, cmd)
connection.close()
# -----------------------------------------------------------------------
program = '../../devel/dismod_at'
for command in ['init', 'fit']:
    cmd = [program, file_name, command]
    if command == 'fit':
        variables = 'both'
        cmd.append(variables)
    print(' '.join(cmd))
    flag = subprocess.call(cmd)
    if flag != 0:
        sys.exit('The dismod_at ' + command + ' command failed')
# -----------------------------------------------------------------------
# connect to database
new = False
Exemple #4
0
def sql_count_rows(connection, table_name) :
	sqlcmd = 'SELECT COUNT(*) FROM ' + table_name
	result = dismod_at.sql_command(connection, sqlcmd)
	n_row  = result[0][0]
	return n_row
Exemple #5
0
	predict_array[sample_index, avgint_id] = value
	predict_found[avgint_id] = True
predict_mean = numpy.mean(predict_array, axis=0)
predict_std  = numpy.std(predict_array, axis=0, ddof = 1)
# -----------------------------------------------------------------------------
# Step 6: Priors for n11 as Parent
# -----------------------------------------------------------------------------
# create fit_n11.db starting from fit_n1.db
shutil.copyfile(file_name, 'fit_n11.db')
file_name = 'fit_n11.db'
connection.close()
connection       = dismod_at.create_connection(file_name, new)
#
# get last id from certain tables
sqlcmd           = 'SELECT COUNT(prior_id) FROM prior'
result           = dismod_at.sql_command(connection, sqlcmd)
prior_id         = sql_count_rows(connection, 'prior') - 1
smooth_id        = sql_count_rows(connection, 'smooth') - 1
smooth_grid_id   = sql_count_rows(connection, 'smooth_grid') - 1
#
sqlcmd      = 'SELECT density_id FROM density WHERE density_name=="uniform"'
result      = dismod_at.sql_command(connection, sqlcmd)
uniform_id  = result[0][0]
#
sqlcmd      = 'SELECT density_id FROM density WHERE density_name=="gaussian"'
result      = dismod_at.sql_command(connection, sqlcmd)
gaussian_id = result[0][0]
#
# add smooth_iota_n11
smooth_name = 'smooth_iota_n11'
n_age       = len( age_table )
Exemple #6
0
			assert( covariate_name == 'one' )
			#
			truth_var_value = gamma_true(meas_noise_effect)
		else :
			assert( var_type == 'rate' )
			rate_id   = var_info['rate_id']
			rate_name = rate_table[rate_id]['rate_name']
			node_id   = var_info['node_id']
			node_name = node_table[node_id]['node_name']
			assert node_name == 'world'
			#
			truth_var_value = iota_true
		#
		var_id2true.append( truth_var_value )
		row_list.append( [ truth_var_value ] )
	dismod_at.sql_command(connection, 'DROP TABLE IF EXISTS truth_var')
	dismod_at.create_table(connection, tbl_name, col_name, col_type, row_list)
	# -------------------------------------------------------------------------
	# create and check the data_sim table
	dismod_at.system_command_prc([ program, file_name, 'simulate', '1' ])
	#
	# check results in data_sim table
	new               = False
	connection        = dismod_at.create_connection(file_name, new)
	density_table     = dismod_at.get_table_dict(connection, 'density')
	data_table        = dismod_at.get_table_dict(connection, 'data')
	data_subset_table = dismod_at.get_table_dict(connection, 'data_subset')
	data_sim_table    = dismod_at.get_table_dict(connection, 'data_sim')
	#
	# check that all the data_id appear in the data_subset table
	for data_subset_id in range(len(data_subset_table)) :