-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Label get param #306
base: development
Are you sure you want to change the base?
Label get param #306
Conversation
…e also enforced at basis initialization
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I played around with this a bit locally, and I think it behaves as expected.
In addition to the comments:
- We need some linting to happen on the notebooks: we're getting a lot of changes that I think are just coming from differences in how editor vs. jupyter lab is saving them, which is distracting
- I want to draw particular attention to my comment in
basis/__init__.py
on__all__
, something is weird there - I don't understand what's going on with
sklearn_get_params
/get_params
and with_map_parameters
/remap_parameters
-- can you explain? Basically, I think I want a description that's a bit more detailed than the high-level one in the PR now. - We only support
__getitem__
for labels, not__getattr__
, which is fine, but do we want to raise a more specific error message if someone tries to grab an attribute using something we know is a label? - Relatedly, if they use attributes, they need to do
basis1.basis2.etc
but getitem allows for labels. Probably worth explaining that in the new doc page?
::: | ||
|
||
|
||
Note that if you don't provide a label, basis class name is used to construct the keys. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From here to the end belongs in the second section, I think. it's not about sklearn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to move the content, let me know
src/nemos/basis/_basis.py
Outdated
|
||
Parameters | ||
---------- | ||
deep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now it is described
…into label_get_param
From last version of the PR, many things got moved around after talking with @billbrod. Composite basis tree-structure traversingMany operation on composite basis require updating child bases. So far, most of the machinery relied on the child basis methods and properties. This is included the label setter property implemented in this PR. With this revised PR, I moved all the label editing logic, as well as other functions that operate over the whole basis tree, in a dedicated module. This functions are now independent from the child bases internal machinery. This is independence is not tested here but will be the object of a dedicated PR in which I will add a mock basis class with a single method, the compute_features, and make sure that I can successfully add it to Get Params LogicThe overwritten Implementation details
|
Co-authored-by: William F. Broderick <billbrod@gmail.com>
Co-authored-by: William F. Broderick <billbrod@gmail.com>
…into label_get_param
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worked on the revisions! ready for a second round
::: | ||
|
||
|
||
Note that if you don't provide a label, basis class name is used to construct the keys. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to move the content, let me know
src/nemos/convolve.py
Outdated
@@ -90,6 +90,8 @@ def _shift_time_axis_and_convolve(array: NDArray, eval_basis: NDArray, axis: int | |||
----- | |||
This function supports arrays of any dimensionality greater or equal than 1. | |||
""" | |||
# convert axis | |||
axis = axis if axis >= 0 else array.ndim + axis |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i thought I already merged this, unsure why it shows. I would keep it since it is a bugfix
src/nemos/utils.py
Outdated
@@ -156,6 +156,8 @@ def _pad_dimension( | |||
"acausal": ((pad_size) // 2, pad_size - (pad_size) // 2), | |||
"anti-causal": (0, pad_size), | |||
} | |||
# convert negative axis in jax jit compilable way | |||
axis = axis * (axis >= 0) + (array.ndim + axis) * (axis < 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same thing, I thought i merged this in main
src/nemos/utils.py
Outdated
|
||
all_params = obj.get_params(deep=False) | ||
# use special method for basis | ||
get_params = getattr(obj, "__sklearn_get_params__", obj.get_params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I explained above, but since it is tricky I add another explenation. the idea is that we need to be able to both retrieve the actual attribute structure and the re-mapping using labels.
Why is that? Because scikit-learn (and our base class) use recursively the signature of classes implementing get/set parameters to determine which parameter can be edited. To work correctly, the recursion must be able to retrieve a dictionary with the actual structure ("basis1__basis2__..."), while the user facing get_prams
should use the labels.
src/nemos/utils.py
Outdated
|
||
all_params = obj.get_params(deep=False) | ||
# use special method for basis | ||
get_params = getattr(obj, "__sklearn_get_params__", obj.get_params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw here we don't need to use the private one, so i changed that, but we still need the method
src/nemos/basis/_basis.py
Outdated
|
||
Parameters | ||
---------- | ||
deep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now it is described
This PR addresses the following
__getitem__
toBasis
. Labels can be used to get the desired basis in the tree._<number>
.get_params
andset_params
override default behavior: instead of reflecting the full attribute structure,basis1__basis2...__parameter_name
, the parameter key is set to<label>_parameter_name
.For a concrete example, refer to the new how-to note:
handling_composite_bases.md
Key Implementation: Setter of Basis
For the PR review, focus on the behavior of
@basis1.setter
and@basis2.setter
. This property determines how theset_params
is finalized. In particular, in case one usesset_params
to set a basis funciton, some extra attribute must be modfied:set_params
, the new gets the_parent
attribute from the current.