feat: extend SegmentalKMeansTrainer to MV via BasicSegmentalKMeansTrainer<Obs> (closes #36)#37
Merged
Merged
Conversation
5882c1e to
865051a
Compare
…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>
865051a to
20e89e5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 sameBasicTrainer<Obs>pattern asBasicBaumWelchTrainerandBasicViterbiTrainer. Uses per-sequence/per-timestep state assignments (replacing theClustershash-map), which correctly handles observations mapping to different states at different times.SegmentalKMeansTrainerMV = BasicSegmentalKMeansTrainer<ObservationVectorView>— trainsHmmMVwithDiagonalGaussianDistribution,FullCovarianceGaussianDistribution, orIndependentComponentsDistribution.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_init→SegmentalKMeansTrainerMV→BasicBaumWelchTrainer<OVV>.Changed
SegmentalKMeansTraineris nowusing SegmentalKMeansTrainer = BasicSegmentalKMeansTrainer<double>. The discrete-only restriction is removed; the genericfit()M-step works with any scalarEmissionDistribution. 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.cpp—RequiresDiscreteDistributions→AcceptsAnyScalarDistribution.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