-
Notifications
You must be signed in to change notification settings - Fork 19
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
Added code to reverse transforms for more flexibility #132
Conversation
@ThibeauWouters Thanks for the PR! The changes look good! For the tests, I think the test scripts in |
@thomasckng Thanks! I had local copies of the test file to try more agressive hyperparameters but indeed I seemed to have messed them up with the ones in the test directory. Thanks for canceling the runs. |
test/integration/test_GW150914_D.py
Outdated
n_epochs=n_epochs, | ||
learning_rate=learning_rate, | ||
n_max_examples=30, | ||
n_flow_samples=100, | ||
n_max_examples=30000, |
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.
Test are supposed to be light weight. Reminder to revert these numbers
src/jimgw/transforms.py
Outdated
@@ -445,3 +445,54 @@ def __init__( | |||
) | |||
for i in range(len(name_mapping[1])) | |||
} | |||
|
|||
|
|||
def create_bijective_transform( |
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 think this is not a good practice in general. Here transform_func_array
and inverse_transform_func_array
can be potentially harmful functions, and in the long run, this flexibility will create trouble in reproducibility. Any bijective transform should be explicitly declared with the class interface.
@kazewong I adapted the code to adapt to your previous comment. But now it feels a bit off in the sense that the "predefined" transforms are classes, that have to be instantiated in order to get the actual transform to be used in PE, and the reverse transforms that are created from the reverse function are objects/instances already. The former require users to give |
There are a couple of things you mentioned here:
I think this is more ergonomic for the user, instead of needing to use a function to call the predefined transform. Going forward, I do think predefined transforms that enforce the naming strictly should mostly be constructed using the interface |
@thomasckng @kazewong I have updated the PR a bit after the discussion yesterday. Let me know if this looks OK to you or if further changes are required. |
@thomasckng The files have been deleted |
src/jimgw/single_event/transforms.py
Outdated
return f"{self.__class__.__name__[1:]}()" | ||
|
||
|
||
ComponentMassesToChirpMassMassRatioTransform = ( |
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.
Do you want to further consolidate it? From what I see, this can be just
def named_transform_func...
def named_transform_inverse_func...
ComponentMassesToChirpMassMassRatioTransform = BijectiveTransform(name_mapping = (["m_1", "m_2"], ["M_c", "q"]), transform_func = named_transform, self.inverse_transform_func = named_inverse_transform)
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.
Please resolve the comment related to further consolidation. But after that it should be good for merging
@kazewong I have updated the source code as requested -- is this what you were referring to? |
0e96439
into
kazewong:98-moving-naming-tracking-into-jim-class-from-prior-class
New attempt at improving the flexibility and use of "pre-made" transforms such as masses transforms etc.
Source code changes
I have added two utility functions:
BijectiveTransform
given aname_mapping
and the forward and backward transformation functions which take arrays as input. That way, we can easily create these "pre-made" transforms by specifying these in a one-liner. At the same time, it allows users to create similar transforms themselves very easily, which therefore also makes thename_mapping
no longer hardcoded for the masses since users can change it if they desire, as @thomasckng mentioned some time ago.BijectiveTransform
object, as @kazewong suggested in my previous PR attempt.These functions are then used to simplify the "pre-made" transforms in
single_event/transforms.py
to be shorter and clearer.Test changes
test/integration
matches this new implementation.