pub struct Policy<K> { /* private fields */ }Expand description
A persistent table of learned weights, one per key, nudged by feedback.
Decision logic is stateless per call; Policy is the small mutable state that
lets an agent improve over time. Read a key’s learned weight and fold it into
an action (as its base or a consideration); after an outcome, call
reward to move that weight toward what actually worked.
The update is a bounded integer moving average, so it is deterministic and can never run away — it is not machine learning, just `weight += rate * (outcome
- weight)
in fixed point, clamped to0.0..=1.0`.
§Example
use reliakit_decide::{Policy, Score};
// Start every key at 0.5, learning at rate 0.5.
let mut policy = Policy::new(Score::from_ratio(1, 2), Score::from_ratio(1, 2));
assert_eq!(policy.weight(&"route_a"), Score::from_ratio(1, 2)); // unseen -> default
// "route_a" worked well (outcome 1.0): its weight rises toward 1.0.
policy.reward("route_a", Score::MAX);
assert_eq!(policy.weight(&"route_a").raw(), 7_500); // 0.5 + 0.5*(1.0-0.5)Implementations§
Source§impl<K> Policy<K>
impl<K> Policy<K>
Source§impl<K: PartialEq> Policy<K>
impl<K: PartialEq> Policy<K>
Trait Implementations§
Auto Trait Implementations§
impl<K> Freeze for Policy<K>
impl<K> RefUnwindSafe for Policy<K>where
K: RefUnwindSafe,
impl<K> Send for Policy<K>where
K: Send,
impl<K> Sync for Policy<K>where
K: Sync,
impl<K> Unpin for Policy<K>where
K: Unpin,
impl<K> UnsafeUnpin for Policy<K>
impl<K> UnwindSafe for Policy<K>where
K: UnwindSafe,
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
Mutably borrows from an owned value. Read more