Python environment.Environment() Examples
The following are 5
code examples of environment.Environment().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
environment
, or try the search function
.
Example #1
Source File: demo.py From simdem with MIT License | 5 votes |
def __init__(self, is_running_in_docker, script_dir="demo_scripts", filename="README.md", is_simulation=True, is_automated=False, is_testing=False, is_fast_fail=True,is_learning = False, parent_script_dir = None, is_prep_only = False, is_prerequisite = False, output_format="log"): """ is_running_in_docker should be set to true is we are running inside a Docker container script_dir is the location to look for scripts filename is the filename of the script this demo represents is_simulation should be set to true if we want to simulate a human running the commands is_automated should be set to true if we don't want to wait for an operator to indicate it's time to execute the next command is_testing is set to true if we want to compare actual results with expected results, by default execution will stop if any test fails (see is_fast_fail) is_fast_fail should be set to true if we want to contnue running tests even after a failure is_learning should be set to true if we want a human to type in the commands parent_script_dir should be the directory of the script that calls this one, or None if this is the root script is_prep_only should be set to true if we want to stop execution after all prerequisites are satsified is_prerequisite indicates whether this is a prerequisite or not. It is used to decide behaviour with respect to simulation etc. """ self.mode = None self.is_docker = is_running_in_docker self.filename = filename self.script_dir = "" self.set_script_dir(script_dir) self.is_simulation = is_simulation self.is_automated = is_automated self.is_testing = is_testing self.is_fast_fail = is_fast_fail self.is_learning = is_learning self.current_command = "" self.current_description = "" self.last_command = "" self.is_prep_only = is_prep_only self.parent_script_dir = parent_script_dir if self.parent_script_dir: self.env = Environment(self.parent_script_dir, is_test = self.is_testing) else: self.env = Environment(self.script_dir, is_test = self.is_testing) self.is_prerequisite = is_prerequisite self.output_format = output_format self.all_results = [] self.completed_validation_steps = []
Example #2
Source File: main.py From simdem with MIT License | 5 votes |
def get_bash_script(script_dir, is_simulation = True, is_automated=False, is_testing=False): """ Reads a README.md file in the indicated directoy and builds an executable bash script from the commands contained within. """ if not script_dir.endswith('/'): script_dir = script_dir + "/" script = "" env = Environment(script_dir, False).get() for key, value in env.items(): script += key + "='" + value + "'\n" filename = env.get_script_file_name(script_dir) in_code_block = False in_results_section = False lines = list(open(script_dir + filename)) for line in lines: if line.startswith("Results:"): # Entering results section in_results_section = True elif line.startswith("```") and not in_code_block: # Entering a code block, if in_results_section = True then it's a results block in_code_block = True elif line.startswith("```") and in_code_block: # Finishing code block in_results_section = False in_code_block = False elif in_code_block and not in_results_section: # Executable line script += line elif line.startswith("#") and not in_code_block and not in_results_section and not is_automated: # Heading in descriptive text script += "\n" return script
Example #3
Source File: main.py From Policy-Gradient-and-Actor-Critic-Keras with MIT License | 5 votes |
def run(args): if args.train_pg: env_name = args.env_name or 'Pong-v0' env = Environment(env_name, args) from agent_dir.agent_pg import Agent_PG agent = Agent_PG(env, args) agent.train() if args.test_pg: env = Environment('Pong-v0', args, test=True) from agent_dir.agent_pg import Agent_PG agent = Agent_PG(env, args) test(agent, env) # Experiment on Cartpole only, test unsupported if args.train_ac: env_name = args.env_name or 'CartPole-v0' env = Environment(env_name, args) from agent_dir.agent_actorcritic import Agent_ActorCritic agent = Agent_ActorCritic(env, args) agent.train() if args.train_pgc: env_name = args.env_name or 'CartPole-v0' env = Environment(env_name, args) from agent_dir.agent_pg_cart import Agent_PGC agent = Agent_PGC(env, args) agent.train()
Example #4
Source File: test.py From Policy-Gradient-and-Actor-Critic-Keras with MIT License | 5 votes |
def run(args): if args.test_pg: env = Environment('Pong-v0', args, test=True) from agent_dir.agent_pg import Agent_PG agent = Agent_PG(env, args) test(agent, env)
Example #5
Source File: learners.py From rltrader with MIT License | 4 votes |
def __init__(self, rl_method='rl', stock_code=None, chart_data=None, training_data=None, min_trading_unit=1, max_trading_unit=2, delayed_reward_threshold=.05, net='dnn', num_steps=1, lr=0.001, value_network=None, policy_network=None, output_path='', reuse_models=True): # 인자 확인 assert min_trading_unit > 0 assert max_trading_unit > 0 assert max_trading_unit >= min_trading_unit assert num_steps > 0 assert lr > 0 # 강화학습 기법 설정 self.rl_method = rl_method # 환경 설정 self.stock_code = stock_code self.chart_data = chart_data self.environment = Environment(chart_data) # 에이전트 설정 self.agent = Agent(self.environment, min_trading_unit=min_trading_unit, max_trading_unit=max_trading_unit, delayed_reward_threshold=delayed_reward_threshold) # 학습 데이터 self.training_data = training_data self.sample = None self.training_data_idx = -1 # 벡터 크기 = 학습 데이터 벡터 크기 + 에이전트 상태 크기 self.num_features = self.agent.STATE_DIM if self.training_data is not None: self.num_features += self.training_data.shape[1] # 신경망 설정 self.net = net self.num_steps = num_steps self.lr = lr self.value_network = value_network self.policy_network = policy_network self.reuse_models = reuse_models # 가시화 모듈 self.visualizer = Visualizer() # 메모리 self.memory_sample = [] self.memory_action = [] self.memory_reward = [] self.memory_value = [] self.memory_policy = [] self.memory_pv = [] self.memory_num_stocks = [] self.memory_exp_idx = [] self.memory_learning_idx = [] # 에포크 관련 정보 self.loss = 0. self.itr_cnt = 0 self.exploration_cnt = 0 self.batch_size = 0 self.learning_cnt = 0 # 로그 등 출력 경로 self.output_path = output_path