Hit and trial là gì?

Noun AI
generate and test

Hit and trial hay cách tiếp cận cổ điển để giải quyết các bài toán trong trí tuệ nhân tạo (AI) và là kỹ thuật đơn giản nhất. Đối với bất kỳ bài toán nào đang xảy ra, chúng ta có thể sử dụng phương pháp hit and trial để kiểm tra các giải pháp (solution) khác nhau cho bài toán đó. Ở đây, chúng ta ngẫu nhiên tạo giải pháp và sau đó kiểm tra giải pháp cho trạng thái mục tiêu (goal state) và chúng ta ngừng tìm kiếm nếu nó là giải pháp. Đây cũng được gọi là phương pháp tiếp cận tạo và thử nghiệm (generate and test).

Các thành phần (component) của tìm kiếm hit and trial:

  • Trình tạo giải pháp (solution generator): tạo ra các giải pháp khác nhau cho một bài toán.
  • Trình kiểm tra (tester): kiểm tra xem một giải pháp khả thi từ giải pháp tạo ra có giải quyết được bài toán hay không

Nếu chúng ta thử tất cả các giải pháp có thể, tìm kiếm được gọi là brute-force search.

Ví dụ về đoán một số bằng cách sử dụng hit and trial:


import random
numbers = [1,2,3,4,5,6,7,8,9,0]
computer_guess_number = random.choice(numbers)

while True:
    user_input = int(input("What number is guessed by Computer??: "))
    if user_input == computer_guess_number:
        print("Congratulations !")
        break
    else:
        print("Try Again")

# What number is guessed by Computer??: 3
# Try Again
# What number is guessed by Computer??: 1
# Try Again
# What number is guessed by Computer??: 2
# Try Again
# What number is guessed by Computer??: 3
# Try Again
# What number is guessed by Computer??: 4
# Try Again
# What number is guessed by Computer??: 7
# Try Again
# What number is guessed by Computer??: 8
# Try Again
# What number is guessed by Computer??: 9
# Try Again
# What number is guessed by Computer??: 0
# Try Again
# What number is guessed by Computer??: 5
# Congratulations !

Learning English Everyday