Skip to content

refactor: Remove likelihood calculation#291

Open
Siel wants to merge 4 commits into
mainfrom
feature/likelihood-extraction
Open

refactor: Remove likelihood calculation#291
Siel wants to merge 4 commits into
mainfrom
feature/likelihood-extraction

Conversation

@Siel

@Siel Siel commented Jul 15, 2026

Copy link
Copy Markdown
Member

No description provided.

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpharmsol
Branchfeature/likelihood-extraction
Testbedmhovd-pgx
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
nanoseconds (ns)
(Result Δ%)
Upper Boundary
nanoseconds (ns)
(Limit %)
dsl/compile/1cpt-12h-po/analytical/dsl-jit📈 view plot
🚷 view threshold
48,375.00 ns
(-6.86%)Baseline: 51,939.48 ns
70,138.22 ns
(68.97%)
dsl/compile/1cpt-12h-po/ode/dsl-jit📈 view plot
🚷 view threshold
81,941.00 ns
(-6.33%)Baseline: 87,477.63 ns
102,326.24 ns
(80.08%)
dsl/compile/2cpt-120h-q12h/analytical/dsl-jit📈 view plot
🚷 view threshold
49,245.00 ns
(-4.74%)Baseline: 51,696.52 ns
69,204.48 ns
(71.16%)
dsl/compile/2cpt-120h-q12h/ode/dsl-jit📈 view plot
🚷 view threshold
101,390.00 ns
(-6.26%)Baseline: 108,165.41 ns
144,391.75 ns
(70.22%)
dsl/predictions/1cpt-12h-po/analytical/dsl-jit/cold📈 view plot
🚷 view threshold
2,214.60 ns
(-2.94%)Baseline: 2,281.68 ns
2,495.30 ns
(88.75%)
dsl/predictions/1cpt-12h-po/analytical/dsl-jit/hot📈 view plot
🚷 view threshold
379.96 ns
(-83.72%)Baseline: 2,333.69 ns
2,539.97 ns
(14.96%)
dsl/predictions/1cpt-12h-po/ode/dsl-jit/cold📈 view plot
🚷 view threshold
24,339.00 ns
(+0.81%)Baseline: 24,144.26 ns
25,025.56 ns
(97.26%)
dsl/predictions/1cpt-12h-po/ode/dsl-jit/hot📈 view plot
🚷 view threshold
386.58 ns
(-69.46%)Baseline: 1,265.78 ns
13,076.24 ns
(2.96%)
dsl/predictions/2cpt-120h-q12h/analytical/dsl-jit/cold📈 view plot
🚷 view threshold
4,065.50 ns
(-6.18%)Baseline: 4,333.11 ns
4,705.75 ns
(86.39%)
dsl/predictions/2cpt-120h-q12h/analytical/dsl-jit/hot📈 view plot
🚷 view threshold
545.92 ns
(-87.29%)Baseline: 4,296.44 ns
4,702.83 ns
(11.61%)
dsl/predictions/2cpt-120h-q12h/ode/dsl-jit/cold📈 view plot
🚷 view threshold
90,155.00 ns
(-2.18%)Baseline: 92,167.22 ns
94,831.25 ns
(95.07%)
dsl/predictions/2cpt-120h-q12h/ode/dsl-jit/hot📈 view plot
🚷 view threshold
546.54 ns
(-86.24%)Baseline: 3,970.69 ns
49,343.17 ns
(1.11%)
native/predictions/1cpt-12h-po/analytical/handwritten/cold📈 view plot
🚷 view threshold
1,804.20 ns
(+1.02%)Baseline: 1,786.01 ns
1,921.53 ns
(93.89%)
native/predictions/1cpt-12h-po/analytical/handwritten/hot📈 view plot
🚷 view threshold
322.52 ns
(-81.96%)Baseline: 1,787.81 ns
1,916.73 ns
(16.83%)
native/predictions/1cpt-12h-po/analytical/macro/cold📈 view plot
🚷 view threshold
1,780.10 ns
(+1.46%)Baseline: 1,754.56 ns
1,911.63 ns
(93.12%)
native/predictions/1cpt-12h-po/analytical/macro/hot📈 view plot
🚷 view threshold
318.47 ns
(-82.10%)Baseline: 1,779.21 ns
1,914.42 ns
(16.64%)
native/predictions/1cpt-12h-po/ode/handwritten/cold📈 view plot
🚷 view threshold
22,136.00 ns
(+0.01%)Baseline: 22,134.11 ns
22,930.63 ns
(96.53%)
native/predictions/1cpt-12h-po/ode/handwritten/hot📈 view plot
🚷 view threshold
280.76 ns
(+2.19%)Baseline: 274.75 ns
400.40 ns
(70.12%)
native/predictions/1cpt-12h-po/ode/macro/cold📈 view plot
🚷 view threshold
21,935.00 ns
(-0.85%)Baseline: 22,122.48 ns
22,599.42 ns
(97.06%)
native/predictions/1cpt-12h-po/ode/macro/hot📈 view plot
🚷 view threshold
369.41 ns
(+7.70%)Baseline: 342.99 ns
429.50 ns
(86.01%)
native/predictions/2cpt-120h-q12h/analytical/handwritten/cold📈 view plot
🚷 view threshold
4,116.20 ns
(+4.24%)Baseline: 3,948.79 ns
4,274.46 ns
(96.30%)
native/predictions/2cpt-120h-q12h/analytical/handwritten/hot📈 view plot
🚷 view threshold
598.21 ns
(-84.83%)Baseline: 3,942.43 ns
4,233.48 ns
(14.13%)
native/predictions/2cpt-120h-q12h/analytical/macro/cold📈 view plot
🚷 view threshold
4,027.20 ns
(+3.58%)Baseline: 3,888.13 ns
4,152.97 ns
(96.97%)
native/predictions/2cpt-120h-q12h/analytical/macro/hot📈 view plot
🚷 view threshold
594.14 ns
(-84.72%)Baseline: 3,887.53 ns
4,140.53 ns
(14.35%)
native/predictions/2cpt-120h-q12h/ode/handwritten/cold📈 view plot
🚷 view threshold
58,896.00 ns
(-30.66%)Baseline: 84,943.74 ns
87,389.81 ns
(67.39%)
native/predictions/2cpt-120h-q12h/ode/handwritten/hot📈 view plot
🚷 view threshold
587.10 ns
(+12.69%)Baseline: 520.98 ns
611.84 ns
(95.96%)
native/predictions/2cpt-120h-q12h/ode/macro/cold📈 view plot
🚷 view threshold
60,026.00 ns
(-29.68%)Baseline: 85,358.85 ns
87,237.33 ns
(68.81%)
native/predictions/2cpt-120h-q12h/ode/macro/hot📈 view plot
🚷 view threshold
568.84 ns
(+9.45%)Baseline: 519.73 ns
613.68 ns
(92.69%)
sde/simulation/session-retain📈 view plot
🚷 view threshold
1,206,700.00 ns
sde/simulation/session-select-ancestors📈 view plot
🚷 view threshold
1,232,000.00 ns
sde/simulation/standard-prediction📈 view plot
🚷 view threshold
773,540.00 ns
🐰 View full continuous benchmarking report in Bencher

Comment thread .github/workflows/build.yml Outdated
- name: Check formatting
run: cargo fmt --all -- --check

- name: Check simulation ownership boundary

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

Comment thread src/simulator/cache.rs
}

/// Create an empty cache with the same capacity but no shared entries.
pub(crate) fn detached(&self) -> Self {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename to e.g. reset?
With documentation comment

/// Reset the cache
///
/// Creates a new, unique cache that is not shared with caches from potentially linked equations

Comment thread src/data/event.rs
/// * `value` - Observed value (e.g., drug concentration)
/// * `outeq` - Output label corresponding to this observation
/// * `errorpoly` - Optional error polynomial coefficients (c0, c1, c2, c3)
/// * `errorpoly` - Optional C0-C3 data

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the old errorpoly - Optional error polynomial coefficients (c0, c1, c2, c3)

Comment thread src/data/event.rs
}

/// Set the [ErrorPoly] for this observation
/// Set the [`ErrorPoly`] data for this observation.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Set the [`ErrorPoly`] data for this observation.
/// Set the [`ErrorPoly`] coefficients for this observation.

Comment thread src/data/event.rs
}

/// Get a mutable reference to the error polynomial
/// Get a mutable reference to the optional [`ErrorPoly`] data.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Get a mutable reference to the optional [`ErrorPoly`] data.
/// Get a mutable reference to the optional [`ErrorPoly`] coefficients.

Comment on lines 97 to +104

/// Calculate the log-likelihood of the predictions given an error model.
///
/// This is numerically more stable than computing the likelihood and taking its log,
/// especially for extreme values or many observations.
///
/// # Parameters
/// - `error_models`: The error models for computing observation variance
///
/// # Returns
/// The sum of log-likelihoods for all predictions
fn log_likelihood(&self, error_models: &AssayErrorModels) -> Result<f64, PharmsolError>;
/// Visit each effective prediction without requiring callers to own a `Vec`.
fn for_each_prediction(&self, mut f: impl FnMut(&Prediction)) {
let predictions = self.get_predictions();
for prediction in &predictions {
f(prediction);
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this preferred over implementing a mutable iterator?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps at least do both

pub(crate) prediction: f64,
pub(crate) outeq: usize,
pub(crate) errorpoly: Option<ErrorPoly>,
pub(crate) state: Vec<f64>,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR, but is there mapping of state index to metadata state name?

Comment on lines +15 to +17
pub struct SubjectPredictions {
predictions: Vec<Prediction>,
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we have had this structure for some time, but I am a little torn about it.
My biggest gripe is that it is disconnected from the data and subject from and for which it was generated.
Would it make sense to have predictions as part of the data?
Or as part of the Observation? I don't know.

Comment thread src/lib.rs
Comment on lines +21 to +22
//! metadata, and NCA. Estimation crates own scoring, objectives, priors,
//! algorithms, diagnostics, covariance, and fit semantics.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! metadata, and NCA. Estimation crates own scoring, objectives, priors,
//! algorithms, diagnostics, covariance, and fit semantics.
//! metadata, and NCA.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the documentation is leaking prompt details

Comment thread CHANGELOG.md Outdated
Comment on lines +9 to +33

## [0.28.1](https://github.com/LAPKB/pharmsol/compare/pharmsol-v0.28.0...pharmsol-v0.28.1) - 2026-07-13
### Added

### Fixed
- Add a caller-controlled, simulation-neutral SDE particle session that pauses
at observation boundaries and can resume with retained or replaced states.
- Add focused Criterion coverage for standard SDE prediction and particle-session
retain/select paths.

### Removed

- Remove equation-level and prediction-container observation evaluation APIs;
downstream fitting crates now generate predictions with pharmsol and evaluate
observations themselves.
- Remove residual-distribution declarations, estimator caches, and parameter
optimization helpers from pharmsol's public API.

### Changed

- Fix data expansion ([#282](https://github.com/LAPKB/pharmsol/pull/282))
- Relocate the existing data-only `ErrorPoly` DTO while preserving its public
path and unchanged C0-C3 transport through observations and predictions.
As before, incomplete C0-C3 rows do not create an `ErrorPoly` value.
- Keep analytical, ODE, and SDE execution focused exclusively on simulation and
prediction generation, including simulation-only examples and benchmarks.
- Run the source-scoped simulation ownership check in CI, including untracked
source files during local use.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PRs should not modify CHANGELOG directly

@mhovd mhovd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

@mhovd mhovd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

@mhovd mhovd changed the title Likelihood extraction refactor: Remove likelihood calculation Jul 21, 2026
@Siel
Siel force-pushed the feature/likelihood-extraction branch from 0b1ab2d to 027fd4d Compare July 21, 2026 21:05
@mhovd

mhovd commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator
  • Add subject ID to the predictions
  • Make sure to expand subjects with outeq from model metadata, then we can remove State from Prediction.
  • Remove progress artifacts and references

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.

2 participants