Address reviewer feedback.

This commit is contained in:
Kevin Zakka
2026-05-27 13:07:35 -07:00
parent ab4102ea42
commit 2b9960a617
3 changed files with 42 additions and 39 deletions
+12 -7
View File
@@ -139,15 +139,18 @@ class Parameter:
rng = np.random.default_rng()
return rng.uniform(self.min_value.flatten(), self.max_value.flatten())
def move_off_bound(self, fraction: float = 0.05) -> None:
"""Shift values within 0.1% of a bound to ``lo + fraction*(hi-lo)`` (or
symmetric for the upper bound). Interior components are unchanged."""
def move_off_bound(
self, fraction: float = 0.05, at_bound_tol: float = 1e-3
) -> None:
"""Shift values within ``at_bound_tol * (hi - lo)`` of a bound to
``lo + fraction*(hi-lo)`` (or symmetric for the upper bound). Interior
components are unchanged."""
lo, hi = self.get_bounds()
rng = hi - lo
safe_rng = np.where(rng > 0, rng, 1.0)
v = self.as_vector().copy()
at_lo = (v - lo) <= 1e-3 * safe_rng
at_hi = (hi - v) <= 1e-3 * safe_rng
at_lo = (v - lo) <= at_bound_tol * safe_rng
at_hi = (hi - v) <= at_bound_tol * safe_rng
v = np.where(at_lo, lo + fraction * rng, v)
v = np.where(at_hi, hi - fraction * rng, v)
self.update_from_vector(v)
@@ -306,13 +309,15 @@ class ParameterDict:
param.update_from_vector(vector[start : start + size])
start += size
def move_off_bounds(self, fraction: float = 0.05) -> Self:
def move_off_bounds(
self, fraction: float = 0.05, at_bound_tol: float = 1e-3
) -> Self:
"""Call :meth:`Parameter.move_off_bound` on every non-frozen parameter,
returning ``self`` so calls can be chained before
:func:`optimize`."""
for param in self.parameters.values():
if not param.frozen:
param.move_off_bound(fraction=fraction)
param.move_off_bound(fraction=fraction, at_bound_tol=at_bound_tol)
return self
def save_to_disk(self, path: str | pathlib.Path) -> None: