pub struct RegionMdp {
transitions: HashMap<(u32, String), HashMap<u32, u32>>,
rewards: HashMap<(u32, String), Vec<f32>>,
region_quality: HashMap<u32, Vec<f32>>,
n_transitions: usize,
}Expand description
A transition model over HNSW regions.
Fields§
§transitions: HashMap<(u32, String), HashMap<u32, u32>>(region, action_type) → {next_region: count}.
rewards: HashMap<(u32, String), Vec<f32>>(region, action_type) → [rewards].
region_quality: HashMap<u32, Vec<f32>>region → [episode_rewards].
n_transitions: usizeTotal transitions learned.
Implementations§
Source§impl RegionMdp
impl RegionMdp
Sourcepub fn learn_trajectory(
&mut self,
regions: &[u32],
actions: &[String],
reward: f32,
)
pub fn learn_trajectory( &mut self, regions: &[u32], actions: &[String], reward: f32, )
Learn from a single episode trajectory.
regions: sequence of region IDs the episode traversed.
actions: corresponding action types (same length as regions).
reward: episode outcome (1.0 = success, 0.0 = failure).
Sourcepub fn action_success_rate(&self, region: u32, action_type: &str) -> f32
pub fn action_success_rate(&self, region: u32, action_type: &str) -> f32
P(success | region, action_type) using Beta prior.
Returns (1 + n_successes) / (2 + n_total) for Bayesian smoothing. Falls back to region-level quality if no data for this (region, action).
Sourcepub fn region_quality_score(&self, region: u32) -> f32
pub fn region_quality_score(&self, region: u32) -> f32
Overall quality of a region (mean reward of episodes passing through).
Sourcepub fn best_actions(&self, region: u32) -> Vec<(String, f32)>
pub fn best_actions(&self, region: u32) -> Vec<(String, f32)>
Rank action types by success rate in a given region.
Returns (action_type, success_rate) sorted descending.
Sourcepub fn transition_probability(
&self,
region: u32,
action: &str,
next_region: u32,
) -> f32
pub fn transition_probability( &self, region: u32, action: &str, next_region: u32, ) -> f32
P(s’ | s, a) — transition probability.
Sourcepub fn decay_factor(&self, region: u32) -> f32
pub fn decay_factor(&self, region: u32) -> f32
Context-aware decay factor based on region quality.
High-quality region → small decay (0.95). Low-quality region → large decay (0.70).
Sourcepub fn format_hints(&self, region: u32, top_n: usize) -> String
pub fn format_hints(&self, region: u32, top_n: usize) -> String
Format action hints for a region as a string.
Sourcepub fn n_transitions(&self) -> usize
pub fn n_transitions(&self) -> usize
Total transitions learned.
Sourcepub fn n_state_actions(&self) -> usize
pub fn n_state_actions(&self) -> usize
Number of distinct (region, action) pairs observed.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for RegionMdp
impl<'de> Deserialize<'de> for RegionMdp
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for RegionMdp
impl RefUnwindSafe for RegionMdp
impl Send for RegionMdp
impl Sync for RegionMdp
impl Unpin for RegionMdp
impl UnwindSafe for RegionMdp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more