MLBazaar / MLPrimitives

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

rolling_window_sequences primitive does not support target_size=0 #205

Open AlexanderGeiger opened 4 years ago

AlexanderGeiger commented 4 years ago

The rolling_window_sequences primitive is not allowing a target_size of 0, in which case an out-of-bounds error will be raised for the line y_index.append(index[end]). The reason is the way we iterate over the arrays, where in the last iteration end is equal to len(index).

However, it would be quite useful to specify target_size=0 in cases where we do not have targets/predictions, but rather only want to create rolling input windows. (Examples would be the CycleGAN primitive or any other reconstruction based models like Autoencoder).

One potential solution would be to check if target_size>0.

...
out_X.append(X[start:end])
X_index.append(index[start])
if target_size>0:
    out_y.append(target[end:end + target_size])
    y_index.append(index[end])
...

This way we would return an empty arrays for the target values and target index if target_size=0.