Research code for simulating dependent (mixing) time series and estimating Tukey's halfspace depth and the associated minimal direction at a point, both empirically (via simulation) and analytically (for Gaussian / VAR(1) processes). Used to study how fast empirical depth/direction estimates converge to their theoretical values as sample size grows.
FunctionalCurves/
├── pyproject.toml # Package metadata & dependencies (pip install -e .)
├── functionalcurves/ # Installable package
│ ├── __init__.py
│ ├── mixing_models.py # Simulate mixing (weakly dependent) bivariate processes
│ └── depth.py # Compute Tukey depth / minimal direction, empirically and analytically
├── notebooks/ # Interactive demos
│ ├── example_var1.ipynb # Demo: VAR(1) process + empirical depth estimation & convergence
│ ├── example_polynomial.ipynb # Demo: MixingLinearModel process + Gaussian analytic depth comparison
│ └── scratch_interactive.ipynb # Scratch/interactive notebook, mostly duplicated commented-out code
└── scripts/
└── donsker_cdf_scratch.py # Scratch script: empirical CDF convergence (Donsker) plots
Generates synthetic bivariate sample paths with controllable dependence ("mixing rate").
transition_markov(X, p, e)/transition_diff(X, p, e)— transition functions defining how the next state depends on the previous state and an innovatione.MixingMarkovModel— simple Markov-chain-style simulator: repeatedly applies a transition function to Gaussian innovations.MixingLinearModel— simulates a linearly-weighted mixing process where weights decay ask^-mixing_rate; includes an error-correction term (zeta/zeta_k, viascipy.special.zeta) to control approximation error from truncating an infinite sum, and adistribution()method giving the theoretical mean/covariance of the limiting process.CovHC_— placeholder for a heteroscedasticity-consistent covariance estimator (unimplemented).if __name__ == '__main__'block — example script simulating a process and plotting estimated depth/direction vs. sample size (usesdepth.py).
Core depth/direction estimation logic.
rad(v1, v2, ...)— signed angle in[0, 2π)between vectors (used throughout for directional comparisons).rad_wu,rad_dec— related/deprecated angle helpers.GaussianDepth(mean, cov, X0)— closed-form Tukey depth and minimal direction for a bivariate normal distribution.Estimator— empirical depth/direction estimator given a sampleXand a pointX0. Two methods:'deg'— scans candidate directions uniformly over[-π, π].'point_wise'— uses each sample point's own direction as a candidate. Returns the minimal depth, the corresponding direction, and the full arrays of angles/depths/directions considered.
TDE— deprecated older counting-based depth estimator, superseded byEstimator.Analytic_Depth— computes the exact Tukey depth and minimal direction for a stationary VAR(1) process (X_t = A0 + A1 X_{t-1} + noise), by deriving the process's stationary mean/covariance and applying the Gaussian depth formula (TD_analytic).Depthclass — thin wrapper stub intended to expose ahalfspacedepth method (currently unimplemented / placeholder).if __name__ == '__main__'block — simulates a VAR(1) process viastatsmodels, computes the true analytic depth/direction, and compares against empirical estimates ('deg'vs'point_wise') as sample size increases, plotting convergence.
Standalone scratch script unrelated to the depth machinery: plots the empirical CDF process √N (F_N(x) - F(x)) for uniform samples of increasing size, illustrating Donsker's theorem.
notebooks/example_var1.ipynb— Simulates a VAR(1) process, computes the analytic Tukey depth/direction at a chosen pointX0, then compares against empirical estimates (Estimator, both methods) across increasing sample sizes, with convergence and directional-vector plots. Also has a section usingmixing_models.MixingModel(transition-based simulation).notebooks/example_polynomial.ipynb— Same style of analysis but driving the sample fromMixingLinearModelinstead of a VAR process, comparing empirical estimates against the Gaussian analytic depth (GaussianDepth) using the model's theoretical stationary distribution.notebooks/scratch_interactive.ipynb— Exploratory/scratch notebook; most cells are commented-out duplicates of the empirical-CDF script fromscripts/donsker_cdf_scratch.py, plus an interactive version. Not core to the library.
numpy, scipy, matplotlib, statsmodels (for VARProcess), tqdm. A commented-out import suggests intended (but currently unused/unavailable) integration with a depth package (depth.multivariate) for halfspace depth via compiled libraries.
pip install -e .Both functionalcurves/mixing_models.py and functionalcurves/depth.py are runnable as scripts (python -m functionalcurves.depth, python -m functionalcurves.mixing_models) and contain end-to-end examples: simulate a process, estimate depth/direction over growing sample sizes, and plot convergence against the true/analytic values. The notebooks in notebooks/ walk through the same workflow interactively.