The MDP class is the base class for all Markov Decision Process solvers in mdptoolbox. To instantiate it, you must provide transition probabilities, rewards, a discount factor, a stopping criterion (epsilon), and a maximum number of iterations (max_iter).
Parameters
transitions: Transition probability matrices. Can be a numpy array of shape (A, S, S) or a list/tuple of length A containing (S, S) arrays (useful for sparse matrices).reward: Reward matrices or vectors. Supported shapes include (S, A), (S,), or (A, S, S). Can also be a list of length A containing (S,), (S, 1), (1, S), or (S, S) arrays. Sparse scipy.sparse.csr_matrix objects are supported.discount: Float ($0 < \text{discount} \le 1$). If set to 1, convergence cannot be assumed.epsilon: Float ($> 0$). The stopping criterion for the value function convergence.max_iter: Integer ($> 0$). Maximum number of iterations allowed.skip_check: Boolean. If True, skips the validation of transitions and reward arrays.
Attributes
P: The processed transition probability matrices.R: The processed reward vectors/matrices.V: The optimal value function.policy: The optimal policy.time: The CPU time used to converge.
Note: MDP.run() is an abstract method and must be implemented by a subclass.
from mdptoolbox.mdp import MDP
import numpy as np
# Example setup (conceptual, as MDP.run() must be overridden)
# transitions = np.random.rand(A, S, S)
# rewards = np.random.rand(S, A)
# mdp = MDP(transitions, rewards, discount=0.9, epsilon=0.01, max_iter=100)