Skip to content

Commit 2c97e3f

Browse files
committed
Fixed starter example
Signed-off-by: Marvin Hansen <[email protected]>
1 parent d8b61b5 commit 2c97e3f

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

examples/starter/src/main.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,25 @@ fn get_test_causaloid(id: IdentificationValue) -> BaseCausaloid {
5454
// - It takes `&Evidence` as input.
5555
// - It returns `Result<PropagatingEffect, CausalityError>`.
5656
fn causal_fn(effect: &PropagatingEffect) -> Result<PropagatingEffect, CausalityError> {
57-
// Safely extract the numerical value from the generic PropagatingEffect enum.
58-
let obs = match effect {
59-
PropagatingEffect::Numerical(val) => *val,
60-
_ => return Err(CausalityError("Expected Numerical effect.".into())),
57+
// This function now handles two types of incoming effects:
58+
// 1. Numerical: Typically from an initial observation.
59+
// 2. Deterministic: The boolean output from a preceding causaloid in the graph.
60+
let is_active = match effect {
61+
PropagatingEffect::Numerical(val) => {
62+
if val.is_sign_negative() {
63+
return Err(CausalityError("Observation is negative".into()));
64+
}
65+
*val > 0.55 // Threshold check
66+
}
67+
PropagatingEffect::Deterministic(val) => *val, // Pass through the boolean effect
68+
_ => {
69+
// Any other effect type is considered invalid for this simple causaloid.
70+
return Err(CausalityError(
71+
"Expected Numerical or Deterministic effect.".into(),
72+
));
73+
}
6174
};
6275

63-
if obs.is_sign_negative() {
64-
return Err(CausalityError("Observation is negative".into()));
65-
}
66-
67-
let threshold: NumericalValue = 0.55;
68-
let is_active = obs.ge(&threshold);
69-
7076
// Return the result wrapped in the `PropagatingEffect` enum.
7177
Ok(PropagatingEffect::Deterministic(is_active))
7278
}

0 commit comments

Comments
 (0)