8. The Multi-Armed Bandit Problem
Activity 8.01: Queueing Bandits
- Import the necessary libraries and tools, as follows:
import numpy as np from utils import QueueBandit
- Declare the bandit object, as follows:
N_CLASSES = 3 queue_bandit = QueueBandit(filename='data.csv')
The
N_CLASSES
variable will be used by our subsequent code. - Implement the Greedy algorithm, as follows:
class GreedyQueue: def __init__(self, n_classes=3): self.n_classes = n_classes self.time_history = [[] for _ in range(n_classes)] def decide(self, queue_lengths): for class_ in range(self.n_classes): if queue_lengths[class_] > 0 and \ ...