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

How to use masked arrays? #5

Open
alexbovet opened this issue Nov 30, 2017 · 2 comments
Open

How to use masked arrays? #5

alexbovet opened this issue Nov 30, 2017 · 2 comments

Comments

@alexbovet
Copy link

Hi,

I don't understand how to use masked arrays with stl.

import numpy as np
import numpy.ma as ma
from pyloess.mpyloess import stl

y = np.array([1,12,5,3,5,6])
yma = ma.masked_array(y, mask=[0,0,1,0,0,0])

stl(yma)

returns: ValueError: Masked arrays should be filled first!

In the code (mpyloess.py), I see that there is a check:

class stl:
    class _inputs:
        def __init__(self, y):
            self.y = masked_array(y, subok=True, copy=False).ravel()
            self._mask = self.y._mask
            if self._mask.any():
                raise ValueError("Masked arrays should be filled first!")
            self.y_eff = self.y.compressed()

So any masked arrays will raise this error.
If I try with yma.filled() instead, the fit does take the filled values into account, which is not what I want for masked arrays.
Is it possible to use masked arrays, I understood that STL could deal with missing data.

Note that I am using @jcrotinger's fork for Python 3.

Thanks!

@jcrotinger
Copy link

@alexbovet I've never used the masked array functionality but it isn't about handling missing data - the underlying Fortran implementation is not set up for this (and I believe this is mentioned in the original paper). While the weights are passed in to the Fortran stl function, this is just because there are no dynamic arrays in Fortran 77. Internally, stl sets these weights to 1 on the initial pass and sets them directly later, instead of multiplicatively.

I'm guessing this functionality is there just to allow extracting some sort of slice from a python array to pass down to the STL, but I'm not sure.

In my Java implementation, I've considered exposing the weights externally for exactly this purpose - the implementation looks like it would be straightforward to modify to ignore missing values, assuming there are enough points available to do the sub-cycle interpolation to the missing point. But it isn't high on my list right now.

@alexbovet
Copy link
Author

ok, thanks a lot for the clarifications and thanks for the python3 implementation!

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

No branches or pull requests

2 participants