DriteStudio
DRITESTUDIOCloud Infrastructure
Home
ArticlesAbout UsContactStatus
0%
Q-Learning คืออะไร?
Back to articles

Q-Learning คืออะไร?

Q-Learning คืออะไร?

Windows-September 2, 2023-Updated: February 24, 2026

Q-Learning คืออะไร?

Q-Learning เป็นวิธีหนึ่งในการเรียนรู้แบบเสริมเหรียญในปัญหาการตัดสินใจ โดยมุ่งหวังให้ตัวแบบเรียนรู้การกระทำที่จะให้ผลลัพธ์ที่ดีที่สุดในสิ่งแวดล้อมที่เปลี่ยนแปลงได้

ขั้นตอนการทำงานของ Q-Learning

  1. กำหนด State (สถานะ) และ Action (การกระทำ): กำหนดชุดของสถานะที่เป็นไปได้และการกระทำที่ตัวแบบสามารถทำได้ในแต่ละสถานะ

  2. สร้างตาราง Q-Value (ค่า Q): สร้างตารางที่เก็บค่า Q-Value ซึ่งเป็นค่าประมาณการของความคุ้มค่าในการกระทำในแต่ละสถานะ

  3. เริ่มต้นค่า Q-Value: กำหนดค่าเริ่มต้นของ Q-Value สำหรับทุกสถานะและการกระทำ

  4. วนรอบการเรียนรู้: ในแต่ละรอบการทำงาน

    • ตัวแบบทำการกระทำในสถานะปัจจุบันตามนโยบาย (Policy) ที่กำหนดโดย Q-Value
    • ตัวแบบได้รับค่าประสบการณ์ (Reward) จากสิ่งแวดล้อมและย้ายไปสถานะใหม่
    • อัปเดตค่า Q-Value ของสถานะและการกระทำตามสูตร Q-Learning
  5. เรียนรู้และปรับปรุง: ดำเนินการวนรอบการเรียนรู้เพื่อปรับปรุงค่า Q-Value จนกระทั่ง Q-Value converge หรือไม่เปลี่ยนแปลงมากแล้ว

ตัวอย่างโค้ด Python สำหรับ Q-Learning

import numpy as np

# กำหนดจำนวนสถานะและการกระทำ
num_states = 6
num_actions = 2

# สร้างตาราง Q-Value และกำหนดค่าเริ่มต้น
Q = np.zeros((num_states, num_actions))

# พารามิเตอร์การเรียนรู้
learning_rate = 0.1
discount_factor = 0.9
num_episodes = 1000

# วนรอบการเรียนรู้
for episode in range(num_episodes):
    state = np.random.randint(0, num_states)
    done = False
    
    while not done:
        action = np.argmax(Q[state, :])
        next_state = np.random.choice(num_states)
        reward = -1 if next_state != num_states - 1 else 10
        
        Q[state, action] = Q[state, action] + learning_rate * (reward + discount_factor * np.max(Q[next_state, :]) - Q[state, action])
        
        state = next_state
        if state == num_states - 1:
            done = True

# พิมพ์ผลลัพธ์ Q-Value
print("Q-Value:")
print(Q)

ในตัวอย่างโค้ดดังกล่าว เราจะพบว่ามีการสร้างตาราง Q-Value และทำการเรียนรู้ Q-Learning โดยใช้การอัปเดตค่า Q-Value ในแต่ละขั้นตอนของการกระทำในสิ่งแวดล้อม โดยพารามิเตอร์เช่น learning rate และ discount factor จะมีผลต่อกระบวนการเรียนรู้และปรับปรุงค่า Q-Value ในแต่ละรอบการเรียนรู้
Share article:
View more articles
D

DriteStudio | ไดรท์สตูดิโอ

Cloud, VPS, Hosting and Colocation provider in Thailand

Operated by Craft Intertech (Thailand) Co., Ltd.

DRITESTUDIOCloud Infrastructure

100/280 Soi 17, Delight Village, Bang Khun Thian - Chaitalay, Phanthai Norasing, Samut Sakhon 74000

Services

  • VPS Hosting
  • Dedicated Server
  • Web Hosting
  • Security Solutions

Company

  • About Us
  • Contact Us
  • System Status

Support

  • Support Ticket
  • Documentation
  • Help Center

© 2026 Craft Intertech (Thailand) Co., Ltd. All rights reserved.

Privacy PolicyTerms of ServiceRefund Policy

We use cookies

We use cookies to enhance your browsing experience, analyze site traffic, and personalize content. By clicking "Accept All", you consent to our use of cookies. Privacy Policy