Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

NHSMM — Neural Hidden Semi-Markov Models


⚠️ Alpha stage — NHSMM is a proof-of-concept and actively evolving. Public APIs may change before stable 1.0.0.

NHSMM is a modular PyTorch library for context-aware sequential modeling, forming the foundation of the State Aware Engine (SAE). NHSMM-INTERFACES defines domain-level contracts for integrating NHSMM in diverse systems.

Designed for developers, data scientists, and system integrators, NHSMM enables rapid understanding, deployment, and extension of latent state models for domains such as finance, IoT, robotics, health, and cybersecurity.

PyPI License: Apache-2.0 Python Version


🌟 Highlights

  • Neural HSMM — integrates Hidden Semi-Markov Models with neural parameterization for expressive latent dynamics.
  • Context-Aware Modulation — initial, transition, duration, and emission distributions adapt to external covariates.
  • Flexible Architectures — supports hierarchical and hybrid models.
  • PyTorch & GPU Ready — scalable multi-domain deployment.
  • Modular Foundation — for research, experimentation, and production-ready sequence models.

🧩 Overview

NHSMM explicitly models:

  • Context-Dependent State Durations — variable dwell-times per hidden state influenced by covariates.
  • Context-Dependent Transitions — dynamic transition probabilities adapting to time-varying features.

Suitable for non-stationary, heterogeneous, and time-aware sequences across real-world applications.


NHSMM Project Covenant

  1. Forever Open Core — nhsmm remains fully open-source and actively maintained.
  2. No Hidden Dependencies — core library uses only open components; experimental modules (nhsmm-interfaces) are optional.
  3. Transparent Evolution — research previews and pre-release interfaces are clearly marked.
  4. Community Respect — contributions are acknowledged; experimental previews may close but knowledge remains accessible.
  5. Clear Upgrade Path — experimental work informs SAE; core NHSMM is stable and independent.

🚀 Key Features

  • Contextual HSMM — dynamic modulation of initial, transition, duration, and emission probabilities.
  • Duration Models — explicit, context-aware state dwell-times.
  • Emission Models — Gaussian, Student-t, or discrete outputs; differentiable and context-aware.
  • Transition Models — learnable, covariate-aware with gating and temperature scaling; supports low-rank factorization.
  • Hybrid HSMM-HMM Inference — forward-backward and Viterbi adapted for neural latent states.
  • Subclassable Distributions — extend Initial, Duration, Transition, Emission modules.
  • Differentiable Training — gradient-based optimization, temperature annealing, neural modulation.
  • Neural Context Encoders — CNN, LSTM, or hybrid encoders for time-varying covariates.
  • GPU-Ready — fully batched operations.
  • Multi-Domain Applicability — finance, IoT, robotics, health, cybersecurity.
  • Extensible Architecture — foundation for SAE interfaces, API integration, and research projects.
  • Hybrid Update Modes — neural gradient-based updates, optional alternative schemes.

⚡ Performance & Scalability

  • Vectorized forward-backward for batched likelihood computation.
  • Optional low-rank transitions for large state spaces.
  • Supports long sequences efficiently.
  • Memory-efficient Viterbi optimized for GPU.
  • Handles variable-length sequences with padding and masking.

📌 Milestones

Stage Status Notes
Proof of Concept ✅ Done Alpha release (0.0.1-alpha)
Testing/Enhancement ⚠️ Todo Improve performance, extend API
Production Release ⚠️ Todo Stable 1.0.0 release with documentation

📦 Installation

🔹 From PyPI (alpha stage)

pip install nhsmm

🔹 From Source (recommended)

git clone https://github.com/awa-si/NHSMM.git
cd NHSMM
pip install -e .

Editable mode allows modification and testing without reinstalling.


🧠 Usage Example — Market Regime Detection

See: State Occupancy & Duration/Transition Diagnostics

Works similarly for IoT signals, health telemetry, robotics, or cybersecurity logs.

from nhsmm.models import HSMM
model = HSMM(n_states=3, n_features=5)
seq_features, canonical = model.encoder.encode(sequences)

🔍 Conceptual Flow

External Input → Neural Initial Module (π)
                → Neural Transition Module (A)
                → Neural Duration Module (D)
                → Emission Module (Gaussian/Student-t/Discrete)
                → Forward-Backward / Viterbi → Backprop
  • External Input: features, covariates, embeddings.
  • Neural Modules: context-conditioned initial, transition, duration, and emission distributions.
  • Inference: latent states inferred via forward-backward and Viterbi.
  • Backpropagation: updates all neural modules jointly.

🌐 Multi-Domain Applicability

  • Security & Cyber-Physical Systems: anomaly and hidden state detection.
  • Finance & Trading: regime detection, forecasting, adaptive strategies.
  • IoT & Industrial: predictive maintenance, fault detection.
  • Health & Wearables: activity and state tracking, multimodal fusion.
  • Robotics: behavior monitoring, safe human-robot interaction.
  • Telecommunications & Energy: latent state monitoring, resource optimization.
  • Research & AI: temporal modeling, neural-probabilistic experiments.

⚙️ Development

Contributions welcome! Bug reports, feature suggestions, or documentation improvements strengthen NHSMM.

git clone https://github.com/awa-si/NHSMM.git
cd NHSMM
pip install -e ".[dev]"
pytest -v
black nhsmm
ruff check nhsmm

Support

Development is supported via GitHub Sponsors, Patreon, Medium. See FUNDING.md for details.


🧾 License

Apache License 2.0 © 2024 AWA.SI Full terms: LICENSE

If used in academic work, please cite the repository.

Metadata

Release files for nhsmm 0.0.4a0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nhsmm 0.0.4a0
File Size Uploaded
nhsmm-0.0.4a0.tar.gz 80.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nhsmm 0.0.4a0
File Interpreter ABI Platform
nhsmm-0.0.4a0-py3-none-any.whl Python 3 none any Details

Total release size: 119.2 kB

Release files / nhsmm-0.0.4a0.tar.gz

Download URL nhsmm-0.0.4a0.tar.gz
Size 80.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8c2efd921de93338186aec5ec17ad212a000f5abc18b5d0ff216889c3ced1399
BLAKE2b-256 checksum
How to use checksums
a9f48fa92d6f3ab6179692dc9f92edad7a2616636e41c3322c406aaa3f6c0e02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release files / nhsmm-0.0.4a0-py3-none-any.whl

Download URL nhsmm-0.0.4a0-py3-none-any.whl
Size 38.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
729fc2ae3022e42e1bd7c48530a9afccf58077c23b580e9f13175cb50e4eeb2b
BLAKE2b-256 checksum
How to use checksums
a2e4c373a456d04ec9f273c34311210b44b5c68cc780af0b0013ccff7669a723
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release history Release notifications | RSS feed

This release

0.0.4a0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page