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

Check on Index of data too strict in statespace #384

Open
AlexAndorra opened this issue Oct 24, 2024 · 0 comments
Open

Check on Index of data too strict in statespace #384

AlexAndorra opened this issue Oct 24, 2024 · 0 comments

Comments

@AlexAndorra
Copy link
Contributor

As discussed with @jessegrabowski , the statespace module has a check on indices of passed observed data that seems to strict: if you pass an integer Index, it will not accept it because it's technically not a RangeIndex:

a = pd.DataFrame(
    index=np.arange(8), columns=["A", "B", "C", "D"], data=np.arange(32).reshape(8, 4)
)

mod = st.LevelTrendComponent(order=2, innovations_order=[0, 1])
ss_mod = mod.build(name="a")

initial_trend_dims, sigma_trend_dims, P0_dims = (
    ss_mod.param_dims.values()
)
coords = ss_mod.coords

with pm.Model(coords=coords) as model_1:
    P0_diag = pm.Gamma("P0_diag", alpha=5, beta=5)
    P0 = pm.Deterministic("P0", pyt.eye(ss_mod.k_states) * P0_diag, dims=P0_dims)

    initial_trend = pm.Normal("initial_trend", dims=initial_trend_dims)
    sigma_trend = pm.Gamma("sigma_trend", alpha=2, beta=50, dims=sigma_trend_dims)

    ss_mod.build_statespace_graph(
        a["A"],
        mode="JAX",
    )
IndexError: Expected pd.DatetimeIndex or pd.RangeIndex on data, found <class 'pandas.core.indexes.base.Index'>

Maybe the check can be relaxed to non-consecutive integer index?
Also note that even if casting the index above to RangeIndex, the model will throw a warning about not finding a TimeIndex in the data, which I think is expected if you have a RandeIndex already.

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

1 participant