Skip to content

Roadmap #3: optimize GaussianNB.predict #212

Closed

Description

@godofecht

Source: benchmarks/OPTIMIZATION_ROADMAP.md rank 3. GaussianNB.predict; python-bound; score 73.6; rewrite first; observed Flow speedup 11.03×. Hypothesis: remove Python control/validation and specialize the complete operation. Preserve sklearn parity, benchmark, and update roadmap evidence before closing.

Implementation evidence

PR #317 (stacked on #316 while GaussianNB.fit lands) specializes the prediction hot loop by precomputing class log-priors, per-class-feature Gaussian normalization terms, and inverse twice-variance terms once per call. It also uses direct row-major Matrix.data reads rather than matrix_at in the inner loop. Fitted state and fit latency are unchanged.

A dedicated regression test checks prediction ordering, posterior normalization, midpoint symmetry, and probability ranking.

Scaled benchmark evidence from #317 push run 32017851050 versus the exact #316 base run 32017435901 shows GaussianNB prediction latency improvements at every measured size:

  • 100 × 8: 0.022182 ms → 0.012734 ms (1.74× faster; 42.6% lower)
  • 100 × 32: 0.043031 ms → 0.012052 ms (3.57× faster; 72.0% lower)
  • 1,000 × 8: 0.113413 ms → 0.029055 ms (3.90× faster; 74.4% lower)
  • 1,000 × 32: 0.425967 ms → 0.111510 ms (3.82× faster; 73.8% lower)
  • 10,000 × 8: 0.810158 ms → 0.213171 ms (3.80× faster; 73.7% lower)
  • 10,000 × 32: 3.138418 ms → 0.743859 ms (4.22× faster; 76.3% lower)

The scaled self-baseline gate passed on the implementation. Keep open until #316 lands, #317 is retargeted/merged, and final parity/evidence checks complete.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions