pub struct FiniteMdp {
pub transitions: Vec<Vec<Vec<(usize, f64)>>>,
pub rewards: Vec<Vec<f64>>,
}Expand description
A finite Markov decision process: in state s, taking action a yields rewards[s][a] and
moves to state s' with the probabilities in transitions[s][a] (a list of (s', prob)).
Every state must offer at least one action; the probabilities of each action must sum to 1.
Fields§
§transitions: Vec<Vec<Vec<(usize, f64)>>>§rewards: Vec<Vec<f64>>Implementations§
Source§impl FiniteMdp
impl FiniteMdp
Sourcepub fn backward_induction(
&self,
horizon: usize,
terminal_values: &[f64],
) -> Result<Vec<MdpSolution>, ErrorsJSL>
pub fn backward_induction( &self, horizon: usize, terminal_values: &[f64], ) -> Result<Vec<MdpSolution>, ErrorsJSL>
Finite-horizon backward induction: the optimal expected total reward over horizon steps
plus terminal_values[s] on arrival in the final state. Returns, for each stage from the
first (0) to the last (horizon - 1), the value of being in each state and the optimal
action there; the first element holds the optimal values over the whole horizon.
Sourcepub fn value_iteration(
&self,
discount: f64,
tolerance: f64,
max_iterations: usize,
) -> Result<MdpSolution, ErrorsJSL>
pub fn value_iteration( &self, discount: f64, tolerance: f64, max_iterations: usize, ) -> Result<MdpSolution, ErrorsJSL>
Discounted infinite-horizon value iteration with discount in [0, 1). Converges when the
largest change in value falls below tolerance; fails if max_iterations is exhausted.
Sourcepub fn evaluate_policy(
&self,
policy: &[usize],
discount: f64,
tolerance: f64,
) -> Result<Vec<f64>, ErrorsJSL>
pub fn evaluate_policy( &self, policy: &[usize], discount: f64, tolerance: f64, ) -> Result<Vec<f64>, ErrorsJSL>
The expected discounted return of following policy forever, by Gauss-Seidel sweeps,
stopping when a sweep changes no value by tolerance or more (the remaining error can be
up to about discount / (1 − discount) times larger).