Skip to content

Commit 7b84c00

Browse files
Merge pull request #284 from marvin-hansen/main
feat(deep_causality): Added more code examples
2 parents c4802b0 + 6e92b3f commit 7b84c00

File tree

57 files changed

+1952
-590
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1952
-590
lines changed

Cargo.lock

Lines changed: 30 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# SPDX-License-Identifier: MIT
2+
# Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
3+
14
[workspace]
25
resolver = "2"
36
members = [

build/scripts/example.sh

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,51 @@ echo "smoking: Simple causal model without Context"
1818
echo "--------------------------------"
1919
echo ""
2020

21-
select opt in csm starter smoking quit;
21+
select opt in cate csm dbn granger starter scm rcm quit;
2222
do
2323
case $opt in
2424

25+
cate)
26+
echo "Selected example: CATE (Conditional Average Treatment Effect)"
27+
command cargo run --release --bin example-cate
28+
break
29+
;;
30+
2531
csm)
2632
echo "Selected example: CSM (Causal State Machine)"
2733
command cargo run --release --bin example-csm
2834
break
2935
;;
3036

37+
dbn)
38+
echo "Selected example: DBN (Dynamic Bayesian Network)"
39+
command cargo run --release --bin example-dbn
40+
break
41+
;;
42+
3143
starter)
3244
echo "Selected example: Starter (Starter)"
3345
command cargo run --release --bin example-starter
3446
break
3547
;;
3648

37-
smoking)
38-
echo "Selected example: SMOKING (Smoking)"
39-
command cargo run --release --bin example-smoking
49+
scm)
50+
echo "Selected example: scm (Structured Causal Model)"
51+
command cargo run --release --bin example-scm
4052
break
4153
;;
4254

55+
granger)
56+
echo "Selected example: Granger (Granger causality)"
57+
command cargo run --release --bin example-granger
58+
break
59+
;;
60+
61+
rcm)
62+
echo "Selected example: RCM (Rubin Causal Model)"
63+
command cargo run --release --bin example-rcm
64+
break
65+
;;
4366
quit)
4467
echo "Exiting!"
4568
exit 0

dcl_data_structures/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# SPDX-License-Identifier: MIT
2+
# Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
3+
14
[package]
25
name = "dcl_data_structures"
36
version = "0.9.1"

deep_causality/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# SPDX-License-Identifier: MIT
2+
# Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
3+
14
[package]
25
name = "deep_causality"
36
version = "0.8.1"

deep_causality/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ pub use crate::traits::generatable::generative_processor::GenerativeProcessor;
6666
// Identifiable Traits
6767
pub use crate::traits::identifiable::Identifiable;
6868
// Indexable Traits
69+
pub use crate::traits::indexable::data_index_current::CurrentDataIndex;
70+
pub use crate::traits::indexable::data_index_previous::PreviousDataIndex;
71+
pub use crate::traits::indexable::data_indexable::DataIndexable;
6972
pub use crate::traits::indexable::time_index_current::CurrentTimeIndex;
7073
pub use crate::traits::indexable::time_index_previous::PreviousTimeIndex;
7174
pub use crate::traits::indexable::time_indexable::TimeIndexable;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* SPDX-License-Identifier: MIT
3+
* Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
4+
*/
5+
use crate::DataIndexable;
6+
7+
const CURRENT_DATA_INDEX_KEY: usize = 1;
8+
9+
pub trait CurrentDataIndex: DataIndexable {
10+
/// Get the current data index.
11+
///
12+
/// # Parameters
13+
///
14+
/// * `key` - The key to look up in the index map
15+
///
16+
/// # Returns
17+
///
18+
/// The current data index as a `usize`.
19+
///
20+
fn get_current_data_index(&self) -> Option<&usize> {
21+
self.get_data_index(&CURRENT_DATA_INDEX_KEY, true)
22+
}
23+
24+
/// Set the current data index.
25+
///
26+
/// # Parameters
27+
///
28+
/// * `key` - The key of the index to place in the index map
29+
/// * `index` - The data index to set as a `usize`
30+
///
31+
fn set_current_data_index(&mut self, index: usize) {
32+
self.set_data_index(CURRENT_DATA_INDEX_KEY, index, true)
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* SPDX-License-Identifier: MIT
3+
* Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
4+
*/
5+
use crate::DataIndexable;
6+
7+
const PREVIOUS_DATA_INDEX_KEY: usize = 0;
8+
9+
pub trait PreviousDataIndex: DataIndexable {
10+
/// Get the previous data index.
11+
///
12+
/// # Parameters
13+
///
14+
/// * `key` - The key to look up in the index map
15+
///
16+
/// # Returns
17+
///
18+
/// The previous data index as a `usize`.
19+
///
20+
fn get_previous_data_index(&self) -> Option<&usize> {
21+
self.get_data_index(&PREVIOUS_DATA_INDEX_KEY, false)
22+
}
23+
24+
/// Set the current previous index.
25+
///
26+
/// # Parameters
27+
///
28+
/// * `key` - The key of the previous data index to place in the index map
29+
/// * `index` - The previous data index to set as a `usize`
30+
///
31+
fn set_previous_data_index(&mut self, index: usize) {
32+
self.set_data_index(PREVIOUS_DATA_INDEX_KEY, index, false)
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* SPDX-License-Identifier: MIT
3+
* Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
4+
*/
5+
6+
pub trait DataIndexable {
7+
/// Gets the data index for the provided key from either the current or previous
8+
/// index map, depending on the value of `current`.
9+
///
10+
/// # Parameters
11+
///
12+
/// * `key` - The key to look up in the index map
13+
/// * `current` - Whether to check the current or previous index map
14+
///
15+
/// # Returns
16+
///
17+
/// Returns the index for the provided key if it exists, otherwise returns None.
18+
///
19+
fn get_data_index(&self, key: &usize, current: bool) -> Option<&usize>;
20+
21+
/// Sets the data index for the provided key in either the current or previous
22+
/// index map, depending on the value of `current`.
23+
///
24+
/// # Parameters
25+
///
26+
/// * `key` - The key to insert into the index map
27+
/// * `index` - The index value to associate with the key
28+
/// * `current` - Whether to insert into the current or previous index map
29+
///
30+
/// If the key already exists in the chosen index map, the existing value
31+
/// will be overwritten with the provided `index` value.
32+
///
33+
fn set_data_index(&mut self, key: usize, index: usize, current: bool);
34+
}

deep_causality/src/traits/indexable/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
* SPDX-License-Identifier: MIT
33
* Copyright (c) "2025" . The DeepCausality Authors and Contributors. All Rights Reserved.
44
*/
5+
pub mod data_index_current;
6+
pub mod data_index_previous;
7+
pub mod data_indexable;
58
pub mod time_index_current;
69
pub mod time_index_previous;
710
pub mod time_indexable;

0 commit comments

Comments
 (0)