pub struct BayesianChangePoint {
pub hazard_rate: f64,
pub prior_mean: f64,
pub prior_var: f64,
pub obs_var: f64,
pub threshold: f64,
}Expand description
Bayesian Online Change Point Detection.
Implements the Adams & MacKay (2007) algorithm that maintains a distribution over “run lengths” (time since last change point). At each time step:
- Observe new data point x_t
- Update run length probabilities using predictive likelihood
- Apply hazard function to compute growth and change point probabilities
The hazard function H(tau) gives the probability of a change point given the current run length tau. A constant hazard 1/lambda yields a geometric prior on run lengths.
§References
Adams, R. P., & MacKay, D. J. C. (2007). “Bayesian online changepoint detection.” arXiv preprint arXiv:0710.3742.
Fields§
§hazard_rate: f64Hazard rate (1/lambda): probability of change at each time step
prior_mean: f64Prior mean for the normal model
prior_var: f64Prior variance for the normal model
obs_var: f64Observation noise variance
threshold: f64Threshold on change point posterior probability
Implementations§
Source§impl BayesianChangePoint
impl BayesianChangePoint
Sourcepub fn new(hazard_rate: f64, threshold: f64) -> Self
pub fn new(hazard_rate: f64, threshold: f64) -> Self
Create a new Bayesian change point detector.
§Arguments
hazard_rate- Constant hazard rate (1/lambda). Higher values mean change points are more frequent a priori.threshold- Posterior probability threshold for declaring a change point.
Sourcepub fn with_prior(
hazard_rate: f64,
threshold: f64,
prior_mean: f64,
prior_var: f64,
obs_var: f64,
) -> Self
pub fn with_prior( hazard_rate: f64, threshold: f64, prior_mean: f64, prior_var: f64, obs_var: f64, ) -> Self
Create with custom prior parameters.
Sourcepub fn detect(&self, data: &ArrayView1<'_, f64>) -> Result<ChangePointResult>
pub fn detect(&self, data: &ArrayView1<'_, f64>) -> Result<ChangePointResult>
Detect change points using Bayesian online detection.
Uses the MAP (Maximum A Posteriori) run length to detect changepoints. With a constant hazard function, P(r_t = 0 | x_{1:t}) = h always, so the raw run-length-zero probability cannot distinguish changepoints. Instead, we detect times when the MAP run length drops significantly, indicating the run length distribution has shifted to short run lengths after a structural break in the data.
The threshold parameter controls the minimum posterior probability
of the new MAP run length required to declare a changepoint, filtering
out low-confidence detections.
Sourcepub fn compute_run_length_distribution(
&self,
data: &ArrayView1<'_, f64>,
) -> Result<(Array2<f64>, Array1<f64>)>
pub fn compute_run_length_distribution( &self, data: &ArrayView1<'_, f64>, ) -> Result<(Array2<f64>, Array1<f64>)>
Compute the full run length distribution over time.
Returns:
run_length_probs- Matrix where row t contains the probability of each run length at time t. Entry [t][r] = P(r_t = r | x_{1:t}).cp_probs- Vector of change point posterior probabilities at each time step.
Trait Implementations§
Source§impl Clone for BayesianChangePoint
impl Clone for BayesianChangePoint
Source§fn clone(&self) -> BayesianChangePoint
fn clone(&self) -> BayesianChangePoint
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BayesianChangePoint
impl RefUnwindSafe for BayesianChangePoint
impl Send for BayesianChangePoint
impl Sync for BayesianChangePoint
impl Unpin for BayesianChangePoint
impl UnsafeUnpin for BayesianChangePoint
impl UnwindSafe for BayesianChangePoint
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.