Esempio n. 1
0
File: main.py Progetto: 1MahdiR/trt
def main():

    try:
        # storing an object that contains the arguments and the action to performing on them
        args = parse(sys.argv[1:])

        if not args.lan_args:
            if args.action == "HELP":
                meta.help()
                sys.exit(0)

            if args.action == "VERSION":
                meta.version()
                sys.exit(0)

        source_lan = args.lan_args[0][1:]
        target_lan = args.lan_args[1][1:]

        if args.action == "TRANSLATE_CLIPBOARD":
            text = "%0A".join(pype.paste().split("\n"))
            web.open(main_address.format(source_lan, target_lan, text))
            sys.exit(0)

        if args.action == "TRANSLATE_COMMANDLINE":
            arg = args.args_word
            text = "%0A".join(arg)
            web.open(main_address.format(source_lan, target_lan, text))
            sys.exit(0)

        if args.action == "TRANSLATE_INPUT":
            arg = []
            # while there is at least one character in input, keep getting input from user.
            while "" not in arg:
                try:
                    arg.append(input("> "))
                except KeyboardInterrupt:
                    print()
                    sys.exit(0)
            text = "%0A".join(arg)
            web.open(main_address.format(source_lan, target_lan, text))
            sys.exit(0)

    except KeyboardInterrupt:
        print()
    except Exception:
        traceback.print_exc(file=sys.stdout)
    sys.exit(0)
Esempio n. 2
0
def get_config(config):
    names = ['g', 'l', 'r', 's', 'rad', 'b', 'd']

    args = arg_parser.parse(names)

    for arg, value in args.items():
        if arg == 'g' and value is not None:
            config['number_of_reservoirs'] = int(value)
        elif arg == 'l' and value is not None:
            config['overlap_size'] = int(value)
        elif arg == 'r' and value is not None:
            config['reservoir_size'] = int(value)
        elif arg == 's' and value is not None:
            config['sigma'] = float(value)
        elif arg == 'rad' and value is not None:
            config['radius'] = float(value)
        elif arg == 'b' and value is not None:
            config['beta'] = float(value)
        elif arg == 'd' and value is not None:
            config['degree'] = int(value)
    return config
Esempio n. 3
0
def main():
    args = arg_parser.parse()

    if args.debug:
        logging.getLogger().setLevel(logging.INFO)

    if args.question == 1:
        logging.debug('question 1:')
        results = question1(args.prob, args.repetitions)
        for r in results:
            print(r)
    elif args.question == 2:
        logging.debug('question 2')
        results = question2(args.strategy, args.state, args.crowded,
                            args.repetitions)
        for r in results:
            print(f'{r[0]}\t{r[1]}')
    elif args.question == 3:
        logging.debug('question 3')
        ea_obj = ea.EA(args.lambda_, args.h, args.weeks)
        ea_obj.run(args.max_t)
    else:
        logging.error('Invalid question number supplied')
        sys.exit(1)
Esempio n. 4
0
def main():
    args = arg_parser.parse()

    if args.debug:
        logger = logging.getLogger()
        logger.setLevel(logging.DEBUG)

    logging.debug('Question: %s', args.question)

    if args.question == 1:
        logging.debug('question 1:')
        print(question1(args.expr, args.x))
    elif args.question == 2:
        logging.debug('question 2')
        print(question2(args.expr, args.data))
    elif args.question == 3:
        logging.debug('question 3')
        best_ind = question3(args.lambda_, args.data, args.time_budget)
        logging.debug('BEST IND:')
        print(best_ind)
        logging.debug('FITNESS: %s', best_ind.fitness)
    else:
        logging.error('Invalid question number supplied')
        sys.exit(1)
import contextlib
from arg_parser import parse
from pathlib import Path
from continuous_cartpole import ContinuousCartPoleEnv
from reinforce_discrete import REINFORCE
from utils import D2C, Visualizer
from utils import reward_laplacian, reward_carrot_stick, reward_no_fast_rotation
from utils import reward_func_map

if __name__ == '__main__':
    print('--- running main ---')
    args = parse()

    # ============ Parameters ============
    reward_func = reward_func_map[args.reward_function]
    env = ContinuousCartPoleEnv(reward_function=reward_func)
    state_dim = env.observation_space.shape[0]
    action_dim = args.action_dim
    episodes = args.episode
    timesteps = args.steps
    hidden_dim = args.hidden_dim
    policy_lr = args.actor_lr
    baseline_lr = args.critic_lr
    exp_count = args.exp_count
    render_flag = args.render
    load_flag = args.load
    # ====================================

    # --- choose algorithm and hyperparameters ---
    d2c_converter = D2C(action_dim, env.action_space.low,
                        env.action_space.high)
            printDataDeep(compiledata[device]["data"])
            print ""


def printDataDeep(d, indent=0):
    for k in d:
        if isinstance(d[k], dict):
            print(" " * indent) + k
            printDataDeep(d[k], indent + 4)
        else:
            print(" " * indent) + ("%s = %d" % (k, d[k]))


if __name__ == "__main__":

    args = arg_parser.parse()

    if args.action == "install": install(args)
    else:
        config = config_parser.read(args.config_path)

        createlocation([
            config["raw_data_location"],
            os.path.join(config["parsed_data_location"], LOCATION_PARSE),
            os.path.join(config["parsed_data_location"],
                         LOCATION_PARSE_DIVERSITY),
            os.path.join(config["collected_data_location"],
                         LOCATION_COLLECT_STATS),
            os.path.join(config["collected_data_location"],
                         LOCATION_COLLECT_DIVERSITY),
        ])