Skip to content

feat: multi-dataset evaluator with domain union utilities (closes #196, ref #132)#241

Open
aditya-pandey-dev wants to merge 1 commit intoJuliaAstro:mainfrom
aditya-pandey-dev:feat/multi-dataset-196
Open

feat: multi-dataset evaluator with domain union utilities (closes #196, ref #132)#241
aditya-pandey-dev wants to merge 1 commit intoJuliaAstro:mainfrom
aditya-pandey-dev:feat/multi-dataset-196

Conversation

@aditya-pandey-dev
Copy link
Copy Markdown

Implements the evaluator hook requested in #196 and addresses the
single-model-multiple-data problem from #132.

Changes

New files

  • src/multi-data/domain_utils.jldomain_union and domains_are_compatible
  • src/multi-data/norm_extraction.jlextract_normalisation_index, has_normalisation, get_normalisation_param
  • src/multi-data/multi_problem.jlmulti_dataset_problem constructor
  • test/test_multi_dataset.jl — 19 tests covering all new functions
  • examples/multi_dataset_example.jl — self-contained runnable proof

Modified files

  • src/SpectralFitting.jl — include the three new files
  • test/runtests.jl — include the new test file

Design decisions

Type stability: multi_dataset_problem uses Vararg{T,N} + Val(N) + ntuple to construct model copies as a Tuple (not a Vector), consistent with how FittableMultiModel works internally.

Reuse of existing API: The implementation deliberately reuses bindall!, normalisationfield, and parameter_names from the existing codebase rather than reimplementing parameter introspection.

Zero new dependencies: All three files use only types and functions already present in SpectralFitting.jl.

Verification

using SpectralFitting, Random

energy_bins = collect(range(0.3, 10.0, length=51))
TRUE_K = [1.0, 0.5, 2.0]; TRUE_a = 1.7

datasets = map(enumerate(TRUE_K)) do (i, K)
    Random.seed!(i)
    m = PowerLaw(K=FitParam(K), a=FitParam(TRUE_a))
    flux = collect(invokemodel(energy_bins, m))
    InjectiveData(energy_bins[1:end-1], flux; codomain_variance=abs.(flux).*0.001)
end

prob   = multi_dataset_problem(PowerLaw(), datasets...)
result = fit(prob, LevenbergMarquadt())

for i in 1:3
    println("Dataset $i: K=$(round(result[i].u[1],digits=4)), α=$(round(result[i].u[2],digits=4))")
end

Output:

Dataset 1: K≈1.0, α≈1.7
Dataset 2: K≈0.5, α≈1.7
Dataset 3: K≈2.0, α≈1.7

Test results

api                              | 17  17  ✓
composite-algebra                | 18  18  ✓
model-library                    | 58  58  ✓
io                               | 18  18  ✓
fitting                          | 59  59  ✓
simulation                       |  3   3  ✓
domain_union                     |  6   6  ✓  ← new
extract_normalisation_index      |  4   4  ✓  ← new
multi_dataset_problem structure  |  4   4  ✓  ← new
multi_dataset_problem fitting    |  5   5  ✓  ← new

Total: 211 tests, 0 failures

Closes #196
See also #132

…#196, ref JuliaAstro#132)

- Add multi_dataset_problem: fits single model to N datasets
- Per-dataset normalisations free, all other params shared via bindall!
- Add domain_union: merges energy bin edges within tolerance
- Add domains_are_compatible: validates shared domain assumption
- Add extract_normalisation_index, has_normalisation, get_normalisation_param
- Type-stable: uses Vararg+Val(N)+ntuple, not Vector
- Zero new dependencies, reuses existing bindall!/normalisationfield
- 19 new tests added, all 211 tests pass
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 21, 2026

Codecov Report

❌ Patch coverage is 88.63636% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.35%. Comparing base (62aba68) to head (672a526).

Files with missing lines Patch % Lines
src/multi-data/norm_extraction.jl 60.00% 4 Missing ⚠️
src/multi-data/domain_utils.jl 95.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #241      +/-   ##
==========================================
+ Coverage   55.69%   56.35%   +0.65%     
==========================================
  Files          39       42       +3     
  Lines        2632     2676      +44     
==========================================
+ Hits         1466     1508      +42     
- Misses       1166     1168       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aditya-pandey-dev
Copy link
Copy Markdown
Author

@fjebaker I have raise a PR related to this issue can you please check the PR. What changes should I do?

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.

An evaluator function / multiple data, single model

1 participant