Repository navigation
Fix review bugs and iterate contour alignment - #13
Merged
Merged
Conversation
- Vampire keeps at least 2 principal components: with one, the Normalizer maps every score to +1 or -1 and K-means finds at most two modes. An integer n_components < 2 raises; a variance fraction reached by one component keeps 2. - Vampire.fit raises when K-means leaves a shape mode empty instead of filling it with the overall mean contour. - Vampire.score is minus the mean squared point distance of each normalized contour to its mode's mean contour, so it no longer depends on n_components (inertia_ still does). - extract_properties: min_area and exclude_border options; circularity is NaN instead of inf for zero perimeter. - read_images skips hidden files (macOS ._name.tif) and names the file when one cannot be read. - ContourAligner refines its reference by generalized Procrustes analysis (max_iter=30, tol=1e-6, n_iter_); max_iter=1 keeps the single pass. Integration golden data regenerated: iterative alignment intentionally changes the example-image fit (n_components_ 20 -> 21, new mode sizes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
Fixes from the code review, plus iterative (generalized Procrustes) alignment.
Bugs
Normalizer, one PC maps every contour to +1 or -1, so K-means found at most 2 modes and empty modes were silently filled with the overall mean contour.Vampirenow keeps at least 2 PCs (an intn_components < 2raises; a variance fraction reached by one PC keeps 2), andfitraises when K-means leaves a mode empty.read_imagescrashed on hidden files such as macOS._name.tifsidecars. Hidden files are skipped; unreadable files raiseOSErrornaming the file.extract_properties(min_area=...);circularityisNaNinstead ofinffor zero perimeter.extract_properties(exclude_border=True)(skimage.segmentation.clear_border).scoredepended onn_components(it was minus the K-means inertia in normalized PC space). It is now minus the mean squared point distance of each normalized contour to its mode's mean contour;inertia_is unchanged.Improvement
ContourAligner(max_iter=30, tol=1e-6)refines the reference by aligning to the mean, recomputing the mean, and repeating; passes are stored inn_iter_, andmax_iter=1keeps the old single pass. On the example images it converges in 12 passes and lowers the mean squared spread around the mean from 4.65 to 4.19.Changed results: the example-image fit now keeps 21 components instead of 20 and has different mode sizes;
tests/data/integration_golden.npzwas regenerated for this intentional change.Docs (method, choosing shape modes, data conventions, GUI differences, tutorial, agent summary) and the changelog are updated.
Test plan
uv run pytest: 358 passed (new tests for each fix and for alignment convergence, spread reduction and reference drift)ruff check/ruff format --checksphinx-build -E -W --keep-goingpasses; executed outputs checked against the prose🤖 Generated with Claude Code