Skip to content

Refactor YehHummer to use linear (D_0, slope) parameterization#206

Merged
arm61 merged 4 commits intokinisi-dev:mainfrom
PythonFZ:refactor/yeh-hummer-linear-parameterization
Feb 11, 2026
Merged

Refactor YehHummer to use linear (D_0, slope) parameterization#206
arm61 merged 4 commits intokinisi-dev:mainfrom
PythonFZ:refactor/yeh-hummer-linear-parameterization

Conversation

@PythonFZ
Copy link
Member

@PythonFZ PythonFZ commented Feb 5, 2026

Reparameterize YehHummer fitting from (D_0, viscosity) to (D_0, slope) where the model is linear: D_PBC = D_0 - slope/L. This improves MCMC sampling efficiency since viscosity spans many orders of magnitude while slope is better behaved in parameter space.

Changes to yeh_hummer.py:

  • Fit slope directly instead of viscosity
  • Convert viscosity bounds to slope bounds (inverted due to inverse relationship)
  • Simplify _yeh_hummer_function to inline the linear formula
  • Remove redundant yeh_hummer_linear static method and bounds_values
  • Add shear_viscosity property that converts slope samples to viscosity
  • Add return type annotation (sc.Variable | Samples)

Changes to fitting.py:

  • Add validation in log_likelihood for invalid model values
  • Return -inf for non-finite or non-positive model outputs
  • Prevents MCMC from accepting unphysical parameter combinations
    (e.g., VTF when T0 >= T)

Copy link
Contributor

Copilot AI left a comment

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 refactors the YehHummer finite-size correction fitting from (D_0, viscosity) parameterization to (D_0, slope) parameterization to improve MCMC sampling efficiency. The linear relationship D_PBC = D_0 - slope/L is more suitable for sampling than the original formulation where viscosity spans many orders of magnitude. Additionally, validation logic is added to the base fitting class to handle invalid model outputs.

Changes:

  • Refactored YehHummer to fit slope directly instead of viscosity, with automatic conversion to viscosity for output via the shear_viscosity property
  • Inverted viscosity bounds to slope bounds (higher viscosity = lower slope)
  • Simplified the fitting function to use the inline linear formula D_PBC = D_0 - slope/L
  • Added validation in FittingBase.log_likelihood to reject non-finite or non-positive model values

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
kinisi/yeh_hummer.py Refactored from (D_0, viscosity) to (D_0, slope) parameterization; removed static method; updated shear_viscosity property to convert slope samples
kinisi/fitting.py Added validation for invalid model values in log_likelihood method

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

Copy link
Collaborator

@arm61 arm61 left a comment

Choose a reason for hiding this comment

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

This is a nice change. A few things to double-check/change, then it can be merged.

x_values = self.get_independent_variable()
model = self.function(x_values, *parameters)

# Handle invalid model values (e.g., from VTF when T0 >= T)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be handled with an appropriate prior probability.

:param box_lengths: Array of box lengths / Angstrom
:param D_0: Infinite-system diffusion coefficient
:param viscosity: Shear viscosity
:param slope: Slope = (k_B * T * xi) / (6 * pi * eta)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
:param slope: Slope = (k_B * T * xi) / (6 * pi * eta)
:param slope: i.e., (k_B * T * xi) / (6 * pi * eta)

@arm61 arm61 merged commit dbfe05e into kinisi-dev:main Feb 11, 2026
0 of 4 checks passed
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.

3 participants