Causaloid

Struct Causaloid 

Source
pub struct Causaloid<I, O, STATE, CTX>
where I: Default, O: Default + Debug, STATE: Default + Clone, CTX: Clone,
{ /* 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::Singleton with context).
  • 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>
where I: Default, O: Default + Debug, PS: Default + Clone, C: Clone,

Source

pub fn id(&self) -> IdentificationValue

Source

pub fn causal_type(&self) -> &CausaloidType

Source

pub fn causal_fn(&self) -> Option<&CausalFn<I, O>>

Source

pub fn context_causal_fn(&self) -> Option<&ContextualCausalFn<I, O, PS, C>>

Source

pub fn context(&self) -> Option<&C>

Source

pub fn causal_collection(&self) -> Option<&Arc<Vec<Causaloid<I, O, PS, C>>>>

Source

pub fn causal_graph( &self, ) -> Option<&Arc<CausaloidGraph<Causaloid<I, O, PS, C>>>>

Source

pub fn description(&self) -> &str

Source

pub fn coll_aggregate_logic(&self) -> Option<&AggregateLogic>

Source

pub fn coll_threshold_value(&self) -> Option<&NumericalValue>

Source§

impl<I, O, STATE, CTX> Causaloid<I, O, STATE, CTX>
where I: Default, O: Default + Debug, STATE: Default + Clone, CTX: Clone,

Source

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.

Source

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>
where I: Default, O: Default + Debug, STATE: Default + Clone, CTX: Clone,

Source

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
where I: Send + Sync + 'static, O: Send + Sync + 'static, STATE: Send + Sync + 'static, CTX: Send + Sync + 'static, Causaloid<I, O, STATE, CTX>: MonadicCausable<I, O>,

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 - An Arc to a vector of child Causaloids 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.

Source

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
where I: Send + Sync + 'static, O: Send + Sync + 'static, STATE: Send + Sync + 'static, CTX: Send + Sync + 'static, Causaloid<I, O, STATE, CTX>: MonadicCausable<I, O>,

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 - An Arc to a vector of child Causaloids 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.

Source

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 - An Arc to a CausaloidGraph containing the interconnected child Causaloids.
§Returns

A new Causaloid instance of CausaloidType::Graph.

Source

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 - An Arc to a CausaloidGraph containing the interconnected child Causaloids.
  • 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>
where I: Default, O: Default + Debug, PS: Default + Clone, C: Clone,

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

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>>
where I: Default + Send + Sync + 'static, O: Default + Debug + Send + Sync + 'static, PS: Default + Clone + Send + Sync + 'static, C: Clone + Send + Sync + 'static, Causaloid<I, O, PS, C>: MonadicCausable<I, O>,

Source§

fn is_frozen(&self) -> bool

Source§

fn freeze(&mut self)

Ensures the graph is in the immutable, performance-optimized Static state. Read more
Source§

fn unfreeze(&mut self)

Ensures the graph is in the mutable, Dynamic state. Read more
Source§

fn get_graph(&self) -> &UltraGraphWeighted<Causaloid<I, O, PS, C>, u64>

Returns a reference to the underlying CausalGraph. Read more
Source§

fn add_root_causaloid( &mut self, value: Causaloid<I, O, PS, C>, ) -> Result<usize, CausalityGraphError>

Adds a special “root” causaloid to the graph. Read more
Source§

fn contains_root_causaloid(&self) -> bool

Checks if a root causaloid has been set in the graph. Read more
Source§

fn get_root_causaloid(&self) -> Option<&Causaloid<I, O, PS, C>>

Retrieves an immutable reference to the root causaloid, if it exists. Read more
Source§

fn get_root_index(&self) -> Option<usize>

Retrieves the index of the root causaloid, if it exists. Read more
Source§

fn get_last_index(&self) -> Result<usize, CausalityGraphError>

Gets the index of the last causaloid added to the graph. Read more
Source§

fn add_causaloid( &mut self, value: Causaloid<I, O, PS, C>, ) -> Result<usize, CausalityGraphError>

Adds a new causaloid (node) to the graph. Read more
Source§

fn contains_causaloid(&self, index: usize) -> bool

Checks if a causaloid exists at a specific index in the graph. Read more
Source§

fn get_causaloid(&self, index: usize) -> Option<&Causaloid<I, O, PS, C>>

Retrieves an immutable reference to a causaloid at a given index. Read more
Source§

fn remove_causaloid( &mut self, index: usize, ) -> Result<(), CausalGraphIndexError>

Removes a causaloid from the graph at the specified index. Read more
Source§

fn add_edge(&mut self, a: usize, b: usize) -> Result<(), CausalGraphIndexError>

Adds a directed edge between two causaloids in the graph. Read more
Source§

fn add_edg_with_weight( &mut self, a: usize, b: usize, weight: u64, ) -> Result<(), CausalGraphIndexError>

Adds a weighted directed edge between two causaloids. Read more
Source§

fn contains_edge(&self, a: usize, b: usize) -> bool

Checks if a directed edge exists from causaloid a to causaloid b. Read more
Source§

fn remove_edge( &mut self, a: usize, b: usize, ) -> Result<(), CausalGraphIndexError>

Removes a directed edge between two causaloids. Read more
Source§

fn size(&self) -> usize

Returns the total number of causaloids (nodes) in the graph. Read more
Source§

fn is_empty(&self) -> bool

Checks if the graph contains no causaloids. Read more
Source§

fn clear(&mut self)

Removes all causaloids and edges from the graph. Read more
Source§

fn number_edges(&self) -> usize

Returns the total number of edges in the graph. Read more
Source§

fn number_nodes(&self) -> usize

Returns the total number of causaloids (nodes) in the graph. Read more
Source§

fn get_shortest_path( &self, start_index: usize, stop_index: usize, ) -> Result<Vec<usize>, CausalityGraphError>

Default implementation for shortest path algorithm. Read more
Source§

impl<I, O, STATE, CTX> Clone for Causaloid<I, O, STATE, CTX>
where I: Default, O: Default + Debug, STATE: Default + Clone, CTX: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<I, O, PS, C> Debug for Causaloid<I, O, PS, C>
where I: Default, O: Default + Debug, PS: Default + Clone, C: Clone,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I, O, PS, C> Display for Causaloid<I, O, PS, C>
where I: Default, O: Default + Debug, PS: Default + Clone, C: Clone,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I, O, PS, C> Identifiable for Causaloid<I, O, PS, C>
where I: Default, O: Default + Debug, PS: Default + Clone, C: Clone,

Source§

fn id(&self) -> u64

Source§

impl<I, O, PS, C> MonadicCausable<I, O> for Causaloid<I, O, PS, C>
where I: Default + Clone + Send + Sync + 'static + Debug, O: Default + Debug + Clone + Send + Sync + 'static, PS: Default + Clone + Send + Sync + 'static, C: Clone + Send + Sync + 'static,

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>

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 - The PropagatingEffect representing 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.

Source§

impl<I, O, PS, C> PartialEq for Causaloid<I, O, PS, C>
where I: Default, O: Default + Debug, PS: Default + Clone, C: Clone,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<I, O, STATE, CTX> Freeze for Causaloid<I, O, STATE, CTX>
where CTX: Freeze,

§

impl<I, O, STATE, CTX> RefUnwindSafe for Causaloid<I, O, STATE, CTX>

§

impl<I, O, STATE, CTX> Send for Causaloid<I, O, STATE, CTX>
where CTX: Send + Sync, I: Send + Sync, O: Send + Sync, STATE: Send + Sync,

§

impl<I, O, STATE, CTX> Sync for Causaloid<I, O, STATE, CTX>
where CTX: Sync + Send, I: Sync + Send, O: Sync + Send, STATE: Sync + Send,

§

impl<I, O, STATE, CTX> Unpin for Causaloid<I, O, STATE, CTX>
where CTX: Unpin, I: Unpin, O: Unpin, STATE: Unpin,

§

impl<I, O, STATE, CTX> UnwindSafe for Causaloid<I, O, STATE, CTX>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.