MLBazaar / MLPrimitives

Primitives for machine learning and data science.
https://mlbazaar.github.io/MLPrimitives
MIT License
70 stars 38 forks source link

Timeseries Intervals to Mask Primitive #186

Closed csala closed 4 years ago

csala commented 5 years ago

Build a new primitive that takes as input an ordered index and a set of intervals and builds a mask with the same length as the index with boolean values indicating whether each value is within any of the given intervals or not.

As this is a very simple primitive, it can be directly put inside the custom.timeseries_preprocessing module.

The behavior should be something along this lines:

>>> index = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> intervals = [[3, 5], [7, 10]]
>>> intervals_to_mask(index, intervals)
array([False, False, False,  True,  True,  True, False,  True,  True,
        True])

Inputs should be called index and intervals and output should be called mask. All types should be numpy.ndarray, even though the implementation can be made to support any kind of array-like object.