pub struct AbductiveReasoningEngine { /* private fields */ }Expand description
Production-quality abductive reasoning engine.
§Example
use ipfrs_tensorlogic::{AbductiveReasoningEngine, AbrTerm, AbrEngineConfig};
let mut eng = AbductiveReasoningEngine::new(AbrEngineConfig::default());
let wet = AbrTerm::prop("wet_grass");
let rain = AbrTerm::prop("rain");
eng.add_observation(wet.clone());
let _hid = eng.add_hypothesis(rain, 1.0, true);
let expls = eng.abduce();
assert!(!expls.is_empty());Implementations§
Source§impl AbductiveReasoningEngine
impl AbductiveReasoningEngine
Sourcepub fn new(config: AbrEngineConfig) -> Self
pub fn new(config: AbrEngineConfig) -> Self
Create a new engine with the given configuration.
Sourcepub fn default_engine() -> Self
pub fn default_engine() -> Self
Create an engine with default configuration.
Sourcepub fn add_hypothesis(
&mut self,
term: AbrTerm,
cost: f64,
is_abducible: bool,
) -> HypothesisId
pub fn add_hypothesis( &mut self, term: AbrTerm, cost: f64, is_abducible: bool, ) -> HypothesisId
Register a hypothesis and return its stable id.
Sourcepub fn add_rule(&mut self, head: AbrTerm, body: Vec<AbrTerm>, confidence: f64)
pub fn add_rule(&mut self, head: AbrTerm, body: Vec<AbrTerm>, confidence: f64)
Register a logical rule.
Sourcepub fn add_observation(&mut self, term: AbrTerm)
pub fn add_observation(&mut self, term: AbrTerm)
Add an observation to be explained.
Sourcepub fn clear_observations(&mut self)
pub fn clear_observations(&mut self)
Remove all observations.
Sourcepub fn set_config(&mut self, config: AbrEngineConfig)
pub fn set_config(&mut self, config: AbrEngineConfig)
Update the engine configuration.
Sourcepub fn remove_hypothesis(&mut self, id: HypothesisId) -> bool
pub fn remove_hypothesis(&mut self, id: HypothesisId) -> bool
Remove a hypothesis by id. Returns true if it existed.
Sourcepub fn abduce(&mut self) -> Vec<AbrExplanation>
pub fn abduce(&mut self) -> Vec<AbrExplanation>
Find all best explanations (hypothesis sets that cover all observations).
Uses branch-and-bound over the space of abducible hypothesis subsets, pruning branches that exceed the cost of the best complete explanation found so far.
Sourcepub fn best_explanation(&mut self) -> Option<AbrExplanation>
pub fn best_explanation(&mut self) -> Option<AbrExplanation>
Return the single best explanation, if any.
Sourcepub fn covers(&self, hypothesis_set: &[HypothesisId]) -> Vec<AbrTerm>
pub fn covers(&self, hypothesis_set: &[HypothesisId]) -> Vec<AbrTerm>
Determine which observations a hypothesis set covers (directly or via rules).
Sourcepub fn is_consistent(&self, hypothesis_set: &[HypothesisId]) -> bool
pub fn is_consistent(&self, hypothesis_set: &[HypothesisId]) -> bool
Check that no two hypotheses in the set assert contradictory facts.
A contradiction is detected when one hypothesis asserts p(…) and
another asserts not_p(…) (prefix "not_" convention) or explicitly
"NOT:p(…)".
Sourcepub fn apply_rules(&self) -> Vec<AbrTerm>
pub fn apply_rules(&self) -> Vec<AbrTerm>
Forward-chain all rules over the facts asserted by every hypothesis in the current hypothesis registry (not just a subset). Returns all newly derived facts as a fixed point.
Sourcepub fn reasoning_stats(&self) -> AbrReasoningStats
pub fn reasoning_stats(&self) -> AbrReasoningStats
Runtime statistics snapshot.
Sourcepub fn hypothesis(&self, id: HypothesisId) -> Option<&AbrHypothesis>
pub fn hypothesis(&self, id: HypothesisId) -> Option<&AbrHypothesis>
Retrieve a hypothesis by id.
Sourcepub fn hypothesis_ids(&self) -> Vec<HypothesisId> ⓘ
pub fn hypothesis_ids(&self) -> Vec<HypothesisId> ⓘ
All hypothesis ids registered with the engine.
Sourcepub fn observations(&self) -> &[AbrTerm]
pub fn observations(&self) -> &[AbrTerm]
All observations currently registered.
Sourcepub fn history(&self) -> &VecDeque<AbrExplanationRecord>
pub fn history(&self) -> &VecDeque<AbrExplanationRecord>
Access the explanation history (most recent last).
Auto Trait Implementations§
impl Freeze for AbductiveReasoningEngine
impl RefUnwindSafe for AbductiveReasoningEngine
impl Send for AbductiveReasoningEngine
impl Sync for AbductiveReasoningEngine
impl Unpin for AbductiveReasoningEngine
impl UnsafeUnpin for AbductiveReasoningEngine
impl UnwindSafe for AbductiveReasoningEngine
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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