pytorch_hamiliton

Implements Tunbridge-style Bayesian inference for the Higgs boson's mass and width using a Markov Chain Monte Carlo enginebbaased on the Shew-Young algorithm.

Updated May 21, 2026
One-click install
npx skills add https://github.com/ulf1/trading-regime --skill pytorch-hamiliton
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytorch_hamiliton
Source: https://github.com/ulf1/trading-regime/tree/main/.agent/skills/899_pytorch_hamiliton
Command: npx skills add https://github.com/ulf1/trading-regime --skill pytorch-hamiliton

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes assets (resource) components.

What problem does it solve?

This Skill solves the difficulty of implementing a batched, high-performance Markov Regime-Switching (MRS) model in PyTorch while keeping parameters mathematically valid and training numerically stable.

Core Features & Use Cases

  • Batched Hamilton Filter in PyTorch: Computes negative log-likelihood and filtered regime probabilities across many independent time series using tensor operations (e.g., batched matrix multiplications).
  • Constraint-safe parameterization: Enforces strictly positive variances via exponential transforms and stochastic transition matrices via softmax parameterization so gradients remain valid.
  • Identifiability via regime sorting: Applies post-training regime permutation by descending state means to resolve label-switching, enabling consistent Bull/Neutral/Bear interpretation.
  • Numerical stability guardrails: Uses float64 guidance, epsilon padding, and log-likelihood safeguards to reduce underflow/overflow during likelihood updates.

Quick Start

Use the pytorch_hamiliton skill to implement a vectorized Hamilton filter MRS model for T time steps, N parallel asset series, and K regimes, then train it with gradient-based optimization using constrained parameters.

Frequently Asked Questions about pytorch_hamiliton

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement a batched Markov regime-switching model in PyTorch for multiple financial time series?

Implement a batched Markov regime-switching model by using a vectorized Hamilton filter with torch.bmm operations. This computes negative log-likelihood and filtered regime probabilities across many independent financial time series simultaneously.

How does a Hamilton filter handle numerical stability during likelihood training?

Hamilton filter numerical stability is maintained through float64 guidance, epsilon padding, and log-likelihood safeguards. These guardrails prevent underflow and overflow during likelihood updates in the Markov regime-switching training process.

How do I resolve label switching in Markov regime-switching models for consistent Bull and Bear regime interpretation?

Resolve label switching in Markov regime-switching models by applying post-training regime permutation. Sorting regimes by descending state means ensures consistent Bull, Neutral, and Bear regime interpretation across financial time series.

Can I use softmax and exponential reparameterization to train stochastic transition matrices in PyTorch?

Softmax and exponential reparameterization enforce strictly positive variances and stochastic transition matrices in PyTorch. This constraint-safe parameterization ensures gradients remain mathematically valid during negative log-likelihood training.

What is the best way to estimate next-step transition probabilities for parallel asset return series?

Estimate next-step transition probabilities for parallel asset return series by applying a vectorized Hamilton filter. The model outputs next-step transition predictions alongside filtered regime probabilities for multiple independent market-return series.

Why does my Markov regime-switching model fail to identify separate regimes across different time series?

Markov regime-switching models fail to identify separate regimes due to label switching during training. Applying post-training regime sorting by descending state means resolves this identifiability issue for consistent regime interpretation.