: 학습은 인공지능에서 가장 기본적인 요소로 기계가 스스로 학습할 수 있도록 기계에게 학습 방법을 가르치는 것을 의미한다. 강화 학습은 주어진 상황에 대해 취할 행동을 보상으로 극대화하는 방향으로 결정하는 방법을 학습한다. 강화학습이 다른 학습과 뚜렷이 구분되는 대표적인 특징은 시행 착오 학습과 지연 보상이다.
: 지도학습은 별도로 제공된 레이블이 달린 샘플을 통해 학습한다. 그렇기 때문에 사전에 주어진 학습용 샘플 데이터가 없는 처음 마주하는 문제를 해결할 때 지도 학습 기법을 적용할 수 없다. 강화학습은 바로 이러한 종류의 문제에서 힘을 발휘한다.
강화 학습은 좀 더 주변 상황을 탐색하고 행동해야 하는가, 아니면 제한된 경험만을 가지고 학습해야 하는가, 즉 탐색과 이용의 상충관계에 대한 연구가 필요하다.
--> 공통적인 특징이 있따. 환경과 상호작용하며, 학습 에이전트는 환경에 대한 불확실성이 어느 정도 있더라도 주어진 목적을 달성하기 위해 노력한다. 나중에 환경이 달라진다면 에이전트가 취하는 행동 또한 달라질 것이다.

$ pip3 install gym
import argparse
import gym
def build_arg_parser():
parser = argparse.ArgumentParser(description='Run an environment')
parser.add_argument('--input-env', dest='input_env', required=True,
choices=['cartpole', 'mountaincar', 'pendulum', 'taxi', 'lake'],
help='Specify the name of the environment')
return parser
if __name__=='__main__':
args = build_arg_parser().parse_args()
input_env = args.input_env
name_map = {'cartpole': 'CartPole-v0',
'mountaincar': 'MountainCar-v0',
'pendulum': 'Pendulum-v0',
'taxi': 'Taxi-v1',
'lake': 'FrozenLake-v0'}
# Create the environment and reset it
env = gym.make(name_map[input_env])
env.reset()
# Iterate 1000 times
for _ in range(1000):
# Render the environment
env.render()
# take a random action
env.step(env.action_space.sample())
import argparse
import gym
def build_arg_parser():
parser = argparse.ArgumentParser(description='Run an environment')
parser.add_argument('--input-env', dest='input_env', required=True,
choices=['cartpole', 'mountaincar', 'pendulum'],
help='Specify the name of the environment')
return parser
if __name__=='__main__':
args = build_arg_parser().parse_args()
input_env = args.input_env
name_map = {'cartpole': 'CartPole-v0',
'mountaincar': 'MountainCar-v0',
'pendulum': 'Pendulum-v0'}
# Create the environment
env = gym.make(name_map[input_env])
# Start iterating
for _ in range(20):
# Reset the environment
observation = env.reset()
# Iterate 100 times
for i in range(100):
# Render the environment
env.render()
# Print the current observation
print(observation)
# Take action
action = env.action_space.sample()
# Extract the observation, reward, status and
# other info based on the action taken
observation, reward, done, info = env.step(action)
# Check if it's done
if done:
print('Episode finished after {} timesteps'.format(i+1))
break