Add likelihood ratio (LR) calculation endpoints for striation and impression marks#149
Merged
Add likelihood ratio (LR) calculation endpoints for striation and impression marks#149
Conversation
SimoneAriens
requested changes
Feb 24, 2026
Collaborator
SimoneAriens
left a comment
There was a problem hiding this comment.
see comments, some parts can be imported from lir or lr_module_scratch and some should be moved to conversion
SimoneAriens
reviewed
Mar 3, 2026
SimoneAriens
reviewed
Mar 3, 2026
SimoneAriens
reviewed
Mar 3, 2026
SimoneAriens
reviewed
Mar 3, 2026
packages/scratch-core/tests/computations/test_likelihood_ratio.py
Outdated
Show resolved
Hide resolved
SimoneAriens
reviewed
Mar 3, 2026
packages/scratch-core/tests/computations/test_likelihood_ratio.py
Outdated
Show resolved
Hide resolved
SimoneAriens
reviewed
Mar 3, 2026
SimoneAriens
reviewed
Mar 3, 2026
SimoneAriens
reviewed
Mar 3, 2026
SimoneAriens
reviewed
Mar 3, 2026
SimoneAriens
reviewed
Mar 3, 2026
SimoneAriens
reviewed
Mar 3, 2026
SimoneAriens
requested changes
Mar 10, 2026
Collaborator
SimoneAriens
left a comment
There was a problem hiding this comment.
almost there, mostly cosmetic changes
SimoneAriens
approved these changes
Mar 10, 2026
vergep
requested changes
Mar 10, 2026
Collaborator
vergep
left a comment
There was a problem hiding this comment.
- We need to be careful whether LR_system.apply needs score or transformed_score.
For the rest minor comments.
Diff CoverageDiff: origin/main..HEAD, staged and unstaged changes
Summary
packages/scratch-core/src/conversion/likelihood_ratio.pyLines 37-47 37
38 @model_validator(mode="after")
39 def _validate_matching_lengths(self) -> Self:
40 if len(self.km_scores) != len(self.km_llrs):
! 41 raise ValueError("km_scores and km_lrs must have the same length")
42 if len(self.knm_scores) != len(self.knm_llrs):
! 43 raise ValueError("knm_scores and knm_lrs must have the same length")
44 return self
45
46 @property
47 def scores(self) -> np.ndarray:Lines 56-64 56 @property
57 def llr_intervals(self) -> np.ndarray:
58 """Concatenated KM and KNM LLR intervals, shape (n, 2)."""
59 if self.km_llr_intervals is None or self.knm_llr_intervals is None:
! 60 raise ValueError("Only models with llr_intervals can be used")
61 return np.concatenate([self.km_llr_intervals, self.knm_llr_intervals], axis=0)
62
63 @property
64 def labels(self) -> np.ndarray:packages/scratch-core/src/conversion/plots/utils.pyLines 394-408 394
395 def _format_lr(llr_data: LLRData) -> str:
396 """Format a single log-LR value with optional confidence interval."""
397 if len(llr_data.llrs) > 1:
! 398 raise ValueError(f"expected single LR value, got {len(llr_data.llrs)}")
399
400 log_lr = llr_data.llrs[0]
401
402 if llr_data.llr_intervals is not None:
! 403 lower, upper = llr_data.llr_intervals[0, 0], llr_data.llr_intervals[0, 1]
! 404 return f"{log_lr:.2f} ({lower:.2f}, {upper:.2f})"
405 return f"{log_lr:.2f}"
406
407
408 def _common_results_metadata(src/processors/router.pyLines 63-71 63 include_in_schema=False,
64 )
65 async def calculate_score_impression(impression: CalculateScore) -> ComparisonResponseImpression:
66 """Compare two impression profiles."""
! 67 vault = create_vault(impression.tag)
68 return ComparisonResponseImpression.generate_urls(vault.access_url)
69
70
71 @processors.post( |
Minimum allowed line rate is |
vergep
approved these changes
Mar 10, 2026
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.
This PR implements the LR calculation pipeline for both striation (CCF-based) and impression (CMC-based) mark comparisons, replacing placeholder stubs with real logic.
Core changes:
model holding KM/KNM scores and LLRs. Reference data is currently hardcoded dummy data pending lr_module_scratch integration.
overviews with histograms and LLR transformation curves).
(JSON-serialisable mirror of ImpressionComparisonMetrics), adds validation (score ≤ n_cells, score range [-1, 1]).