Ejemplo n.º 1
0
 def get_results(self, path):
     # all jobs should be done
     res = tres.load_results(path)
     mapping = {'max_steps': (-1., 'steps'), 'min_steps': (1., 'steps'),
                'max_reward': (-1., 'return')}
     neg, quan = mapping[self.objective]
     avg, std, n_trials = tres.avg_quantity(res, quan)
     avg *= neg
     weights = (np.arange(len(avg)) + 1) ** 2
     loss = (avg * weights).sum() / weights.sum()
     print time.ctime()
     print "Loss: {:.4g}".format(loss)
     # use #steps/eps at the moment
     return {"loss": loss,
             "num_trials": n_trials[-1],
             "status": hyperopt.STATUS_OK,
             "std_last_mean": std[-1]}
Ejemplo n.º 2
0
 def get_results(self, path):
     # all jobs should be done
     res = tres.load_results(path)
     mapping = {'max_steps': (-1., 'steps'), 'min_steps': (1., 'steps'),
                'max_reward': (-1., 'return')}
     neg, quan = mapping[self.objective]
     avg, std, n_trials = tres.avg_quantity(res, quan)
     avg *= neg
     weights = (np.arange(len(avg)) + 1) ** 2
     loss = (avg * weights).sum() / weights.sum()
     print time.ctime()
     print "Loss: {:.4g}".format(loss)
     # use #steps/eps at the moment
     return {"loss": loss,
             "num_trials": n_trials[-1],
             "status": hyperopt.STATUS_OK,
             "std_last_mean": std[-1]}
Ejemplo n.º 3
0
    def f(hyperparam):
        """function to optimize by hyperopt"""

        # "temporary" directory to use
        full_path = os.path.join(
            path, "-".join([str(v) for v in list(hyperparam.values())]))

        # execute experiment
        rt.run(setting,
               location=full_path,
               ids=list(range(1, trials_per_point + 1)),
               parallelization=parallelization,
               force_rerun=False,
               block=True,
               **hyperparam)

        # all jobs should be done
        res = tres.load_results(full_path)

        if objective == "max_steps":
            m, s, n = tres.avg_quantity(res, "steps")
            val = -m
            std = s[-1]
        elif objective == "min_steps":
            m, s, n = tres.avg_quantity(res, "steps")
            val = m
            std = s[-1]
        elif objective == "max_reward":
            m, s, n = tres.avg_quantity(res, "return")
            val = -m
            std = s[-1]
        else:
            print("unknown objective")
        weights = (np.arange(len(val)) + 1)**2
        loss = old_div((val * weights).sum(), weights.sum())
        print(time.ctime())
        print("Parameters", hyperparam)
        print("Loss", loss)
        # use #steps/eps at the moment
        return {
            "loss": loss,
            "num_trials": n[-1],
            "status": hyperopt.STATUS_OK,
            "std_last_mean": std
        }
Ejemplo n.º 4
0
    def f(hyperparam):
        """function to optimize by hyperopt"""

        # "temporary" directory to use
        full_path = os.path.join(
            path,
            "-".join([str(v) for v in hyperparam.values()]))

        # execute experiment
        rt.run(setting, location=full_path, ids=range(1, trials_per_point + 1),
               parallelization=parallelization, force_rerun=False, block=True, **hyperparam)

        # all jobs should be done
        res = tres.load_results(full_path)

        if objective == "max_steps":
            m, s, n = tres.avg_quantity(res, "steps")
            val = -m
            std = s[-1]
        elif objective == "min_steps":
            m, s, n = tres.avg_quantity(res, "steps")
            val = m
            std = s[-1]
        elif objective == "max_reward":
            m, s, n = tres.avg_quantity(res, "return")
            val = -m
            std = s[-1]
        else:
            print "unknown objective"
        weights = (np.arange(len(val)) + 1) ** 2
        loss = (val * weights).sum() / weights.sum()
        print time.ctime()
        print "Parameters", hyperparam
        print "Loss", loss
        # use #steps/eps at the moment
        return {"loss": loss,
                "num_trials": n[-1],
                "status": hyperopt.STATUS_OK,
                "std_last_mean": std}
Ejemplo n.º 5
0
def variable_MER_AUC(var, mp="9x9-2Path0.txt"):
    #LOAD ALL RESULTS 
    results_agent_eps = get_all_result_paths("./TwoPathExperiments/" + var + "/" + mp + "/")
    ##LOAD AS VALUE -> SEED -> RESULT(dict)
    tempres = dict([(x_to_y[var][int(path[-2:])], load_results(path)) for path in results_agent_eps])

    ##Refactor dictionary into -> SEED -> VALUE -> RESULT(dict)
    seed_based_results = defaultdict(dict)
    for val, total_results in tempres.items():
        for seed, result in total_results.items():
            seed_based_results[seed][val] = result

    seed_based_AUC = defaultdict(dict)
    for seed, val_res in seed_based_results.items():
        for val, result in val_res.items():
            seed_based_AUC[seed][val] = rt.get_AUC(result['return'])

    for i, run in seed_based_AUC.items():
        run_values = sorted(run.items(), key=lambda x: x[0])
        keys, values = zip(*run_values)
        seed_based_AUC[i] = {"Values": list(keys), "AUCS": list(values)}

    return seed_based_AUC