Skip to content

Addition of non-uniform priors.#211

Open
arm61 wants to merge 11 commits into
mainfrom
issue-143
Open

Addition of non-uniform priors.#211
arm61 wants to merge 11 commits into
mainfrom
issue-143

Conversation

@arm61

@arm61 arm61 commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

This PR implements the ability to pass arbitrary scipy.stats objects as priors. This means that non-uniform priors can be passed to different FittingBase objects.

However, to achieve this, I have removed the bounds keyword argument, which is an API change; hence, this will be a part of a 2.1.0 release to account for this.

Closes #143

@arm61 arm61 changed the title Additional of non-uniform priors. Addition of non-uniform priors. Jun 17, 2026
@arm61 arm61 requested review from PythonFZ, bjmorgan and Copilot June 17, 2026 13:43
@arm61 arm61 requested review from Harry-Rich and jd15489 June 17, 2026 13:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR replaces parameter bounds with support for arbitrary scipy.stats frozen distributions as priors across FittingBase-derived fitting classes, enabling non-uniform priors (per #143) and updating tests/docs accordingly.

Changes:

  • Introduce priors support in FittingBase and propagate it through Arrhenius/VTF and Yeh-Hummer fitting.
  • Add/adjust unit tests to cover prior initialization and usage.
  • Update Arrhenius tutorial documentation to demonstrate providing priors.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
kinisi/fitting.py Replaces bounds-based configuration with prior distributions; adds MAP objective and validation.
kinisi/arrhenius.py Switches Arrhenius/VTF wrappers to pass priors into FittingBase.
kinisi/yeh_hummer.py Updates YehHummer to accept priors and passes them to FittingBase; adjusts default prior construction.
kinisi/tests/test_fitting.py Adds new unit tests for FittingBase priors and sampling.
kinisi/tests/test_arrhenius.py Updates Arrhenius/VTF tests to use priors instead of bounds.
kinisi/tests/test_yeh_hummer.py Updates YehHummer tests to exercise custom priors and invalid priors.
docs/source/arrhenius_t.ipynb Updates tutorial to demonstrate priors-based API and explain scipy.stats.uniform.
Comments suppressed due to low confidence (3)

kinisi/tests/test_yeh_hummer.py:67

  • Leftover debug print statements in the test will pollute test output and can cause CI noise/failures when output is asserted.
        assert 1e-4 < yh.shear_viscosity.value < 1e-2

    def test_yeh_hummer_mcmc(self):

kinisi/arrhenius.py:161

  • VogelFulcherTammann.__init__ still uses a bounds-like type annotation for priors, but FittingBase expects a sequence of frozen scipy.stats distributions. The current annotation is inconsistent with runtime validation.
    def __init__(
        self,
        diffusion,
        priors: tuple[
            tuple[VariableLike, VariableLike], tuple[VariableLike, VariableLike], tuple[VariableLike, VariableLike]
        ]
        | None = None,
    ) -> 'VogelFulcherTammann':

kinisi/fitting.py:204

  • max_aposteriori is annotated to return tuple[float] but currently returns None. Returning the fitted parameters keeps the API consistent with the type hint and with max_likelihood.
            self.data_group[name] = result[i] * self.parameter_units[i]

    def mcmc(self, n_samples: int = 1000, n_walkers: int = 32, n_burn: int = 500, n_thin=10) -> None:
        """

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread kinisi/yeh_hummer.py
Comment thread kinisi/yeh_hummer.py Outdated
Comment thread kinisi/yeh_hummer.py
Comment thread kinisi/tests/test_arrhenius.py Outdated
Comment thread kinisi/arrhenius.py
Comment thread kinisi/fitting.py Outdated
Comment thread kinisi/fitting.py Outdated
Comment on lines +191 to +194
result = minimize(self.nll, x0).x
for i, name in enumerate(self.parameter_names):
self.data_group[name] = result[i] * self.parameter_units[i]

Comment thread docs/source/arrhenius_t.ipynb Outdated
Comment thread kinisi/fitting.py Outdated
Comment thread kinisi/tests/test_yeh_hummer.py
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
2031 1923 95% 0% 🟢

New Files

File Coverage Status
kinisi/tests/test_fitting.py 100% 🟢
TOTAL 100% 🟢

Modified Files

File Coverage Status
kinisi/_init_.py 100% 🟢
kinisi/arrhenius.py 100% 🟢
kinisi/fitting.py 96% 🟢
kinisi/tests/test_arrhenius.py 100% 🟢
kinisi/tests/test_yeh_hummer.py 100% 🟢
kinisi/yeh_hummer.py 88% 🟢
TOTAL 97% 🟢

updated for commit: 08d9b25 by action🐍

arm61 and others added 3 commits June 17, 2026 14:55
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@arm61

arm61 commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot please re-review

Copilot AI commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

@copilot please re-review

Addressed the remaining unresolved threads in commit Fix docstring, default prior construction, return annotation, and test slope/viscosity labeling:

  • yeh_hummer.py docstring — updated to say [D_0, slope] instead of [D_0, viscosity], which matches how priors are actually applied internally.
  • Default slope prior bug — removed the erroneous * self._slope_unit multiplication (lines 73-74) that wrapped the plain floats from viscosity_to_slope() back into scipp variables, causing a UnitError when the optimizer called logpdf with plain floats. Also fixed the D_prior scale from the incorrect D_max + 0.8 to 1.2 * D_max so the support is [0.8*D_max, 2.0*D_max] as intended.
  • max_likelihood / max_aposteriori — added explicit -> None return annotations since both methods store results as side effects on data_group.
  • Test — fixed the second prior comment from "viscosity prior" to "slope prior", and updated the assertion to compare the fitted slope value against the slope prior bounds (instead of comparing shear_viscosity against a slope-unit prior range, which was semantically wrong).

Copilot finished work on behalf of arm61 June 17, 2026 14:07
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.

Ability for non-uniform priors in Arrhenius

3 participants