Skip to content

feat: extend SegmentalKMeansTrainer to MV via BasicSegmentalKMeansTrainer<Obs> (closes #36)#37

Merged
OldCrow merged 1 commit into
mainfrom
feat/basic-segmental-kmeans-trainer
Jul 4, 2026
Merged

feat: extend SegmentalKMeansTrainer to MV via BasicSegmentalKMeansTrainer<Obs> (closes #36)#37
OldCrow merged 1 commit into
mainfrom
feat/basic-segmental-kmeans-trainer

Conversation

@OldCrow

@OldCrow OldCrow commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Closes #36.

Summary

Introduces BasicSegmentalKMeansTrainer<Obs>, completing the template-parameterised trainer family for both scalar and multivariate HMMs.

What changed

New

  • include/libhmm/training/basic_segmental_kmeans_trainer.h — header-only template following the exact same BasicTrainer<Obs> pattern as BasicBaumWelchTrainer and BasicViterbiTrainer. Uses per-sequence/per-timestep state assignments (replacing the Clusters hash-map), which correctly handles observations mapping to different states at different times.
  • SegmentalKMeansTrainerMV = BasicSegmentalKMeansTrainer<ObservationVectorView> — trains HmmMV with DiagonalGaussianDistribution, FullCovarianceGaussianDistribution, or IndependentComponentsDistribution.
  • src/training/segmental_kmeans_trainer_mv.cpp — explicit MV instantiation.
  • tests/training/test_segmental_kmeans_mv.cpp — 12 test cases.
  • examples/segmental_kmeans_mv_example.cpp — demonstrates the recommended warm-start workflow: kmeans_initSegmentalKMeansTrainerMVBasicBaumWelchTrainer<OVV>.

Changed

  • SegmentalKMeansTrainer is now using SegmentalKMeansTrainer = BasicSegmentalKMeansTrainer<double>. The discrete-only restriction is removed; the generic fit() M-step works with any scalar EmissionDistribution. Existing code is unaffected.
  • segmental_kmeans_example.cpp — constraint-demo section (which would now return exit code 1) replaced with a Gaussian Path C.
  • test_canonical_training.cppRequiresDiscreteDistributionsAcceptsAnyScalarDistribution.
  • Version bump 4.1.3 → 4.2.0.

Test results

47/47 tests pass on Windows/MSVC 2022 (all pre-commit hooks pass).


Generated with Warp
Plan: feat: BasicSegmentalKMeansTrainer — multivariate support (Issue #36)

Co-Authored-By: Oz oz-agent@warp.dev

@OldCrow OldCrow force-pushed the feat/basic-segmental-kmeans-trainer branch from 5882c1e to 865051a Compare July 4, 2026 15:36
…iner<Obs> (closes #36)

Introduces BasicSegmentalKMeansTrainer<Obs> following the same BasicTrainer<Obs>
pattern as BasicBaumWelchTrainer and BasicViterbiTrainer.

Key changes:
- New BasicSegmentalKMeansTrainer<Obs> template header with all logic inline;
  uses per-sequence/per-timestep state assignments instead of the Clusters hash-map,
  which correctly handles the same observation value mapping to different states.
- SegmentalKMeansTrainer = BasicSegmentalKMeansTrainer<double> (scalar alias,
  backward-compatible). Discrete-only restriction lifted; generic fit() M-step
  accepts any scalar EmissionDistribution.
- SegmentalKMeansTrainerMV = BasicSegmentalKMeansTrainer<ObservationVectorView>
  (new MV alias). Trains HmmMV with DiagonalGaussian, FullCovGaussian, or
  IndependentComponents emissions.
- maxIterations parameter (default 100) bounds iteration count for continuous data.
- New test_segmental_kmeans_mv.cpp: 12 test cases covering construction, null/empty
  guards, MV training, log-prob non-degradation, and scalar alias regression.
- New segmental_kmeans_mv_example.cpp: demonstrates the recommended MV warm-start
  workflow (kmeans_init -> SegmentalKMeansTrainerMV -> BaumWelchTrainer<OVV>).
- Updated segmental_kmeans_example.cpp: replaces the broken constraint-demo
  section with a Gaussian Path C.
- test_canonical_training.cpp: RequiresDiscreteDistributions -> AcceptsAnyScalarDistribution.
- Version bump 4.1.3 -> 4.2.0. 47/47 tests pass.

Co-Authored-By: Oz <oz-agent@warp.dev>
@OldCrow OldCrow force-pushed the feat/basic-segmental-kmeans-trainer branch from 865051a to 20e89e5 Compare July 4, 2026 15:40
@OldCrow OldCrow merged commit c23d24d into main Jul 4, 2026
7 checks passed
@OldCrow OldCrow deleted the feat/basic-segmental-kmeans-trainer branch July 4, 2026 15:50
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.

feat: extend SegmentalKMeansTrainer to multivariate via ObsSeqTraits (M-6)

1 participant