Esempio n. 1
0
    time_of_start = time.time()
    # set the title of the terminal so that what the terminal is doing is clear
    print('\33]0;{}\a'.format(' '.join(sys.argv)), end='', flush=True)
    print(args)

    # compile the simulation module in C
    check_C_module_and_compile()

    # set the replay memory
    capacity = round(args.size_of_replay_memory * controls_per_half_period *
                     t_max) if args.train else 1
    memory = RL.Memory(capacity = capacity, data_size = data_size * 2 + 2 if args.input != 'measurements' else \
                                            (read_control_step_length+read_length) + read_length//read_control_step_length+1 + 2,
                                            policy = 'random', passes_before_random = 0.2)
    # define the neural network
    net = RL.direct_DQN(data_size).cuda(
    ) if args.input != 'measurements' else RL.DQN_measurement(read_length)
    # set the task
    if args.train or args.LQG:
        train = RL.TrainDQN(net,
                            memory,
                            batch_size=args.batch_size,
                            gamma=0.99,
                            backup_period=args.target_network_update_interval,
                            args=args)
        del net
        # the main function of training
        if args.train:
            main = Main_System(train, num_of_processes=args.num_of_actors)
            main(num_of_episodes)
        # when we do not train and we test the result of LQG
        elif args.LQG:
    # set the title of the terminal so that what the terminal is doing is clear
    print('\33]0;{}\a'.format(' '.join(sys.argv)), end='', flush=True)
    print(args)

    # compile the simulation module in C
    check_C_module_and_compile()

    # set the replay memory
    capacity = round(args.size_of_replay_memory * controls_per_unit_time *
                     t_max) if args.train else 1
    memory = RL.Memory(capacity=capacity,
                       data_size=data_size * 2 + 2,
                       policy='random',
                       passes_before_random=0.2)
    # define the neural network
    net = RL.direct_DQN(data_size).cuda()
    # set the task
    if args.train or args.control_strategy != 'DQN':
        train = RL.TrainDQN(net,
                            memory,
                            batch_size=args.batch_size,
                            gamma=0.99,
                            backup_period=args.target_network_update_interval,
                            args=args)
        del net
        # the main function of training
        if args.train:
            main = Main_System(train, num_of_processes=args.num_of_actors)
            main(num_of_episodes)
        # when we do not train and we test the result of analytic strategies
        elif args.control_strategy != 'DQN':