pub struct Causaloid<I, O, STATE, CTX>{ /* private fields */ }Expand description
Causaloid is the fundamental building block for causal models in DeepCausality.
It represents a self-contained unit of causality, capable of encapsulating various forms of causal logic:
- A single, stateless causal function (
CausaloidType::Singleton). - A single, context-aware causal function (
CausaloidType::Singletonwithcontext). - A collection of other
Causaloids (CausaloidType::Collection). - A directed acyclic graph (DAG) of other
Causaloids (CausaloidType::Graph).
Causaloids are generic over their input (I), output (O), state (STATE), and context (CTX).
§Type Parameters
I: The type of the input effect value.O: The type of the output effect value.STATE: The type for state management (e.g., internal state or aggregation state).CTX: The type for context, providing access to external data or environment.
Implementations§
Source§impl<I, O, PS, C> Causaloid<I, O, PS, C>
impl<I, O, PS, C> Causaloid<I, O, PS, C>
pub fn id(&self) -> IdentificationValue
pub fn causal_type(&self) -> &CausaloidType
pub fn causal_fn(&self) -> Option<&CausalFn<I, O>>
pub fn context_causal_fn(&self) -> Option<&ContextualCausalFn<I, O, PS, C>>
pub fn context(&self) -> Option<&C>
pub fn causal_collection(&self) -> Option<&Arc<Vec<Causaloid<I, O, PS, C>>>>
pub fn causal_graph( &self, ) -> Option<&Arc<CausaloidGraph<Causaloid<I, O, PS, C>>>>
pub fn description(&self) -> &str
pub fn coll_aggregate_logic(&self) -> Option<&AggregateLogic>
pub fn coll_threshold_value(&self) -> Option<&NumericalValue>
Source§impl<I, O, STATE, CTX> Causaloid<I, O, STATE, CTX>
impl<I, O, STATE, CTX> Causaloid<I, O, STATE, CTX>
Sourcepub fn new(
id: IdentificationValue,
causal_fn: CausalFn<I, O>,
description: &str,
) -> Self
pub fn new( id: IdentificationValue, causal_fn: CausalFn<I, O>, description: &str, ) -> Self
Creates a new singleton Causaloid with a stateless causal function.
This constructor is used for Causaloids that represent a single, atomic
causal relationship defined by a pure function, without requiring any external context.
§Arguments
id- A unique identifier for the causaloid.causal_fn- The stateless function that defines the causaloid’s reasoning logic.description- A human-readable description of the causaloid.
§Returns
A new Causaloid instance of CausaloidType::Singleton.
Sourcepub fn new_with_context(
id: IdentificationValue,
context_causal_fn: ContextualCausalFn<I, O, STATE, CTX>,
context: CTX,
description: &str,
) -> Self
pub fn new_with_context( id: IdentificationValue, context_causal_fn: ContextualCausalFn<I, O, STATE, CTX>, context: CTX, description: &str, ) -> Self
Creates a new singleton Causaloid with a context-aware causal function.
This constructor is used for Causaloids that represent a single, atomic
causal relationship whose logic depends on an external, shared Context.
§Arguments
id- A unique identifier for the causaloid.context_causal_fn- The context-aware stateless function for reasoning.context- A shared context object accessible by the function.description- A human-readable description of the causaloid.
§Returns
A new Causaloid instance of CausaloidType::Singleton with an associated context.
Source§impl<I, O, STATE, CTX> Causaloid<I, O, STATE, CTX>
impl<I, O, STATE, CTX> Causaloid<I, O, STATE, CTX>
Sourcepub fn from_causal_collection(
id: IdentificationValue,
causal_coll: Arc<Vec<Causaloid<I, O, STATE, CTX>>>,
description: &str,
aggregate_logic: AggregateLogic,
threshold_value: NumericalValue,
) -> Self
pub fn from_causal_collection( id: IdentificationValue, causal_coll: Arc<Vec<Causaloid<I, O, STATE, CTX>>>, description: &str, aggregate_logic: AggregateLogic, threshold_value: NumericalValue, ) -> Self
Creates a new Causaloid that encapsulates a linear collection of other Causaloids.
This allows treating a sequence of causal relationships as a single, composite causal unit. The collection can be evaluated individually, as part of another causal collection, or embedded into a causal graph.
§Arguments
id- A unique identifier for the causaloid.causal_coll- AnArcto a vector of childCausaloids forming the collection.description- A human-readable description of the causaloid.aggregate_logic- The logic used to aggregate the results of the child causaloids.threshold_value- A numerical threshold relevant to the aggregation logic.
§Type Bounds
The child Causaloids within the collection must implement Send, Sync, and 'static
to ensure thread safety and static lifetime requirements for shared ownership.
They must also implement MonadicCausable<CausalMonad> for evaluation.
§Returns
A new Causaloid instance of CausaloidType::Collection.
Sourcepub fn from_causal_collection_with_context(
id: IdentificationValue,
causal_coll: Arc<Vec<Causaloid<I, O, STATE, CTX>>>,
context: CTX,
description: &str,
aggregate_logic: AggregateLogic,
threshold_value: NumericalValue,
) -> Self
pub fn from_causal_collection_with_context( id: IdentificationValue, causal_coll: Arc<Vec<Causaloid<I, O, STATE, CTX>>>, context: CTX, description: &str, aggregate_logic: AggregateLogic, threshold_value: NumericalValue, ) -> Self
Creates a new Causaloid that encapsulates a linear collection of other Causaloids
with an associated shared context.
This allows treating a sequence of causal relationships as a single, composite causal unit,
where the evaluation of the collection can depend on an external, shared Context.
§Arguments
id- A unique identifier for the causaloid.causal_coll- AnArcto a vector of childCausaloids forming the collection.context- A shared context object accessible by the collection’s logic.description- A human-readable description of the causaloid.aggregate_logic- The logic used to aggregate the results of the child causaloids.threshold_value- A numerical threshold relevant to the aggregation logic.
§Type Bounds
The child Causaloids within the collection must implement Send, Sync, and 'static
to ensure thread safety and static lifetime requirements for shared ownership.
They must also implement MonadicCausable<CausalMonad> for evaluation.
§Returns
A new Causaloid instance of CausaloidType::Collection with an associated context.
Sourcepub fn from_causal_graph(
id: IdentificationValue,
description: &str,
causal_graph: Arc<CausaloidGraph<Self>>,
) -> Self
pub fn from_causal_graph( id: IdentificationValue, description: &str, causal_graph: Arc<CausaloidGraph<Self>>, ) -> Self
Creates a new Causaloid that encapsulates a causal graph of other Causaloids.
This allows treating a complex, interconnected network of causal relationships as a single, composite causal unit. The graph can be evaluated independently, or embedded into a larger causal structure.
§Arguments
id- A unique identifier for the causaloid.description- A human-readable description of the causaloid.causal_graph- AnArcto aCausaloidGraphcontaining the interconnected childCausaloids.
§Returns
A new Causaloid instance of CausaloidType::Graph.
Sourcepub fn from_causal_graph_with_context(
id: IdentificationValue,
description: &str,
causal_graph: Arc<CausaloidGraph<Self>>,
context: CTX,
) -> Self
pub fn from_causal_graph_with_context( id: IdentificationValue, description: &str, causal_graph: Arc<CausaloidGraph<Self>>, context: CTX, ) -> Self
Creates a new Causaloid that encapsulates a causal graph of other Causaloids
with an associated shared context.
This allows treating a complex, interconnected network of causal relationships
as a single, composite causal unit, where the evaluation of the graph can depend
on an external, shared Context.
§Arguments
id- A unique identifier for the causaloid.description- A human-readable description of the causaloid.causal_graph- AnArcto aCausaloidGraphcontaining the interconnected childCausaloids.context- A shared context object accessible by the graph’s logic.
§Returns
A new Causaloid instance of CausaloidType::Graph with an associated context.
Trait Implementations§
Source§impl<I, O, PS, C> Causable for Causaloid<I, O, PS, C>
Implements the Causable trait for Causaloid.
impl<I, O, PS, C> Causable for Causaloid<I, O, PS, C>
Implements the Causable trait for Causaloid.
This trait provides fundamental properties and methods for any entity that can
participate in a causal relationship. For Causaloid, it primarily defines
how to determine if a causaloid represents a single, atomic causal unit.
Source§fn is_singleton(&self) -> bool
fn is_singleton(&self) -> bool
Checks if the Causaloid is of type Singleton.
A singleton causaloid represents an atomic causal relationship that can be evaluated independently.
§Returns
true if the CausaloidType is Singleton, false otherwise.
Source§impl<I, O, PS, C> CausableGraph<Causaloid<I, O, PS, C>> for CausaloidGraph<Causaloid<I, O, PS, C>>
impl<I, O, PS, C> CausableGraph<Causaloid<I, O, PS, C>> for CausaloidGraph<Causaloid<I, O, PS, C>>
fn is_frozen(&self) -> bool
Source§fn freeze(&mut self)
fn freeze(&mut self)
Static state. Read moreSource§fn get_graph(&self) -> &UltraGraphWeighted<Causaloid<I, O, PS, C>, u64>
fn get_graph(&self) -> &UltraGraphWeighted<Causaloid<I, O, PS, C>, u64>
CausalGraph. Read moreSource§fn add_root_causaloid(
&mut self,
value: Causaloid<I, O, PS, C>,
) -> Result<usize, CausalityGraphError>
fn add_root_causaloid( &mut self, value: Causaloid<I, O, PS, C>, ) -> Result<usize, CausalityGraphError>
Source§fn contains_root_causaloid(&self) -> bool
fn contains_root_causaloid(&self) -> bool
Source§fn get_root_causaloid(&self) -> Option<&Causaloid<I, O, PS, C>>
fn get_root_causaloid(&self) -> Option<&Causaloid<I, O, PS, C>>
Source§fn get_root_index(&self) -> Option<usize>
fn get_root_index(&self) -> Option<usize>
Source§fn get_last_index(&self) -> Result<usize, CausalityGraphError>
fn get_last_index(&self) -> Result<usize, CausalityGraphError>
Source§fn add_causaloid(
&mut self,
value: Causaloid<I, O, PS, C>,
) -> Result<usize, CausalityGraphError>
fn add_causaloid( &mut self, value: Causaloid<I, O, PS, C>, ) -> Result<usize, CausalityGraphError>
Source§fn contains_causaloid(&self, index: usize) -> bool
fn contains_causaloid(&self, index: usize) -> bool
Source§fn get_causaloid(&self, index: usize) -> Option<&Causaloid<I, O, PS, C>>
fn get_causaloid(&self, index: usize) -> Option<&Causaloid<I, O, PS, C>>
Source§fn remove_causaloid(
&mut self,
index: usize,
) -> Result<(), CausalGraphIndexError>
fn remove_causaloid( &mut self, index: usize, ) -> Result<(), CausalGraphIndexError>
Source§fn add_edge(&mut self, a: usize, b: usize) -> Result<(), CausalGraphIndexError>
fn add_edge(&mut self, a: usize, b: usize) -> Result<(), CausalGraphIndexError>
Source§fn add_edg_with_weight(
&mut self,
a: usize,
b: usize,
weight: u64,
) -> Result<(), CausalGraphIndexError>
fn add_edg_with_weight( &mut self, a: usize, b: usize, weight: u64, ) -> Result<(), CausalGraphIndexError>
Source§fn remove_edge(
&mut self,
a: usize,
b: usize,
) -> Result<(), CausalGraphIndexError>
fn remove_edge( &mut self, a: usize, b: usize, ) -> Result<(), CausalGraphIndexError>
Source§fn size(&self) -> usize
fn size(&self) -> usize
Source§fn number_edges(&self) -> usize
fn number_edges(&self) -> usize
Source§fn number_nodes(&self) -> usize
fn number_nodes(&self) -> usize
Source§fn get_shortest_path(
&self,
start_index: usize,
stop_index: usize,
) -> Result<Vec<usize>, CausalityGraphError>
fn get_shortest_path( &self, start_index: usize, stop_index: usize, ) -> Result<Vec<usize>, CausalityGraphError>
Source§impl<I, O, PS, C> Identifiable for Causaloid<I, O, PS, C>
impl<I, O, PS, C> Identifiable for Causaloid<I, O, PS, C>
Source§impl<I, O, PS, C> MonadicCausable<I, O> for Causaloid<I, O, PS, C>
Implements the MonadicCausable trait for Causaloid.
impl<I, O, PS, C> MonadicCausable<I, O> for Causaloid<I, O, PS, C>
Implements the MonadicCausable trait for Causaloid.
This implementation provides the core evaluation logic for Causaloids,
leveraging monadic principles to handle the flow of effects, errors, and logs.
Note: This base implementation only supports CausaloidType::Singleton.
For Collection and Graph evaluation with aggregation support, use the
specialized constructors that ensure proper trait bounds are met.
Source§fn evaluate(
&self,
incoming_effect: &PropagatingEffect<I>,
) -> PropagatingEffect<O>
fn evaluate( &self, incoming_effect: &PropagatingEffect<I>, ) -> PropagatingEffect<O>
Evaluates the causal effect of this Causaloid given an incoming_effect.
The evaluation process is monadic, ensuring that errors are propagated and a comprehensive log of operations is maintained.
Important: This base implementation only supports Singleton causaloids.
For Collection and Graph types, specialized evaluation methods with
proper trait bounds should be used.
§Arguments
incoming_effect- ThePropagatingEffectrepresenting the input to this causaloid.
§Returns
A PropagatingEffect containing the result of the causal evaluation,
any errors encountered, and a complete log of the operations performed.