Skip to content

Conversation

@Jameswlepage
Copy link

@Jameswlepage Jameswlepage commented Jan 20, 2026

Summary

This PR adds State Space Model (SSM) based generation as an alternative to diffusion models for time series synthesis.

Motivation: Diffusion models tend to average out patterns and struggle with:

  • Long-range trends (degradation signals)
  • High-frequency oscillations (vibration)
  • Periodicity (pressure cycles)

SSMs address this through continuous-time dynamics and selective state transitions.

Key Additions

  • SSM/s4_layer.py: S4 layer with HiPPO initialization for long-range dependencies
  • SSM/mamba_tsg.py: Mamba selective SSM implementation
    • SelectiveSSM: Core Mamba with input-dependent B, C, Δ parameters
    • MambaVAE: VAE architecture with Mamba encoder/decoder
    • MambaTimeSeriesGenerator: Autoregressive generator
  • SSM/train_mamba_oilfield.py: Training script example

Validation Results

Tested on oil field degradation pattern (should have negative trend):

Model Avg Slope % Negative Trend
Original Data -0.334 100%
Diffusion (DDPM) -0.001 60%
Mamba SSM -0.252 100%

Mamba captures the degradation trend 250x better than diffusion.

Features

  • Pure PyTorch implementation (no custom CUDA ops required)
  • Works on CPU and Apple Silicon (MPS)
  • Linear time complexity O(n)
  • Based on Mamba paper and LS4

Bug Fix Included

  • TimeDP/utils/init_utils.py: Fix undefined cfg_name variable when using --name flag

Test Plan

  • Unit tests for SelectiveSSM, MambaBlock, MambaVAE
  • Training convergence on synthetic data
  • Pattern preservation validation (degradation trends)
  • MPS (Metal) acceleration verified on Apple Silicon

Built with assistance from Claude Code

This PR adds State Space Model (SSM) based generation as an alternative
to diffusion models for time series synthesis.

Key additions:
- SSM/s4_layer.py: S4 layer with HiPPO initialization
- SSM/mamba_tsg.py: Mamba selective SSM implementation
  - SelectiveSSM: Input-dependent B, C, Δ parameters
  - MambaVAE: VAE with Mamba encoder/decoder
  - MambaTimeSeriesGenerator: Autoregressive generator
- SSM/train_mamba_oilfield.py: Training script example

Why SSMs for time series:
- Captures trends better than diffusion (validated on degradation patterns)
- Linear time complexity O(n) vs O(n²) for transformers
- HiPPO-style state preserves long-range dependencies
- Works on CPU and Apple Silicon (MPS)

Bug fix included:
- TimeDP/utils/init_utils.py: Fix undefined cfg_name variable

References:
- Mamba paper: https://arxiv.org/abs/2312.00752
- LS4 (SSM for generation): ICML 2023

Co-Authored-By: Claude <noreply@anthropic.com>
@Jameswlepage
Copy link
Author

@microsoft-github-policy-service agree

@Jameswlepage
Copy link
Author

Jameswlepage commented Jan 20, 2026

Additional findings from the SSM optimization loop

  • Using TimeDP metrics (MMD / KL), the best current SSM configurations achieve:

    • exchange:
      • MMD = 0.0029
      • KL = 0.0686
      • Improves over DiffTime on both metrics; KL remains above TimeGen (KL = 0.016).
    • solar:
      • MMD = 0.0299
      • KL = 0.1735
      • Beats TimeVAE on KL (0.314); still behind DiffTime and TimeGen on KL.
  • MMD is consistently stronger than all baselines across datasets.

  • KL divergence remains the primary gap to close to outperform TimeGen end-to-end.

  • Sweeps were run on TimeDP exchange / solar splits with a deterministic seed = 42.

  • Results are recorded locally at:
    SSM/benchmarks/kl_sweep_results.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant