Skip to content

Commit 76dd67b

Browse files
authored
Fix docstring, default prior construction, return annotation, and test slope/viscosity labeling
1 parent 581dd10 commit 76dd67b

3 files changed

Lines changed: 12 additions & 13 deletions

File tree

kinisi/fitting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def prior_transform(self, parameters: tuple[float]) -> tuple[float]:
181181
x[i] = self.priors[i].ppf(parameters[i])
182182
return x
183183

184-
def max_likelihood(self):
184+
def max_likelihood(self) -> None:
185185
"""Find the max likelihood fit parameters for the model."""
186186
if self.priors is not None:
187187
x0 = [p.mean() for p in self.priors]
@@ -191,7 +191,7 @@ def max_likelihood(self):
191191
for i, name in enumerate(self.parameter_names):
192192
self.data_group[name] = result[i] * self.parameter_units[i]
193193

194-
def max_aposteriori(self):
194+
def max_aposteriori(self) -> None:
195195
"""Find the max aposteriori fit parameters for the model."""
196196
if self.priors is not None:
197197
x0 = [p.mean() for p in self.priors]

kinisi/tests/test_yeh_hummer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@ def test_yeh_hummer_priors(self):
106106
# Custom priors
107107
priors = (
108108
uniform(4e-5, 7e-5), # D_0 prior
109-
uniform(1e-4, 1e-2), # viscosity prior
109+
uniform(1e-4, 1e-2), # slope prior
110110
)
111111

112112
yh = YehHummer(td, temperature=sc.scalar(298, unit='K'), priors=priors)
113113

114114
# Check that fitted values are within priors
115115
assert priors[0].a <= yh.D_infinite.value <= (priors[0].b + priors[0].a)
116-
assert priors[1].a <= yh.shear_viscosity.value <= (priors[1].b + priors[1].a)
116+
assert priors[1].a <= yh.data_group['slope'].value <= (priors[1].b + priors[1].a)
117117

118118
def test_yeh_hummer_properties(self):
119119
"""Test YehHummer property accessors."""

kinisi/yeh_hummer.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class YehHummer(FittingBase):
4141
4242
:param diffusion: sc.DataArray with diffusion coefficients and box_length coordinate
4343
:param temperature: Temperature (will be extracted from coords if not provided)
44-
:param priors: Optional priors for [D_0, viscosity] parameters using scipy.stats objects
45-
(viscosity in Pa*s)
44+
:param priors: Optional priors for [D_0, slope] parameters using scipy.stats objects,
45+
where slope has units of [diffusion] * [length]
4646
"""
4747

4848
def __init__(self, diffusion, temperature: sc.Variable, priors=None):
@@ -65,15 +65,14 @@ def __init__(self, diffusion, temperature: sc.Variable, priors=None):
6565
# Compute priors: use provided or defaults
6666
if priors is None:
6767
D_max = np.max(diffusion.values)
68-
D_prior = uniform(D_max * 0.8, (D_max * 2.0) - (D_max - 0.8))
68+
D_prior = uniform(D_max * 0.8, D_max * 1.2)
6969
visc_lower, visc_upper = 1e-5 * sc.Unit('Pa*s'), 1e-1 * sc.Unit('Pa*s')
7070

71-
# Higher viscosity = lower slope, so bounds are inverted
72-
slope_bounds = (
73-
self.viscosity_to_slope(visc_upper) * self._slope_unit,
74-
self.viscosity_to_slope(visc_lower) * self._slope_unit,
75-
)
76-
slope_prior = uniform(slope_bounds[0], slope_bounds[1] - slope_bounds[0])
71+
# Higher viscosity = lower slope, so bounds are inverted; viscosity_to_slope
72+
# already returns plain floats so no unit multiplication needed here
73+
slope_min = self.viscosity_to_slope(visc_upper)
74+
slope_max = self.viscosity_to_slope(visc_lower)
75+
slope_prior = uniform(slope_min, slope_max - slope_min)
7776
priors = [D_prior, slope_prior]
7877
else:
7978
if len(priors) != 2:

0 commit comments

Comments
 (0)