num=20, base=2).astype('int') for start, end in _budgets ] results = [] original_results = [] print(ss) for s, budgets in zip(ss, _budgets): s_results = [] for budget in budgets: filename = 'data/HooVer_%s_nqueries_regret_budget%d_s%lf_exp%d.pklz' % ( model, budget, s, exp_id) os.system( 'cd ../; python3 check.py --nRuns 1 --sigma 1e-5 --model %s --args %lf --budget %d --output %s --seed %d' % (model, s, budget, filename, exp_id * 1024)) nimc = models.__dict__[model](s=s) initial_states = loadpklz('../' + filename)['optimal_xs'][0] original_results.append( loadpklz('../' + filename)['optimal_values'][0]) result = nimc.get_prob(initial_states) s_results.append(result) results.append(s_results) savepklz( { 'results': results, 'ss': ss, 'budgets': _budgets, 'original_results': original_results }, '../data/HooVer_%s_nqueries_regret_exp%d.pklz' % (model, exp_id)) # from IPython import embed; embed()
from utils.general_utils import loadpklz, savepklz # ----------------------------------------------------------------------------- model = 'Slplatoon' if __name__ == '__main__': budget = 800000 outputs = [] bss = [10, 20, 50, 100, 400, 1600, 6400, 25600] for exp_id in range(1, 10): outputs.append([]) for bs in bss: filename = 'data/HooVer_%s_budget%d_bs%d_exp%d.pklz' % ( model, budget, bs, exp_id) outputs[-1].append(loadpklz('../' + filename)) depth = [[o['depths'][0] for o in exp] for exp in outputs] mem = [[o['memory_usages'][0] for o in exp] for exp in outputs] time = [[o['running_times'][0] for o in exp] for exp in outputs] num_nodes = [[o['num_nodes'][0] for o in exp] for exp in outputs] depth = np.array(depth).mean(axis=0) mem = np.array(mem).mean(axis=0) time = np.array(time).mean(axis=0) num_nodes = np.array(num_nodes).mean(axis=0) results_ho = [] for exp_id in range(1, 10): results_ho.append( loadpklz('../data/HooVer_%s_bs_exp%d.pklz' %
plt.rc('ytick', labelsize=15) # fontsize of the tick labels plt.rc('legend', fontsize=20) # legend fontsize plt.rc('figure', titlesize=BIGGER_SIZE) # fontsize of the figure title plt.rc('axes', axisbelow=True) left = 0.17 # the left side of the subplots of the figure right = 0.98 # the right side of the subplots of the figure bottom = 0.17 # the bottom of the subplots of the figure top = 0.98 # the top of the subplots of the figure model = 'ConceptualModel' if __name__ == '__main__': labels = ['s=0.1', 's=0.01', 's=0.001', 's=0.0003'] exps_ho = [ loadpklz('../data/HooVer_%s_nqueries_regret_exp%d.pklz' % (model, exp_id)) for exp_id in range(1, 11) ] ss = exps_ho[0]['ss'] budgets_ho = exps_ho[0]['budgets'] results_ho = [ np.stack([exp['results'][ids] for exp in exps_ho]).mean(axis=0) for ids in range(len(ss)) ] exps_pl = [ loadpklz('../data/PlasmaLab_%s_nqueries_regret_exp%d.pklz' % (model, exp_id)) for exp_id in range(1, 11) ] ss = exps_pl[0]['ss'] budgets_pl = exps_pl[0]['budgets'] results_pl = [
import models # ----------------------------------------------------------------------------- model = 'Mlplatoon' exp_id = int(sys.argv[1]) if __name__ == '__main__': budgets = np.logspace(np.log(0.85 * 1e5)/np.log(2), np.log(8e5)/np.log(2), num=6, base=2).astype('int')[:-1] outputs = [] print('budgets: ' + str(budgets)) # run an experiment for each budget configuration for budget in budgets: filename = 'data/HooVer_%s_budget%d_exp%d.pklz'%(model, budget, exp_id) os.system('cd ../; python3 check.py --nRuns 1 --sigma 1e-5 --model %s --budget %d --output %s --seed %d'%(model, budget, filename, exp_id*1024)) outputs.append(loadpklz('../'+filename)) results = [] optimal_xs = [o['optimal_xs'][0] for o in outputs] original_results = [o['optimal_values'][0] for o in outputs] num_queries = [o['budget'] for o in outputs] # Monte-Carlo estimation of the hitting probability (using 250k simulations) nimc = models.__dict__[model]() for initial_states in optimal_xs: initial_states = initial_states.tolist() np.random.seed(1024) result = evaluate_single_state(nimc, initial_states, nimc.k, mult=250000) results.append(result) print(result)
### enumerate all mu def func(arg): context = arg[1:] arm = arg[0] reward = [] np.random.seed(1024) mult = 30000 for _ in range(mult): reward.append(cmab.play_context(arm, context)) return np.mean(reward) if os.path.exists('oracle.pklz'): data = loadpklz('oracle.pklz') args = data['args'] mu = data['mu'] else: args = np.meshgrid(range(cmab.nArms), range(cmab.nZ), range(cmab.nU)) args = np.stack([arg.reshape(-1) for arg in args]).T args = [args[i] for i in range(args.shape[0])] with Pool(processes=25) as pool: mu = list(tqdm.tqdm(pool.imap(func, args), total=len(args))) savepklz({'mu': mu, 'args': args}, 'oracle.pklz') # import ipdb; ipdb.set_trace() # func(args[0]) args = np.stack(args)
left = 0.17 # the left side of the subplots of the figure right = 0.98 # the right side of the subplots of the figure bottom = 0.17 # the bottom of the subplots of the figure top = 0.98 # the top of the subplots of the figure # ----------------------------------------------------------------------------- model = 'Slplatoon' if __name__ == '__main__': budgets = np.logspace(np.log(0.85 * 1e5)/np.log(2), np.log(8e5)/np.log(2), num=6, base=2).astype('int') outputs = [] num_nodes = [] # bss = [1, 10, 20, 50, 80, 100, 200, 400, 800] bss = [10, 20, 50, 80, 100, 200, 400, 800] exps = [loadpklz('../data/HooVer_%s_nqueries_regret_bs_exp%d.pklz'%(model, exp_id)) for exp_id in range(1, 11)] data = np.zeros((len(bss), len(budgets), len(exps))) budgets = budgets / 1e5 for budget in range(len(budgets)): for bs in range(len(bss)): for exp_id in range(1, 11): data[bs, budget, exp_id-1] = exps[exp_id-1]['results'][budget*len(bss)+bs] for ibs, bs in enumerate(bss): plt.plot(budgets, 1-data.mean(axis=2)[ibs, :], 'o-', label='bs=%d'%bs) plt.text(budgets[0], 1-data.mean(axis=2)[ibs, :][0], 'bs=%d'%bs) plt.text(budgets[-1], 1-data.mean(axis=2)[ibs, :][-1], 'bs=%d'%bs) plt.xlabel('#queries (x $10^5$)') plt.ylabel('regret')
'$\mathsf{SLplatoon}(d=4, k=11)$', '$\mathsf{MLplatoon}(d=8, k=9)$', '$\mathsf{DetectBrake}(d=4 , k=10)$', '$\mathsf{Merging}(d=4, k=10)$', '$\mathsf{MLplatoon}(d=9, k=9)$' ] models = [ models[int(sys.argv[1]) - 1], ] for model in models: results_pl = [] num_queries_pl = [] results_ho = [] num_queries_ho = [] for exp_id in range(1, 10): results_pl.append( loadpklz('../data/PlasmaLab_%s_exp%d.pklz' % (model, exp_id))['results']) num_queries_pl.append( loadpklz('../data/PlasmaLab_%s_exp%d.pklz' % (model, exp_id))['num_queries']) results_ho.append( loadpklz('../data/HooVer_%s_exp%d.pklz' % (model, exp_id))['results']) num_queries_ho.append( loadpklz('../data/HooVer_%s_exp%d.pklz' % (model, exp_id))['num_queries']) results_pl = np.array(results_pl) num_queries_pl = np.array(num_queries_pl) / 1e5 results_ho = np.array(results_ho) num_queries_ho = np.array(num_queries_ho) / 1e5