Function counterfactual_trajectory

Source
pub fn counterfactual_trajectory(
    pre_change: &[(i64, &[f32])],
    post_change: &[(i64, &[f32])],
    change_point: i64,
) -> Result<CounterfactualResult, AnalyticsError>
Expand description

Compute a counterfactual trajectory analysis.

Splits the trajectory at change_point, fits a linear trend to the pre-change segment, extrapolates beyond the change point, and compares with the actual post-change data.

§Arguments

  • pre_change — Trajectory before the change point (sorted by timestamp)
  • post_change — Trajectory after the change point (sorted by timestamp)
  • change_point — Timestamp of the detected change

§Errors

Returns AnalyticsError::InsufficientData if pre_change has < 2 points or post_change is empty.