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

New operator: moving_product #380

Closed
ianspektor opened this issue Feb 26, 2024 · 4 comments · Fixed by #383
Closed

New operator: moving_product #380

ianspektor opened this issue Feb 26, 2024 · 4 comments · Fixed by #383
Assignees
Labels
new operator Development of a new operator.

Comments

@ianspektor
Copy link
Collaborator

ianspektor commented Feb 26, 2024

New EventSet.moving_product() operator.

See EventSet.moving_sum() for reference. Note that this issue will require C++ code.

See https://github.com/google/temporian/blob/main/CONTRIBUTING.md#developing-a-new-operator for guidance.

Questions or requests for additional guidance from possible contributors more than welcome!

@ianspektor ianspektor added enhancement New feature or request good first issue Good for newcomers and removed good first issue Good for newcomers labels Feb 26, 2024
@ianspektor ianspektor added new operator Development of a new operator. and removed enhancement New feature or request labels Feb 26, 2024
@akshatvishu
Copy link
Contributor

Will be working on this as a part of #350

@ianspektor
Copy link
Collaborator Author

Hey @akshatvishu!

This involves modifying quite a bit of cpp code:

  • Creating a new Accumulator implementation (see MovingSumAccumulator in temporian/implementation/numpy_cc/operators/window.cc)
  • Creating new accumulate overloads for moving_product in the same file
  • Registering and creating bindings for the new accumulate cpp functions (see bottom of that same file)

Plus, there's some specifics to moving product that make it not as straightforward to implement as moving sum, for example. We'd rather have the core dev team implement this (ETA: this/next week tops) and then have you do cumprod alone - unless you are perfectly comfortable with all of the above, in which case I can give more detail as to what these specifics are and let you take a shot at it :)

Let me know!

@akshatvishu
Copy link
Contributor

Hi @ianspektor ,

Thanks for the guidance. I'm keen to take a stab at implementing moving_product myself before you guys steps in. I've got a couple of quick questions to ensure I'm on the right track:

  • Zero or extreme values: How should I handle them in MovingProductAccumulator? Any tips for ensuring stability?
  • Accumulate overloads: Could you provide a bit more insight on handling cases with/without external sampling, and for constant vs. variable window lengths?

I plan to start working on this today and will update you by tomorrow on my progress to avoid any unnecessary delays on your end in-case I am unable to make any progress.

@ianspektor
Copy link
Collaborator Author

ianspektor commented Feb 27, 2024

Sounds perfect 👍🏼 and great questions.

  • Zero or extreme values: zeros will result in the accumulator's result being 0. NaNs should be ignored (i.e., if we have a [2, NaN, 3] window, the result should still be 6, not NaN).
  • Accumulate overloads: you don't need to modify these, you'll just need to add the REGISTER_CC_FUNC and ADD_PY_DEF calls. See simple_moving_average's for reference.

Some extra notes:

  • You'll see that most accumulators work by adding/removing the new/old values from the window directly onto the accumulation result. This won't be possible here, since 0 would erase the accumulation, and precision loss would be high. Instead, we want the accumulator to store the left/right indexes, and compute the product on the whole window in Result().
  • No need to raise an error message on overflow (numpy doesn't in cumprod)
  • We'll only make this available for float types for now. This restriction should be in the C defs, the operator's accepted types, and the function's docstring.
  • Please do moving_product only for this task, leave cumprod for a follow up.

Issue and discord always open 💪🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new operator Development of a new operator.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants