pub struct InfluenceDiagram { /* private fields */ }Expand description
Influence diagram for decision-making under uncertainty.
§Example
use tensorlogic_quantrs_hooks::{InfluenceDiagram, NodeType};
use scirs2_core::ndarray::{ArrayD, IxDyn};
let mut id = InfluenceDiagram::new();
// Add chance node (weather)
id.add_chance_node("weather".to_string(), 2, vec![]);
// Add decision node (umbrella)
id.add_decision_node("umbrella".to_string(), 2, vec!["weather".to_string()]);
// Add utility node
id.add_utility_node("comfort".to_string(), vec!["weather".to_string(), "umbrella".to_string()]);Implementations§
Source§impl InfluenceDiagram
impl InfluenceDiagram
Sourcepub fn add_chance_node(
&mut self,
name: String,
cardinality: usize,
parents: Vec<String>,
) -> &mut Self
pub fn add_chance_node( &mut self, name: String, cardinality: usize, parents: Vec<String>, ) -> &mut Self
Add a chance node (random variable).
Sourcepub fn add_decision_node(
&mut self,
name: String,
cardinality: usize,
parents: Vec<String>,
) -> &mut Self
pub fn add_decision_node( &mut self, name: String, cardinality: usize, parents: Vec<String>, ) -> &mut Self
Add a decision node.
Sourcepub fn add_utility_node(
&mut self,
name: String,
parents: Vec<String>,
) -> &mut Self
pub fn add_utility_node( &mut self, name: String, parents: Vec<String>, ) -> &mut Self
Add a utility node.
Sourcepub fn set_cpt(&mut self, node: &str, cpt: ArrayD<f64>) -> Result<&mut Self>
pub fn set_cpt(&mut self, node: &str, cpt: ArrayD<f64>) -> Result<&mut Self>
Set the conditional probability table for a chance node.
Sourcepub fn set_utility(
&mut self,
node: &str,
utility: ArrayD<f64>,
) -> Result<&mut Self>
pub fn set_utility( &mut self, node: &str, utility: ArrayD<f64>, ) -> Result<&mut Self>
Set the utility table for a utility node.
Sourcepub fn set_decision_order(&mut self, order: Vec<String>) -> &mut Self
pub fn set_decision_order(&mut self, order: Vec<String>) -> &mut Self
Set the decision order explicitly.
Sourcepub fn chance_nodes(&self) -> Vec<&InfluenceNode>
pub fn chance_nodes(&self) -> Vec<&InfluenceNode>
Get all chance nodes.
Sourcepub fn decision_nodes(&self) -> Vec<&InfluenceNode>
pub fn decision_nodes(&self) -> Vec<&InfluenceNode>
Get all decision nodes.
Sourcepub fn utility_nodes(&self) -> Vec<&InfluenceNode>
pub fn utility_nodes(&self) -> Vec<&InfluenceNode>
Get all utility nodes.
Sourcepub fn get_node(&self, name: &str) -> Option<&InfluenceNode>
pub fn get_node(&self, name: &str) -> Option<&InfluenceNode>
Get a node by name.
Sourcepub fn to_factor_graph(&self) -> Result<FactorGraph>
pub fn to_factor_graph(&self) -> Result<FactorGraph>
Convert to a factor graph for inference.
Decision nodes are treated as having uniform distributions.
Sourcepub fn expected_utility(&self, policy: &HashMap<String, usize>) -> Result<f64>
pub fn expected_utility(&self, policy: &HashMap<String, usize>) -> Result<f64>
Compute expected utility for a given policy.
A policy maps decision nodes to their chosen values.
Sourcepub fn optimal_policy(&self) -> Result<(HashMap<String, usize>, f64)>
pub fn optimal_policy(&self) -> Result<(HashMap<String, usize>, f64)>
Find the optimal policy that maximizes expected utility.
Uses exhaustive search over all possible policies.
Sourcepub fn value_of_perfect_information(&self, node: &str) -> Result<f64>
pub fn value_of_perfect_information(&self, node: &str) -> Result<f64>
Compute the value of perfect information for a chance node.
VPI measures how much the expected utility would increase if we could observe the node before making decisions.
Sourcepub fn information_parents(&self, decision: &str) -> Vec<String>
pub fn information_parents(&self, decision: &str) -> Vec<String>
Get the information parents of a decision node.
These are the nodes whose values are known when making this decision.
Sourcepub fn is_well_formed(&self) -> bool
pub fn is_well_formed(&self) -> bool
Check if the influence diagram is well-formed.
A well-formed ID satisfies:
- No cycles
- Decisions have a valid temporal order
- Utility nodes have no children
Sourcepub fn num_decisions(&self) -> usize
pub fn num_decisions(&self) -> usize
Get number of decision nodes.
Sourcepub fn num_utilities(&self) -> usize
pub fn num_utilities(&self) -> usize
Get number of utility nodes.
Trait Implementations§
Source§impl Clone for InfluenceDiagram
impl Clone for InfluenceDiagram
Source§fn clone(&self) -> InfluenceDiagram
fn clone(&self) -> InfluenceDiagram
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for InfluenceDiagram
impl Debug for InfluenceDiagram
Auto Trait Implementations§
impl Freeze for InfluenceDiagram
impl RefUnwindSafe for InfluenceDiagram
impl Send for InfluenceDiagram
impl Sync for InfluenceDiagram
impl Unpin for InfluenceDiagram
impl UnwindSafe for InfluenceDiagram
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.