With job_type = ms, an ave_norm_sos (column-mean sigma) objective divides each segment by that segment's own data mean, so the segmented stages fit a differently weighted objective from the one the user asked for

Open
#959 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
numpy, python
Domain
backend, data

Research direction

Start with MultipleShootingProblem._build_objective in pybnf/shooting/problem.py and follow experiment.segment_exp_data through ave_norm_sos in pybnf/objective.py and column_mean in pybnf/noise/source.py. Read _require_series_are_cuttable in pybnf/algorithms/optimizers/multiple_shooting.py and docs/gradient_fitting.rst. Done means segmented scoring matches whole-series scoring, or these settings are clearly rejected, with regression coverage.

Written by the indexing model from the issue text.

Description

bug

A multiple-shooting fit (job_type = ms) with objective = ave_norm_sos, or noise_model = gaussian, sigma = column_mean, should divide every residual by the mean of the whole data column. Instead, each segment of the time course is divided by the mean of its own rows. Late segments of a decaying curve have small means, so they get a much larger weight, and the segmented stages of the ladder converge to a different optimum. For one decay experiment the correct fit is k = 0.2900. The 4-segment stage drives k to 0.2542, which makes the real objective 47% worse (0.0893 to 0.1311), and the 2-segment stage takes it to 0.2597. The final unsegmented stage then brings k back to 0.28995, so the reported fit is close to right here. But the segmented stages are how ms chooses a basin, and here they steer away from the answer. The docs say ms refuses "any scored quantity that is a function of a whole series", and it does refuse normalization for this reason, but it accepts a column mean without a message.

Example

decay.bngl:

begin model
begin parameters
  k   0.3
  A0  100
end parameters
begin molecule types
  A()
end molecule types
begin seed species
  A()  A0
end seed species
begin observables
  Molecules  Atot  A()
end observables
begin reaction rules
  A() -> 0  k
end reaction rules
end model

tc.exp (70·e^(−0.5t) + 30·e^(−0.1t), which a single exponential cannot fit exactly, so the weighting matters):

# time	Atot
0	100
1	69.6023
2	50.3135
3	37.8437
4	29.5831
5	23.9419
6	19.9494
7	17.0114
8	14.762
9	12.9747
10	11.508

ms.conf:

edition = 2
model: decay.bngl
bngl_backend = bngsim
job_type = ms
objective = ave_norm_sos
experiment: tc, data: tc.exp
uniform_var = k 0.01 3
start_point = k 0.8
population_size = 1
max_iterations = 30
output_dir = out_ms

pybnf -c ms.conf prints stage trace: m=4: 0.0892849 m=2: 0.114791 m=1: 0.0773959. In Results/sorted_params_final.txt, listed in run order, the m = 4 stage's iterates move k from 0.2723 (objective 0.0893) to 0.25415 (0.1311). The m = 2 stage ends at k = 0.25966 (0.1148). The single m = 1 iterate is k = 0.28995 (0.0773959).

The correct numbers come from scipy on the closed form 100·e^(−kt), with PyBNF's factor of 1/2:

objective minimiser k whole-series objective there
each residual divided by the whole column's mean (what was asked for) 0.29001 0.0773958
each of 2 segments divided by its own mean 0.25966 0.1148
each of 4 segments divided by its own mean 0.25415 0.1311

The m = 4 and m = 2 stages land exactly on the minimisers of the per-segment-mean objectives. job_type = gntr with the same conf reaches k = 0.290010 (0.0773958).

The same comparison at a single point: at k = 0.3, with every continuity defect zero (so the segments join into the ordinary trajectory), the m = 2 stage scores 0.278768 and the m = 4 stage 0.385826. The single-shoot score is 0.0807138, and numpy gives the same three numbers. Under objective = sos the three agree to seven digits (100.1575), and ms with objective = sos ends at k = 0.290010, the same minimiser, because sos has no divisor. noise_model = gaussian, sigma = column_mean in place of objective = ave_norm_sos gives the same numbers as ave_norm_sos.

Why

MultipleShootingProblem._build_objective (pybnf/shooting/problem.py:409-437) presents each segment to the objective and to the gradient assembly as its own experiment, with experiment.segment_exp_data(segment) (the segment's rows only, problem.py:181-190) as its data (problem.py:426-428). ave_norm_sos computes its divisor from the data it is handed (pybnf/objective.py:2606), and so does the column_mean sigma source (pybnf/noise/source.py:649), so each segment gets its own mean. _require_series_are_cuttable (pybnf/algorithms/optimizers/multiple_shooting.py:627-670) refuses the other quantities computed over a whole series (normalization, an analytic scale, cumulative columns, constraints) but not a column mean. docs/gradient_fitting.rst:219-223 describes that list as refusing "any scored quantity that is a function of a whole series". Reported scores are not affected: certify (problem.py:554-580) re-scores each whole series, which is why the stage trace and sorted_params_final.txt show genuine single-shoot values.

Possible fix

A column mean depends only on the data, so it can be computed once per experiment from the whole series and used for every segment. The segmented objective at a continuous trajectory would then equal the ordinary one, as it already does for sos. Failing that, refuse ave_norm_sos and any sigma = column_mean in _require_series_are_cuttable, with a test either way.

Related: #913 (the final m = 1 stage stops at a loose tolerance, which limits how much of this the last stage can undo)

Found while fixing the PEtab issues #892–#908 (2026-09-25); reproduced on main at 5ecb1f69.

Dominant language
Python
Stars
25
Forks
25
Avg merge
4h 5m
Merged PRs (30d)
10

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lanl/PyBNF

All issues in lanl/PyBNF

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.