Reinforcement Learning คืออะไร ?
Reinforcement Learning หรือ การเรียนรู้แบบเสริมกำลัง เป็นทฤษฎีการเรียนรู้อีกแบบหนึ่ง โดยอนุญาตให้ agent สามารถเรียนรู้กลยุทธ์เพื่อเพิ่มจำนวนผลลัพธ์ที่สะสม (delayed) จากรางวัลที่กำหนดไว้ใน environement (ตัวอย่างเช่น วิดีโอเกม)
รูปแบบที่นิยมใช้งาน คือ Q-learning , MDP และอื่น ๆ เป็นต้น
ตัวอย่างของ Reinforcement Learning
- AlphaGo ที่สามารถเล่นเกม Go แข่งกับ Lee Sedol ชนะ - https://deepmind.com/alpha-go
ผมอาจอธิบายไม่ละเอียดในส่วนนี้ เพราะ มีคนที่อธิบายเรื่องนี้ได้ดีกว่าผมครับ
อ่านเพิ่มเติมได้ที่ Reinforcement Learning และตัวอย่างพื้น ๆ - https://goo.gl/v0F6Ul
Reinforcement Learning กับภาษา Python
โมดูลภาษา Python ในงานด้าน Reinforcement Learning มีอยู่มากมายดังนี้
- PyBrain - Machine Learning Library http://pybrain.org/
- pymdptoolbox - Markov Decision Process (MDP) Toolbox https://github.com/sawcordwell/pymdptoolbox
- DeeR - python library for Deep Reinforcement https://github.com/VinF/deer
- Modular toolkit for Data Processing (MDP) - http://mdp-toolkit.sourceforge.net/
- OpenAI Gym - A toolkit for developing and comparing reinforcement learning algorithms. https://gym.openai.com/
เรามาลองเล่น Reinforcement Learning กันครับ
ผมเลือก qlearning4k - Q-learning for Keras https://github.com/farizrahman4u/qlearning4k มาลองสร้าง Reinforcement Learning ด้วยโมดูล Keras บน Python (ต้องทำการติดตั้งโมดูล Keras และตั้งค่า Theano หรือ TensorFlow กับ Keras ให้เรียบร้อย) เนื่องจากโมดูล Keras ไม่ได้มีไลบรารีสำหรับงาน Reinforcement Learning โดยตรง qlearning4k จึงเป็น reinforcement learning add-on สำหรับโมดูล Keras
qlearning4k มีเกมตัวอย่างในการทำ Reinforcement Learning สองเกมคือ เกม Catch และเกม snake
ผมทำการ clone qlearning4k ด้วยคำสั่ง :
git clone https://github.com/farizrahman4u/qlearning4k.git
แล้วผมทำการสร้างไฟล์ q.py ขึ้นมา เพื่อรัน qlearning4k ให้เล่นเกม Catch
from keras.models import Sequentialแล้วบันทึกไว้ในโฟลเดอร์ qlearning4k ทำการรันด้วยคำสั่ง
from keras.layers import Flatten, Dense
from qlearning4k.games import Catch
from keras.optimizers import *
from qlearning4k import Agent
grid_size = 10
hidden_size = 100
nb_frames = 1
model = Sequential()
model.add(Flatten(input_shape=(nb_frames, grid_size, grid_size)))
model.add(Dense(hidden_size, activation='relu'))
model.add(Dense(hidden_size, activation='relu'))
model.add(Dense(3))
model.compile(sgd(lr=.2), "mse")
catch = Catch(grid_size)
agent = Agent(model=model)
agent.train(catch, batch_size=10, nb_epoch=1000, epsilon=.1)
agent.play(catch)
python q.py
ผลลัพธ์
เข้าไปในโฟลเดอร์ images จะพบกับรูปภาพที่โปรแกรมได้บันทึกไว้
แหล่งศึกษาเพิ่มเติม
- Awesome Reinforcement Learning - https://github.com/aikorea/awesome-rl
- Guest Post (Part I): Demystifying Deep Reinforcement Learning - https://www.nervanasys.com/demystifying-deep-reinforcement-learning/
- Artificial Intelligence > The Pac-Man Projects https://sites.google.com/a/eng.src.ku.ac.th/vacharapat/ai/pacman
- Keras plays catch - a single file Reinforcement Learning example https://gist.github.com/EderSantana/c7222daa328f0e885093
- Fruit - Toy example of a deep reinforcement learning model playing a game of catching fruit. https://github.com/bitwise-ben/Fruit
- Snake - Toy example of deep reinforcement model playing the game of snake. https://github.com/bitwise-ben/Snake
- Subsets of Machine Learning Cookbook - https://www.gitbook.com/book/bigaidream/subsets_ml_cookbook/details
- Deep-Q-Learning-Keras - https://github.com/hashbangCoder/DeepRL-FlappyBird
- Simple DQN - Simple deep Q-learning agent. https://github.com/tambetm/simple_dqn
- DQN-tensorflow - https://github.com/devsisters/DQN-tensorflow
ติดตามบทความต่อไปนะครับ
ขอบคุณครับ
สอบถามครับ เราจะเอาโมเดลที่ได้ไปใช้ยังไงได้บ้างครับ
ตอบลบ