from utils.DataSaver import DataSaver from utils.draw import draw_participant_and_simulation import numpy as np import matplotlib.pyplot as plt participant_analysis_data = DataSaver.load_from_file("analysis_result.pkl") model_names = ["MF", "MB", "MF_no_reinit", "MF_attention" ] # could be "MF", "MB", "MF_no_reinit", "MF_attention" model_number = len(model_names) simulate_analysis_data = {} for name in model_names: simulate_analysis_data[name] = [] NUMBER_OF_REPEAT = 50 for i in range(NUMBER_OF_REPEAT): for name in model_names: analysis_result = DataSaver.load_from_file( "simulate_analysis_result/" + name + "_simulate_analysis_result" + str(i) + ".pkl") simulate_analysis_data[name].append(analysis_result) def draw(metric, method, simulate_data, participant_data, randomized): draw_participant_and_simulation( participant_data, simulate_data, metric, title=metric + "_in_" + method + "_method_" +
import matplotlib.pyplot as plt model_names = ["MF_attention" ] # could be "MF", "MB", "MF_no_reinit", "MF_attention" randomized = True model_number = len(model_names) simulate_analysis_data = {} for name in model_names: simulate_analysis_data[name] = [] NUMBER_OF_REPEAT = 50 for i in range(NUMBER_OF_REPEAT): for name in model_names: analysis_result = DataSaver.load_from_file( "simulate_analysis_result_all_" + ("randomized" if randomized else "block") + "/" + name + "_simulate_analysis_result" + str(i) + ".pkl") simulate_analysis_data[name].append(analysis_result) def draw(metric, method, simulate_data_even, simulate_data_odd): draw_even_odd_simulation( simulate_data_even, simulate_data_odd, metric, title=metric + "_in_" + method + "_method_" + ("randomized" if randomized else "block") + "_even_odd_comparison", save_path="participant_simulation_comparison_even_odd/", save=True, show=True, smooth=False)
from utils.DataSaver import DataSaver import numpy as np import matplotlib.pyplot as plt participant_analysis_data = DataSaver.load_from_file("analysis_result.pkl") step_data = participant_analysis_data.get_data("step") mean = np.mean(step_data, axis=1) sum = np.sum(step_data, axis=1) plt.hist(mean) plt.show() plt.hist(sum) plt.show() for i in range(36): if sum[i] > 1324: print(i)
import json import os import numpy as np import pandas from data_analysis.analysis_optimal import optimal_probability from utils.DataSaver import DataSaver if __name__ == "__main__": NUMBER_OF_PARTICIPANT = 36 TRIAL_LENGTH = 144 NEED_UPDATE_DATA_FRAME = False saver = DataSaver([ "step", "time", "normalized_time", "optimal", "optimal_inner", "optimal_outer", "optimal_last" ], NUMBER_OF_PARTICIPANT, TRIAL_LENGTH) all_data = [[] for _ in range(NUMBER_OF_PARTICIPANT)] optimal_data_frame = pandas.DataFrame(columns=[ "step", "reaction_time", "normalized_reaction_time", "optimal_p", "optimal_inner", "optimal_outer", "optimal_last", "timestep", "block", "condition", "participant" ]) for lists in os.listdir("data/"): path = os.path.join("data/", lists) print("Loading ", path) split = lists.split("_") participant_id = int(split[0]) rawFile = open(path, "r")
from utils.DataSaver import DataSaver from utils.draw import draw_participant_and_simulation import matplotlib.pyplot as plt participant_analysis_data = DataSaver.load_from_file("analysis_result.pkl") simulate_analysis_data = { "MF": DataSaver.load_from_file("MF_simulate_analysis_result.pkl"), "MB": DataSaver.load_from_file("MB_simulate_analysis_result.pkl") } def draw(metric, method, randomized=True): if randomized: draw_participant_and_simulation( participant_analysis_data.get_data(metric)[::2, :], simulate_analysis_data[method].get_data(metric)[::2, :], metric, title=metric + "_in_" + method + "_method_randomized_condition", save_path="participant_simulation_comparison_all/", save=False, show=False) else: draw_participant_and_simulation( participant_analysis_data.get_data(metric)[1::2, :], simulate_analysis_data[method].get_data(metric)[1::2, :], metric, title=metric + "_in_" + method + "_method_block_condition", save_path="participant_simulation_comparison_all/", save=False, show=False)
from utils.DataSaver import DataSaver from data_analysis.analysis_optimal import optimal_probability MODEL_NAME = "MF_attention" f = open(MODEL_NAME + "_fit_result.csv", "r") fit_result = csv.DictReader(f) NUMBER_OF_PARTICIPANT = 36 TRIAL_LENGTH = 144 NUMBER_OF_REPEAT = 50 savers = [] for _ in range(NUMBER_OF_REPEAT): savers.append( DataSaver( ["optimal", "optimal_inner", "optimal_outer", "optimal_last"], NUMBER_OF_PARTICIPANT, TRIAL_LENGTH)) for participant_param in fit_result: participant_id = int(participant_param["participant"]) # Use the fitted model to simulate BASE_PATH = "simulate_data/%s/%02d/" % (MODEL_NAME, participant_id) # simulate_MF(randomized=participant_id % 2 == 0, # alpha=float(participant_param["alpha"]), # tau=float(participant_param["tau"]), # repeat=NUMBER_OF_REPEAT, # gamma=float(participant_param["gamma"]), # forget=float(participant_param["forget_MF"]), # path=BASE_PATH, # seed=participant_id) # simulate_MB(randomized=participant_id % 2 == 0,
def save_results_to_csv(results): saver = DataSaver(results_dir=RESULTS_DIR, results_ext=RESULTS_EXT) saver.save(result=results, filename=RESULTS_FILENAME)
from utils.DataSaver import DataSaver def transform_and_plot(data, data_name): randomized_data = data[::2, :] draw_metrics(randomized_data, data_name, "%s under %s condition in participants" % (data_name, "randomized"), # extra_data_names=["MF_randomized", "optimal_randomized", "random_randomized", "MB_randomized"], smooth=True, save_npy=False, draw_individual=True, annotate_block_mean=False) block_data = data[1::2, :] draw_metrics(block_data, data_name, "%s under %s condition in participants" % (data_name, "block"), # extra_data_names=["MF_block", "optimal_block", "random_block", "MB_block"], smooth=True, save_npy=False, draw_individual=True, annotate_block_mean=False) if __name__ == "__main__": saver = DataSaver.load_from_file("analysis_result.pkl") for metric in saver.data_names: transform_and_plot(saver.get_data(metric), metric)