Skip to content
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

MAINT deprecate average in Scattering1D #897

Merged
merged 18 commits into from
Jun 27, 2022
Merged

MAINT deprecate average in Scattering1D #897

merged 18 commits into from
Jun 27, 2022

Conversation

cyrusvahidi
Copy link
Collaborator

@cyrusvahidi cyrusvahidi commented Jun 21, 2022

Addressing #885. Deprecation of Scattering1D average for v0.3, in preparation for removal in v0.4

Alters the semantics of T:

  • T=None performs default mode averaging, i.e. T=2**J
  • T=0 is no averaging
  • Any other integer T will stride over the specified support

I have made an average property and renamed the attribute to self._average

UPDATE: 25/06/22

  • reinstated the average kwarg and attribute.
  • allows T=0 iff average=False, else throws exception

@cyrusvahidi cyrusvahidi added the 1D Issue with 1D scattering code label Jun 21, 2022
@cyrusvahidi cyrusvahidi added this to the 0.3.alpha milestone Jun 21, 2022
@changhongw
Copy link
Collaborator

  • T=None performs default mode averaging, i.e. T=2**J
  • T=0 is no averaging
  • Any other integer T will stride over the specified support

Why not using T=2**J as the default rather than T=None (as following)? Having both T=None and T=0 may cause confusion for the case of no averaging?

  • T=0: no averaging
  • T=2**J: default averaging
  • T=other positive integer: other averaging

@cyrusvahidi
Copy link
Collaborator Author

  • T=None performs default mode averaging, i.e. T=2**J
  • T=0 is no averaging
  • Any other integer T will stride over the specified support

Why not using T=2**J as the default rather than T=None (as following)? Having both T=None and T=0 may cause confusion for the case of no averaging?

* `T=0`: no averaging

* `T=2**J`: default averaging

* `T=other positive integer`: other averaging

good idea but you cannot write def __init__(J, shape, T=2**J ... ). that would be referencing a variableJ that is undefined.

@changhongw
Copy link
Collaborator

  • T=None performs default mode averaging, i.e. T=2**J
  • T=0 is no averaging
  • Any other integer T will stride over the specified support

Why not using T=2**J as the default rather than T=None (as following)? Having both T=None and T=0 may cause confusion for the case of no averaging?

* `T=0`: no averaging

* `T=2**J`: default averaging

* `T=other positive integer`: other averaging

good idea but you cannot write def __init__(J, shape, T=2**J ... ). that would be referencing a variableJ that is undefined.

Indeed.

@cyrusvahidi cyrusvahidi marked this pull request as draft June 25, 2022 20:41
@cyrusvahidi cyrusvahidi requested a review from janden June 25, 2022 20:41
@cyrusvahidi
Copy link
Collaborator Author

OK the average kwarg is back and is an attribute. T=0 is only accepted if average=False

@lostanlen
Copy link
Collaborator

lostanlen commented Jun 25, 2022

@cyrusvahidi can't we default average to None so that it becomes False internally if and only if T=0?
With your latest change, the setting T=0 has no justification because it must be paired with passing average=False

the issue raised by @janden was different:

if user passes average=False and leaves T=None, we raise a warning and perform averaging. Instead, we should not average

or maybe i'm misunderstanding something?

Copy link
Collaborator

@MuawizChaudhary MuawizChaudhary left a comment

Choose a reason for hiding this comment

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

just one set of changes

kymatio/scattering1d/frontend/base_frontend.py Outdated Show resolved Hide resolved
tests/scattering1d/test_torch_scattering1d.py Outdated Show resolved Hide resolved
@cyrusvahidi
Copy link
Collaborator Author

this seems safe to me and also a better way to send the deprecate message. as long as we check not average and T == 0. do you agree?

@lostanlen
Copy link
Collaborator

lostanlen commented Jun 25, 2022

this seems safe to me and also a better way to send the deprecate message. as long as we check not average and T == 0. do you agree?

it's certainly safe now but i'd argue it's too safe in the sense that (if i understand well " T=0 is only accepted if average=False") the average argument will remain compulsory (=False) if one wants to disable averaging. Just passing T=0 is no longer enough.

@cyrusvahidi
Copy link
Collaborator Author

this seems safe to me and also a better way to send the deprecate message. as long as we check not average and T == 0. do you agree?

it's certainly safe now but i'd argue it's too safe in the sense that (if i understand well " T=0 is only accepted if average=False") the average argument will remain compulsory (=False) if one wants to disable averaging.

yes, too safe. So only error if T=0 and average=True. average=False will override any T.

@cyrusvahidi cyrusvahidi marked this pull request as ready for review June 25, 2022 21:15
Copy link
Collaborator

@MuawizChaudhary MuawizChaudhary left a comment

Choose a reason for hiding this comment

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

@lostanlen what do ya think?

@lostanlen
Copy link
Collaborator

lostanlen commented Jun 25, 2022

"average=False will override any T" is still not right. Here's what i have in mind, presented as a truth table

⬇️ average / T ➡️ None 0 (int) >=1 (int or float)
None avg. with T=2**J no avg. avg. with user-set T
True avg. with T=2**J (DeprecationWarning) ValueError avg. with user-set T (DeprecationWarning)
False no avg. (DeprecationWarning) ValueError ValueError
  • The new default will be average=None, T=None, and will be backwards compatible with the old default, without warning nor error.
  • Passing T=0 and letting average=None will be the new way to specify average=False.
  • Already-in-place settings average=False and T>=1 will keep working as intended. The former will raise a DeprecationWarning, instructing the user to replace average=False by T=0 before v0.4.
  • Passing average=True together with T>=1 or T=None will raise a DeprecationWarning, instructing the user to remove the average argument befor v0.4.
  • Passing T=0 together with setting average=False will raise a ValueError, because this is redundant. The ValueError will instruct the user to remove the average argument immediately.
  • If both parameters are set (to non-None values), neither of the two parameters will override the other. T=0, average=True will error, and same for T>=1, average=False.

We have four possible combinations as of v0.2. With this PR, we will have nine, of which three are errors and three are deprecated.
In the future (v0.4), we will remove average and only have (9-3-3) = 3 branches: T=None, T=0, and T>=1.

I haven't included this in the truth table, but cases T<0 and 0<T<1 should also lead to ValueError's.

This is a good first step towards supporting T="global" in v0.4

kymatio/scattering1d/frontend/base_frontend.py Outdated Show resolved Hide resolved
kymatio/scattering1d/frontend/base_frontend.py Outdated Show resolved Hide resolved
kymatio/scattering1d/frontend/base_frontend.py Outdated Show resolved Hide resolved
kymatio/scattering1d/frontend/base_frontend.py Outdated Show resolved Hide resolved
kymatio/scattering1d/frontend/base_frontend.py Outdated Show resolved Hide resolved
kymatio/scattering1d/frontend/base_frontend.py Outdated Show resolved Hide resolved
kymatio/scattering1d/frontend/base_frontend.py Outdated Show resolved Hide resolved
kymatio/scattering1d/frontend/base_frontend.py Outdated Show resolved Hide resolved
kymatio/scattering1d/frontend/base_frontend.py Outdated Show resolved Hide resolved
tests/scattering1d/test_torch_scattering1d.py Outdated Show resolved Hide resolved
kymatio/scattering1d/frontend/base_frontend.py Outdated Show resolved Hide resolved
kymatio/scattering1d/frontend/base_frontend.py Outdated Show resolved Hide resolved
kymatio/scattering1d/frontend/base_frontend.py Outdated Show resolved Hide resolved
kymatio/scattering1d/frontend/base_frontend.py Outdated Show resolved Hide resolved
else:
self.average = True if self.average is None else self.average
if not self.average:
raise ValueError("T must be None or 0 when average=False"
Copy link
Collaborator

@lostanlen lostanlen Jun 27, 2022

Choose a reason for hiding this comment

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

i'm not sure what we're doing here. we're in a T>=1 branch, so the logic i'm hoping to see is:
if average==None --> no lizard
if average==True --> DeprecationWarning. Tell the user to remove average kwarg, and that averaging will be applied.
if average==False --> ValueError. Tell the user to remove average kwarg to apply averaging at scale T. Tell the user to set T=0 to disable averaging.

This ValueError seems to suggest that T should be modified and average should be kept. That code will break in v0.4 since we'll remove the average kwarg. So right now, we want to discourage the use of average in all situations.

Copy link
Collaborator Author

@cyrusvahidi cyrusvahidi Jun 27, 2022

Choose a reason for hiding this comment

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

in this case if average is None then indeed no lizard. if False then there's a value error. I updated the message too.

Copy link
Collaborator

@lostanlen lostanlen left a comment

Choose a reason for hiding this comment

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

looks perfect now !!

@lostanlen lostanlen merged commit fe6ac19 into kymatio:dev Jun 27, 2022
eickenberg pushed a commit that referenced this pull request Jul 5, 2022
author: Cyrus Vahidi
reviewers : Muawiz Chaudhary, Vincent Lostanlen

* scat1d frontend: add deprecated average property

* deprecate average documentation

* new semantics for T and remove average kwargs

* average default None kwargs

* fix test Ux

* fix scattering1d Ux tests

* reinstate 1d average attribute

* check T is integer

* update deprecation warning msg

* default average to None

* deprecation message:

* remove empty line

* raise value error if average is False and T is not None or 0

* change valueerror message when average=False and T>=1

* update deprecation warning message

* update deprecation warning message

* update deprecation warning message

* update value error message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1D Issue with 1D scattering code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants