Skip to content

Tolerances for snowstorm additional params#936

Open
JanWeldert wants to merge 1 commit into
masterfrom
snowstorm_tol
Open

Tolerances for snowstorm additional params#936
JanWeldert wants to merge 1 commit into
masterfrom
snowstorm_tol

Conversation

@JanWeldert
Copy link
Copy Markdown
Collaborator

Allows a user to set tolerances for the parameters of the snowstorm stage that require a re-calculation of the systematics gradients (e.g. osc params). Setting no tolerance results in a re-calculation every time the parameter is changed.

Copy link
Copy Markdown
Collaborator

@thehrh thehrh left a comment

Choose a reason for hiding this comment

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

See the handful of inline comments.

NB: From a design standpoint, attributes such as grads, tol, additional_params_values etc. should better be declared as non-public (self._tol etc.) IMO, to indicate that they are only meant for internal use, in particular because this service has a custom caching mechanism. I'm aware that other services don't adhere to such a design, so approval won't depend on this.

self.tol = tolerances
assert isinstance(self.tol, list)
assert len(self.tol) == len(self.additional_params)
self.tol = np.array(self.tol)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • instantiate array with appropriate data type: self.tol = np.array(self.tol, dtype=FTYPE)
  • from pisa import ureg, FTYPE at top

# We need to calculate if an additional params value or the apply_mode changed
additional_params_values = [self.params[p].m for p in self.additional_params]
if additional_params_values != self.additional_params_values:
additional_params_values = np.array([self.params[p].m for p in self.additional_params])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

instantiate with dtype=FTYPE

additional_params : list of str (default None)
Parameters that are no detector systematics but if changed require a
re-calculation of the gradients (e.g. osc params).
tolerances : list of float (default None)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This description is a bit brief for my liking. I would reformulate this for clarity, for instance like so (adapt if necessary):

Numerical tolerances for `additional_params`, to be given in the same order.
If none are given (default), all gradients will be updated each time at least
one parameter value changes (most accurate but slowest option). If tolerances
*are* given, though, and *all* parameters move away from their initial values
by *less* than the specified tolerances over the course of a single fit, gradients
will *never* be re-calculated. Only once at least one parameter's overall delta
exceeds its corresponding tolerance will all gradients be updated (and a new
reference point set). Subsequent modfications of the parameter vector will
then be compared to this updated referenced point.

if isinstance(tolerances, str):
self.tol = eval(tolerances)
elif tolerances is None:
self.tol = [FTYPE_PREC] * len(self.additional_params)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Having considered this a bit more, instantiating self.tol = np.zeros_like(self.additional_params, dtype=FTYPE) is probably more prudent. We want to err on the side of caution here. You are also not checking parameters' rescaled values in compute_function, so all values could have vastly different magnitudes. I'd say just update gradients and the reference point once any change is detected, however small it may be and irrespective of FTYPE_PREC.

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.

2 participants