def generatePlot(exp_paths): ax = plt.gca() # ax.semilogx() for exp_path in exp_paths: exp = loadExperiment(exp_path) results = loadResults(exp, 'rmspbe_summary.npy') use_ideal_h = exp._d['metaParameters'].get('use_ideal_h', False) dashed = use_ideal_h label = exp.agent if use_ideal_h: label += '-h*' if use_ideal_h: continue if 'SmoothTDC' in exp.agent: agents = splitOverParameter(results, 'averageType') smooth_colors = { 'ema': 'pink', 'buffer': 'grey', 'window': 'black', } plot(agents['ema'], ax, label=label + '_ema', bestBy='auc', color=smooth_colors['ema'], dashed=dashed) # plot(agents['buffer'], ax, label=label + '_buffer', bestBy='auc', color=smooth_colors['buffer'], dashed=dashed) # plot(agents['window'], ax, label=label + '_window', bestBy='auc', color=smooth_colors['window'], dashed=dashed) else: color = colors[exp.agent] plot(results, ax, label=label, bestBy='auc', color=color, dashed=dashed) plt.show() exit() # save(exp, f'rmspbe', type='png') problem = fileName(exp.getExperimentName()) save_path = f'plots/' os.makedirs(save_path, exist_ok=True) fig = plt.gcf() fig.set_size_inches((13, 12), forward=False) plt.savefig(f'{save_path}/{problem}_rmspbe.png')
def generatePlot(exp_paths): ax = plt.gca() # ax.semilogx() for exp_path in exp_paths: exp = loadExperiment(exp_path) # load the errors and hnorm files errors = loadResults(exp, 'errors_summary.npy') results = loadResults(exp, 'hnorm_summary.npy') # choose the best parameters from the _errors_ best = getBestEnd(errors) best_hnorm = find(results, best) label = fileName(exp_path).replace('.json', '') plotBest(best_hnorm, ax, label=label) plt.show() # save(exp, f'learning-curve') plt.clf()
import sys import json import glob import os sys.path.append(os.getcwd()) from src.utils.path import fileName, up old_agent_path = sys.argv[1] problems = sys.argv[2:] problems = filter( lambda p: '.' not in p and 'plots' not in p and 'LeftZero' not in p and 'Random' not in p and '5050' not in p, problems) with open(old_agent_path, 'r') as f: old_agent = f.read() old_agent_base_name = fileName(up(old_agent_path)) old_agent_name = fileName(old_agent_path).replace('.json', '') old_problem = fileName(up(up(old_agent_path))) for problem in problems: path = f'{problem}/{old_agent_base_name}/{old_agent_name}.json' new = old_agent.replace(old_problem, fileName(problem)) os.makedirs(up(path), exist_ok=True) with open(path, 'w') as f: f.write(new)
import os import sys import json import numpy as np sys.path.append(os.getcwd()) from src.analysis.results import loadResults, getBest from src.utils.model import loadExperiment from src.utils.path import up, fileName exp_paths = sys.argv[1:] for exp_path in exp_paths: exp = loadExperiment(exp_path) results = loadResults(exp, 'rmspbe_summary.npy') best = getBest(results) print('---------------------') print('agent:', exp.agent) print(best.params) f = fileName(exp_path) new_path = up(exp_path) + '/best_rmspbe_auc/' + f d = exp._d d['metaParameters'] = best.params os.makedirs(up(new_path), exist_ok=True) with open(new_path, 'w') as f: json.dump(d, f, indent=4)
import sys import json import glob import os sys.path.append(os.getcwd()) from src.utils.path import fileName, up prob_folder = sys.argv[1] new_prob = sys.argv[2] jsons = glob.glob(f'{prob_folder}/**/*.json', recursive=True) old_prob = fileName(prob_folder) for json in jsons: with open(json, 'r') as f: d = f.read() new = d.replace(old_prob, new_prob) new_path = json.replace(old_prob, new_prob) os.makedirs(up(new_path), exist_ok=True) with open(new_path, 'w') as f: f.write(new)
if 'lstd' in exp_path or 'htd' in exp_path or ( 'tdc_ema' in exp_path and not 'tdc_ema_x' in exp_path): continue if stepsize != 'constant' and stepsize not in exp_path: continue if stepsize == 'constant' and ('amsgrad' in exp_path or 'adagrad' in exp_path or 'schedule' in exp_path): continue exp = loadExperiment(exp_path) use_ideal_h = exp._d['metaParameters'].get('use_ideal_h', False) if use_ideal_h: continue paths.append(exp_path) generatePlot(paths) plt.show() exit() exp_name = fileName(up(exp.getExperimentName())) save_path = f'experiments/stepsizes/plots/2x2/{bestBy}' os.makedirs(save_path, exist_ok=True) fig = plt.gcf() fig.set_size_inches((13, 12), forward=False) plt.savefig(f'{save_path}/{exp_name}_square_{stepsize}.png', dpi=125)