예제 #1
0
    def update_trials(self, trials):
        count = 0
        for trial in trials:
            if trial["state"] == hyperopt.JOB_STATE_NEW:
                if "submitted" not in trial or not trial["submitted"]:
                    # submit jobs and set status to running
                    hyperparam = self.unwrap_hyperparam(trial["misc"]["vals"])
                    full_path = self.make_full_path(hyperparam)
                    rt.run(self.setting, location=full_path, ids=self.ids,
                           parallelization="condor", force_rerun=False, block=False,
                           **hyperparam)
                    trial["submitted"] = True
                else:
                    count += 1
                #trial["state"] = hyperopt.JOB_STATE_RUNNING

                # elif trial["state"] == hyperopt.JOB_STATE_RUNNING:
                # check if all results files are there and set to ok
                hyperparam = self.unwrap_hyperparam(trial["misc"]["vals"])
                full_path = self.make_full_path(hyperparam)
                finished_ids = rt.get_finished_ids(path=full_path)
                if set(finished_ids).issuperset(set(self.ids)):
                    trial["state"] = hyperopt.JOB_STATE_DONE
                    print trial["tid"], "done"
                    trial["result"] = self.get_results(full_path)
                    print "Parameters", hyperparam
        return count
예제 #2
0
    def update_trials(self, trials):
        count = 0
        for trial in trials:
            if trial["state"] == hyperopt.JOB_STATE_NEW:
                if "submitted" not in trial or not trial["submitted"]:
                    # submit jobs and set status to running
                    hyperparam = self.unwrap_hyperparam(trial["misc"]["vals"])
                    full_path = self.make_full_path(hyperparam)
                    rt.run(self.setting, location=full_path, ids=self.ids,
                           parallelization="condor", force_rerun=False, block=False,
                           **hyperparam)
                    trial["submitted"] = True
                else:
                    count += 1
                #trial["state"] = hyperopt.JOB_STATE_RUNNING

                # elif trial["state"] == hyperopt.JOB_STATE_RUNNING:
                # check if all results files are there and set to ok
                hyperparam = self.unwrap_hyperparam(trial["misc"]["vals"])
                full_path = self.make_full_path(hyperparam)
                finished_ids = rt.get_finished_ids(path=full_path)
                if set(finished_ids).issuperset(set(self.ids)):
                    trial["state"] = hyperopt.JOB_STATE_DONE
                    print trial["tid"], "done"
                    trial["result"] = self.get_results(full_path)
                    print "Parameters", hyperparam
        return count
예제 #3
0
def multiple_parallel_runs(varname, vrange, singlemap="9x9-2Path0.txt"):
    '''Runs 5 seeds of experiment. 
       Results will be saved with special convention (for sake of more than 10 variables)
   '''
    params = rt.default_params()
    params['mapf'] = singlemap
    for i, v in enumerate(vrange):
        params[varname] = v #update hyperparam object
        print params
        print "Running {0}: {1}".format(varname, v)
        run("./TwoPathExperiments/trial_2pathsreward.py", 
            "./TwoPathExperiments/{0}/{1}/{2}".format(varname, singlemap, str('%02d' % i)), 
            ids=range(5), parallelization="joblib", force_rerun=True, **params)
예제 #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 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
        }
예제 #5
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}
예제 #6
0
from rlpy.Tools.run import run
run("examples/tutorial/infTrackCartPole_rbfs.py", "./Results/Tutorial/InfTrackCartPole/RBFs",
    ids=range(10), parallelization="joblib")

run("examples/tutorial/infTrackCartPole_tabular.py", "./Results/Tutorial/InfTrackCartPole/Tabular",
    ids=range(10), parallelization="joblib")
예제 #7
0
from rlpy.Tools.run import run
import rlpy.Tools.results as rt
import os
import sys

if __name__ == '__main__':
    experiment_name = sys.argv[1]

    experiment_dir = os.path.expanduser("~/work/clipper/models/rl/")
    result_dir = "./Results/" + experiment_name + "/"

    run(experiment_dir + experiment_name + "Experiment.py",
        result_dir,
        ids=range(6),
        parallelization="joblib")

    paths = {experiment_name: result_dir}

    merger = rt.MultiExperimentResults(paths)
    fig = merger.plot_avg_sem("learning_steps", "return")
    rt.save_figure(fig, result_dir + "plot.pdf")