semvec/pypi-packages huggingface dataset:
macs-py 1.1.1
A short description of your package.
Requires Python: >=3.6

# Change Point Detection using Wasserstein Distance

macs-py is a change point detection method based on 1-wasserstein distance and permutation test to detect changes in mean, variance, and both mean and variance.\
For more information see the paper .................

---

##  Installation

```bash
pip install macs-py
```

---

##  Overview

MACS detects change points in univariate time series using three refinement modes:

| Function | Detects | Refinement method |
|-----------|----------|------------------|
| `macs_cpd_mean()` | Mean shifts | CUSUM |
| `macs_cpd_var()` | Variance shifts | Negative Log Likelihood (NLL) |
| `macs_cpd_meanvar()` | Mean + variance shifts | Segment-specific NLL |
---

##  Quick Start Examples

Detect a **mean shift** in a univariate time series using `macs_cpd_mean()`.

```python
import numpy as np
from macs import macs_cpd_mean

# Generate synthetic data with a mean shift at t = 300
rng = np.random.default_rng(123)
n = 500
x = np.r_[rng.normal(0.0, 1.0, 300), rng.normal(2.0, 1.0, 200)]

# Run MACS Change Point Detection
cpts, elapsed = macs_cpd_mean(
    series=x,
    window_sizes=[30, 40, 50],
    n_perm=400,     
    alpha_q=1.0,    # 1% two-sided tail (as percent)
    seed=7,
    threshold=0.5
)

print("Detected change points (1-based):", cpts)
print(f"Elapsed time: {elapsed:.3f} seconds")
```

**Output (approximate):**
```
Detected change points (1-based): [301]
Elapsed time: 0.22 seconds
```

![Change Point Detection in Mean](images/change_in_mean.png)


Detect a **variance shift** in a univariate time series using `macs_cpd_var()`.

```python
import numpy as np
from macs import macs_cpd_var

rng = np.random.default_rng(123)
n = 500

x = np.r_[rng.normal(0.0, 1.0, 300), rng.normal(0.0, 2.0, 200)]

cpts, elapsed = macs_cpd_var(
    series=x,
    window_sizes=[30, 40, 50],
    n_perm=400,
    alpha_q=1, 
    seed=7,
    threshold=0.5
)
print("CPs (1-based):", cpts, "elapsed:", round(elapsed, 3), "s")
```

**Output (approximate):**
```
Detected change points (1-based): [301]
Elapsed time: 0.22 seconds
```
![Change Point Detection in Variance](images/change_in_variance.png)

Detect a  **shift in both mean and variance** in a univariate time series using `macs_cpd_meanvar()`.

```python
import numpy as np
from macs import macs_cpd_meanvar


rng = np.random.default_rng(91)
n = 450
# joint change at t=250: mean up, variance up
x = np.r_[rng.normal(0.0, 0.8, 250), rng.normal(1.0, 1.6, 200)]

cpts, elapsed = macs_cpd_meanvar(
    series=x,
    window_sizes=[24, 32, 40],
    n_perm=500,
    alpha_q=1.0,   
    threshold=0.50,
)
print("CPs (1-based):", cpts, "elapsed:", round(elapsed, 3), "s")
```
![Change Point Detection in Mean and Variance](images/change_in_mean_and_variance.png)