Implement model-based value expansion (MVE) for updating action-value estimates by combining short model-predicted rollouts with a learned value function for bootstrapping.
In model-free RL, updates rely solely on real experience. In contrast, model-based value expansion uses a learned dynamics model to simulate short trajectories forward from a given state-action pair, accumulating predicted rewards, and then bootstraps the remaining value using a separate value function estimate at the end of the rollout.
Given:
Q: numpy array of shape (num_states, num_actions), current action-value estimatestransitions: dictionary mapping (state, action) -> next_state (learned deterministic dynamics model)rewards_model: dictionary mapping (state, action) -> reward (learned reward model)V: numpy array of shape (num_states,), value function estimates used for bootstrapping at the rollout horizonexperiences: list of (state, action) tuples representing starting points for value expansionH: int, the model rollout horizon (number of model steps to simulate)gamma: float, discount factoralpha: float, learning rateterminal_states: list of terminal state indicesFor each (state, action) pair in experiences:
Experiences are processed sequentially, and Q-value updates from earlier experiences affect greedy action selection in subsequent ones.
Return the updated Q-table as a numpy array rounded to 4 decimal places.