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

Flexible remapper #82

Open
OpheliaMiralles opened this issue Nov 21, 2024 · 5 comments
Open

Flexible remapper #82

OpheliaMiralles opened this issue Nov 21, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@OpheliaMiralles
Copy link

OpheliaMiralles commented Nov 21, 2024

Use of custom remappers for training.

Right now, only the angle to cosine/sine remapper is provided with anemoi-models. I feel like there might be a need for additional 1-to-1 remappers, e.g. mapping precipitation to log precipitation during training to facilitate the learning. I am currently adding 3 remappers of the sort

  • log1p, mapping $x$ to $\log(1+x)$ and back using expm1 from torch;
  • sqrt, mapping $x$ to $\sqrt{x}$ and back;
  • boxcox, mapping $x$ to $(x^{\lambda}-1) / \lambda \text{ if } \lambda \neq 0 \text{ else } \log(x)$ and back.

Boxcox transforms are used to control the variable spread and generate Gaussian-like data. Coments are welcome regarding the need for such remappers by the community.

Organisation

MeteoSwiss

@OpheliaMiralles OpheliaMiralles added the enhancement New feature or request label Nov 21, 2024
@sahahner
Copy link
Member

Hi Ophelia,
If I understand the issue correctly you want to convert a variable in place.
I would recommend creating a new class of preprocessors called for example "converter". I wrote some code on that already, which should have been shared with you already.
The remapper always clones the tensors and also changes the position of the variables since it is thought to do one-to-many remappings. This is why I would not recommend using the remapper for in-place conversion of variables.

@OpheliaMiralles
Copy link
Author

OpheliaMiralles commented Nov 21, 2024

I think you are right if we want to directly provide the network with a function of a variable. But what if you want to apply the link function (I prefer this term) while conserving the original variable, e.g. give the network $x$ and $\log(x)$ as input for example? Then it would make sense to do that in the remapper... Does it really change the performance to clone the tensor? Did you run some tests?

@sahahner
Copy link
Member

Does it really change the performance to clone the tensor? Did you run some tests?

Yes, I tested this thoroughly and the performance is not slower. Also, memory consumption does not increase significantly. Feel free to write me an email and I can point you to the results.

Note that the remapper must be applied after the other preprocessors since it changes the order of variables.

@sahahner
Copy link
Member

want to apply the link function (I prefer this term) while conserving the original variable, e.g. give the network x and l o g ⁡ ( x ) as input for example? Then it would make sense to do that in the remapper

That does indeed sound like a nice application for the remapper! :) Note that the newly created variables cannot be normalized, as the normalizers always use the original ordering of the variables. (see comment above)

@OpheliaMiralles
Copy link
Author

I tried to propose a version in #88 where the remapping occurs in place for 1-to-1 remapping, and the code is unchanged for more complex mappings, though the name has been changed into multimapper (module and object) to let the remapper be the 1-to-1 mapping. Maybe you could be a reviewer @sahahner ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants