Skip to content

Commit

Permalink
Merge pull request #2 from tomaskourim/paper_finalization
Browse files Browse the repository at this point in the history
Paper finalization
  • Loading branch information
tomaskourim authored Apr 24, 2020
2 parents c76326e + 2348b64 commit bffd25c
Show file tree
Hide file tree
Showing 14 changed files with 3,010 additions and 642 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ logfile_error.log
logfile_info.log
logfile_total.log
venv/
paper/aux_files
paper/aux_files
simulations_test
out/
paper/A model of random walk with varying transition probabilities.synctex.gz
6 changes: 3 additions & 3 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
C_LAMBDA_PAIRS = [[0.5, 0.8], [0.1, 0.5], [0.5, 0.99], [0.99, 0.9]]
START_PROBABILITIES = [0.5, 0.8, 0.9, 0.99]
STEP_COUNTS = [5, 10, 50, 100]
REPETITIONS_OF_WALK_S = [10000, 10, 100]
REPETITIONS_OF_WALK_S = [10000]
REPETITIONS_OF_WALK_SERIES = 100

C_LAMBDAS_TESTING = [0.2, 0.75, 0.95]
C_LAMBDA_PAIRS_TESTING = [[0.5, 0.8], [0.75, 0.9], [0.2, 0.6]]
START_PROBABILITIES_TESTING = [0.99, 0.8, 0.4]
STEP_COUNTS_TESTING = [20,50]
STEP_COUNTS_TESTING = [200]

MODEL_TYPES = ['success_punished', 'success_rewarded', 'success_punished_two_lambdas', 'success_rewarded_two_lambdas']
DATA_DIRNAME = "generated_walks"
PREDICTION_TYPES = ["only_lambda", "only_p0", "all_parameters", "everything"]
PREDICTION_TYPES = ["only_lambda", "only_p0", "all_parameters", "everything"]\

OPTIMIZATION_ALGORITHM = 'Nelder-Mead'

Expand Down
141 changes: 71 additions & 70 deletions graphs_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,86 +14,87 @@ def main(simulated_property="probability"):
mean_styles = ['g.', 'r.', 'b.']
var_styles = ['g-.', 'r-.', 'b-.']
expected_styles = ['g-', 'r-', 'b-']
model_min_y = [-3, -10, -25, -100]
model_max_y = [20, 30, 25, 200]
model_min_y = [-3, -10, 0, 0]
model_max_y = [20, 30, 50, 2000]
for step_count in STEP_COUNTS_TESTING:
for model_index, model_type in enumerate(MODEL_TYPES):
# if model_type != 'success_rewarded':
# continue
if 'two_lambdas' in model_type:
two_lambda = True
else:
two_lambda = False
# TODO handle with dignity
min_y = 0 if simulated_property == "probability" else model_min_y[model_index]
max_y = 1 if simulated_property == "probability" else model_max_y[model_index]
for p_index, starting_probability in enumerate(START_PROBABILITIES_TESTING):
plt.subplot(plt_rows, plt_columns, p_index + 1)
plt.title(r'$p_{0}=%.2f$' % starting_probability, fontsize=20)
plt.axis([1, step_count, min_y, max_y])
plt.xlabel('steps', fontsize=18)
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)
for index, c_lambda in enumerate(C_LAMBDAS_TESTING):
if two_lambda:
c_lambdas = C_LAMBDA_PAIRS_TESTING[index]
label = r'$\bar{\lambda}=[%.2f,%.2f]$' % (c_lambdas[0], c_lambdas[1])
else:
c_lambdas = [c_lambda]
label = r'$\lambda=%.2f$' % c_lambda
walks = generate_random_walks(model_type, starting_probability, c_lambdas, step_count,
REPETITIONS_OF_WALK_S[0])
probabilities, steps, developments = list_walks2list_lists(walks)
for repetitions in REPETITIONS_OF_WALK_S:
for model_index, model_type in enumerate(MODEL_TYPES):
if 'two_lambdas' in model_type:
two_lambda = True
else:
two_lambda = False
# TODO handle with dignity
min_y = 0 if simulated_property == "probability" else model_min_y[model_index]
max_y = 1 if simulated_property == "probability" else model_max_y[model_index]
for p_index, starting_probability in enumerate(START_PROBABILITIES_TESTING):
plt.subplot(plt_rows, plt_columns, p_index + 1)
plt.title(r'$p_{0}=%.2f$' % starting_probability, fontsize=20)
plt.axis([1, step_count, min_y, max_y])
plt.xlabel('steps', fontsize=18)
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)
for index, c_lambda in enumerate(C_LAMBDAS_TESTING):
if two_lambda:
c_lambdas = C_LAMBDA_PAIRS_TESTING[index]
label = r'$\bar{\lambda}=[%.2f,%.2f]$' % (c_lambdas[0], c_lambdas[1])
else:
c_lambdas = [c_lambda]
label = r'$\lambda=%.2f$' % c_lambda
walks = generate_random_walks(model_type, starting_probability, c_lambdas, step_count,
repetitions)
probabilities, steps, developments = list_walks2list_lists(walks)

if simulated_property == "probability":
mean = np.mean(probabilities, axis=0)
variance = np.var(probabilities, axis=0)
elif simulated_property == "position":
mean = np.mean(developments, axis=0)
variance = np.var(developments, axis=0)
elif simulated_property == "p_s":
ps_all = []
for observation in range(0, REPETITIONS_OF_WALK_S[0]):
ps_single = []
for walk_step in range(0, step_count + 1):
ps_single.append(
probabilities[observation][walk_step] * developments[observation][walk_step])
ps_all.append(ps_single)
mean = np.mean(ps_all, axis=0)
variance = np.var(ps_all, axis=0)
else:
raise Exception("unexpected property type")
plt.plot(mean, mean_styles[index], label=label)
plt.plot(variance, var_styles[index])
if not two_lambda:
if simulated_property == "probability":
plt.plot(exp_p_t_array(step_count, starting_probability, c_lambda, model_type),
expected_styles[index], linewidth=0.7)
plt.plot(var_p_t_array(step_count, starting_probability, c_lambda, model_type),
expected_styles[index], linewidth=0.7)
mean = np.mean(probabilities, axis=0)
variance = np.var(probabilities, axis=0)
elif simulated_property == "position":
s0 = 0
plt.plot(exp_s_t_array(step_count, starting_probability, c_lambda, s0, model_type),
expected_styles[index], linewidth=0.7)
plt.plot(var_s_t_array(step_count, starting_probability, c_lambda, s0, model_type),
expected_styles[index], linewidth=0.7)
mean = np.mean(developments, axis=0)
variance = np.var(developments, axis=0)
elif simulated_property == "p_s":
s0 = 0
plt.plot(exp_p_s_t_array(step_count, starting_probability, c_lambda, s0, model_type),
expected_styles[index], linewidth=0.7)
plt.legend(loc='best', fontsize='xx-large', markerscale=3)
ps_all = []
for observation in range(0, repetitions):
ps_single = []
for walk_step in range(0, step_count + 1):
ps_single.append(
probabilities[observation][walk_step] * developments[observation][walk_step])
ps_all.append(ps_single)
mean = np.mean(ps_all, axis=0)
variance = np.var(ps_all, axis=0)
else:
raise Exception("unexpected property type")
plt.plot(mean, mean_styles[index], label=label)
plt.plot(variance, var_styles[index])
if not two_lambda:
if simulated_property == "probability":
plt.plot(exp_p_t_array(step_count, starting_probability, c_lambda, model_type),
expected_styles[index], linewidth=0.7)
plt.plot(var_p_t_array(step_count, starting_probability, c_lambda, model_type),
expected_styles[index], linewidth=0.7)
elif simulated_property == "position":
s0 = 0
plt.plot(exp_s_t_array(step_count, starting_probability, c_lambda, s0, model_type),
expected_styles[index], linewidth=0.7)
plt.plot(var_s_t_array(step_count, starting_probability, c_lambda, s0, model_type),
expected_styles[index], linewidth=0.7)
elif simulated_property == "p_s":
s0 = 0
plt.plot(exp_p_s_t_array(step_count, starting_probability, c_lambda, s0, model_type),
expected_styles[index], linewidth=0.7)
plt.legend(loc='best', fontsize='xx-large', markerscale=3)
logger.info(
f"Type: {simulated_property}, model {model_type}, steps {step_count}, reps {repetitions}, p0 {starting_probability}, lambda {c_lambda}")

fig = plt.gcf()
fig.set_size_inches(18.5, 10.5)
fig.show()
fig.savefig(
f'e_{simulated_property}_{REPETITIONS_OF_WALK_S[0]}_walks_{step_count}_steps_type_{model_type}.pdf',
dpi=100)
fig = plt.gcf()
fig.set_size_inches(18.5, 10.5)
fig.show()
fig.savefig(
f'e_{simulated_property}_{repetitions}_walks_{step_count}_steps_type_{model_type}.pdf',
dpi=100)


if __name__ == '__main__':
start_time, logger = create_logger()
main(simulated_property="position")
# main(simulated_property="probability")
main(simulated_property="probability")
# main(simulated_property="p_s")
log_time(start_time, logger)
Loading

0 comments on commit bffd25c

Please sign in to comment.