コード例 #1
0
def main(job_id, params):
    print "Anything printed here will end up in the output directory for job #:", str(job_id)
    parameters = {}
    for key in params:
        if isinstance(key, unicode):
            parameters[key.encode("utf-8")] = params[key]
    else:
        parameters[key] = params[key]

    for key in parameters:
        parameters[key] = map(lambda k: k.encode("utf-8") if isinstance(k, unicode) else k, parameters[key])
        if len(parameters[key]) == 1:
            value = parameters[key][0]
            try:
                value = float(value)
            except:
                if value.lower() == "false":
                    value = False
                elif value.lower() == "true":
                    value = True

            parameters[key] = value
    print parameters

    my_path = os.path.dirname(os.path.abspath(__file__))
    tmp_file = os.path.join(my_path, "rndtrial" + str(numpy.random.randint(1.0e10)) + ".dat")
    my_path = os.path.abspath(os.path.join(my_path, "experiment.json"))
    agent, a_args, env, env_args, exp, exp_args = fromjson(my_path)

    for key in parameters:
        a_args.setdefault(key, parameters[key])

    config = {
        "agent": {"name": agent.name, "params": a_args},
        "environment": {"name": env.name, "params": env_args},
        "experiment": {"name": exp.name, "params": exp_args},
    }

    experiment = Episodic(config, agent=agent(**a_args), environment=env(**env_args), **exp_args)

    # Using this try/except makes debugging in spearmint 1mil times easier
    try:
        experiment.run_experiment(filename=tmp_file)
    except Exception as ex:
        import traceback

        traceback.print_exc()

    locs, means, std = plotExperiment.processFile(tmp_file, "reward", verbose=False, method="sum")
    os.remove(tmp_file)
    print "Result:", -means[0]
    return -means[0]
コード例 #2
0
ファイル: spearmint_config.py プロジェクト: AAHays/python-rl
        elif param.choices.__class__ is ValueRange:
            config_contents += gen_numeric_pbvar(param.dest, var_size, param.type,
                param.choices.min(), param.choices.max())
        else:
            config_contents += gen_enum_pbvar(param.dest, var_size, param.choices)

    return config_contents

if __name__ == "__main__":
    from pyrl.agents import *
    from pyrl.rlglue.registry import rlglue_registry
    from pyrl.rlglue import run

    agent_name = sys.argv[1]
    agent = rlglue_registry.agents[agent_name]
    param_parser = agent.agent_parameters()
    fixed_params = run.fromjson(sys.argv[2])[1] # Grabs agent parameters from experiment file

    # Produce a config.pb file based upon parameter parser
    config_contents = gen_config(agent_name, param_parser, fixed_params)
    for line in config_contents:
        print line








コード例 #3
0
def main(job_id, params):
    print 'Anything printed here will end up in the output directory for job #:', str(
        job_id)
    parameters = {}
    for key in params:
        if isinstance(key, unicode):
            parameters[key.encode('utf-8')] = params[key]
    else:
        parameters[key] = params[key]

    for key in parameters:
        parameters[key] = map(
            lambda k: k.encode('utf-8')
            if isinstance(k, unicode) else k, parameters[key])
        if len(parameters[key]) == 1:
            value = parameters[key][0]
            try:
                value = float(value)
            except:
                if value.lower() == "false":
                    value = False
                elif value.lower() == "true":
                    value = True

            parameters[key] = value
    print parameters

    my_path = os.path.dirname(os.path.abspath(__file__))
    tmp_file = os.path.join(
        my_path, "rndtrial" + str(numpy.random.randint(1.e10)) + ".dat")
    my_path = os.path.abspath(os.path.join(my_path, "experiment.json"))
    agent, a_args, env, env_args, exp, exp_args = fromjson(my_path)

    for key in parameters:
        a_args.setdefault(key, parameters[key])

    config = {
        'agent': {
            'name': agent.name,
            'params': a_args
        },
        'environment': {
            'name': env.name,
            'params': env_args
        },
        'experiment': {
            'name': exp.name,
            'params': exp_args
        }
    }

    experiment = Episodic(config,
                          agent=agent(**a_args),
                          environment=env(**env_args),
                          **exp_args)

    # Using this try/except makes debugging in spearmint 1mil times easier
    try:
        experiment.run_experiment(filename=tmp_file)
    except Exception as ex:
        import traceback
        traceback.print_exc()

    locs, means, std = plotExperiment.processFile(tmp_file,
                                                  "reward",
                                                  verbose=False,
                                                  method="sum")
    os.remove(tmp_file)
    print "Result:", -means[0]
    return -means[0]