You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Changing window size or basis function requires a reset of the convolution kernels, which are of shape (window_size, n_basis_funcs). The set_kernel method is the method responsible to compute the kernels. This is meant to be part of the fit call of the TransformerBasis, which prepares the basis for the transform method (which maps to _compute_features).
Currently, if one changes window size or num basis after the kenels have been set, then the kernel shape would not match the basis parameters, and a call to transform (or _compute_features for regular bases) would not produce the expected results.
One way possible solution is to re-write the __setattr__ of basis and intercept the window size and basis setter:
# these are methods of nemos._basis.Basisdef_recompute_kernels(self):
"""Recompute all kernels if needed. Traverse the tree upwards and reset all input-independent states. If the node is the root, directly update its states; otherwise, propagate the request to the parent node. """# Assumes that state updates in the basis tree can be handled independently for each node.# This is currently true but may change if dependencies are introduced.# The only such state is self.kernel_, which is set independently for each basis component.# If dependencies are introduced, use `self.set_kernel` at the root level instead.# (A basis is the tree root if self._parend is None).# Note: `self.set_kernel` is more expensive as it recomputes kernels for the entire tree.update_states=getattr(self, "_reset_all_input_independent_states", None)
ifupdate_states:
update_states()
ifgetattr(self, "_parent", None):
self._parent._recompute_kernels()
def_is_init_params_updated(self, name: str, value: Any):
"""Check if an attribute set at initialization have been updated."""returnnameinself._get_param_names()
def__setattr__(self, name: str, value: Any):
""" Set to None all attributes ending with '_'. This __setattr__ resets all the attributes that are defined by a method like the `kernel_` or `_n_input_shape_` (states of the basis) when an initialization configuration is updated. A Basis class must respect the following naming convention: all names of parameters that are settable by with a method (like `kernel_` computed in `set_kernel`) must end in "_". Parameters ---------- name : The name of the attribute to set. value : The value to set the attribute to. """# check if the attribute was defined in the __init__ signature# and if so, then resets all computable states.super().__setattr__(name, value)
ifself._is_init_params_updated(name, value):
self._recompute_kernels()
And in the ConvBasisMixin
def_reset_all_input_independent_states(self):
"""Set all states that are input independent for self only. This method sets all the input independent states. This reimplements an abstract method of basis, and it is different from ``set_kernel`` because it won't traverse the basis tree in any basis (including composite basis), while ``set_kernel`` applies to all the tree. Called by the setattr of basis. """current_kernel=getattr(self, "kernel_", None)
try:
self.kernel_= (
current_kernelifcurrent_kernelisNoneelseself._evaluate(np.linspace(0, 1, self.window_size))
)
exceptExceptionase:
# if basis not fully initialized attribute is not there yet.kernel=getattr(self, "kernel_", None)
ifkernelisnotNone:
warnings.warn(
message=f"Unable to re-initialize the kernel for basis {self.label}, "f"with exception:\n{repr(e)}. \n"f"Resetting the kernel `None`.",
category=UserWarning,
)
self.kernel_=None
The text was updated successfully, but these errors were encountered:
set_kernel
and kernel computationChanging window size or basis function requires a reset of the convolution kernels, which are of shape
(window_size, n_basis_funcs)
. Theset_kernel
method is the method responsible to compute the kernels. This is meant to be part of thefit
call of theTransformerBasis
, which prepares the basis for thetransform
method (which maps to_compute_features
).Currently, if one changes window size or num basis after the kenels have been set, then the kernel shape would not match the basis parameters, and a call to
transform
(or_compute_features
for regular bases) would not produce the expected results.One way possible solution is to re-write the
__setattr__
of basis and intercept the window size and basis setter:And in the ConvBasisMixin
The text was updated successfully, but these errors were encountered: