Skip to content

Conversation

@Dekermanjian
Copy link
Contributor

@Dekermanjian Dekermanjian commented Oct 19, 2025

This PR is related to #589 and aims to remove redundant parameters k_endog and k_exog from SSM models. The following models will be updated:

  • ETS Model
  • SARIMAX Model
  • VARMAX Model
  • DFM Model
  • Structural SSM API

In addition, this PR will also address

Closes #587
Closes #589

@Dekermanjian
Copy link
Contributor Author

Dekermanjian commented Oct 25, 2025

Hey @jessegrabowski, after updating all the models and the regression component in the structural api the complexity of the validation code dropped quite a bit. I am looking at pulling out that VARMAX validation utility to use across all the other models (SARIMAX, ETS, DFM) but the only commonality between them is how the endog_names are handled. I can pull out the validation for endog_names and wrap that up in a utility but that is only 4 lines of code. Do you think it is worth it? Never mind, I am going to do it. Once we have more models it will be worth it.

@jessegrabowski
Copy link
Member

I was going to say yes anyway :D

@jessegrabowski
Copy link
Member

jessegrabowski commented Oct 27, 2025

I am looking at pulling out that VARMAX validation utility to use across all the other models

Mark that this PR will close both #589 and #587 as a result

@Dekermanjian
Copy link
Contributor Author

Jesse, I marked the two open issues for closer upon merging this PR.

Copy link
Member

@jessegrabowski jessegrabowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work as always! Left some feedback.

Also rebase, we just merged the Pytensor update that will fix tests.

def __init__(
self,
k_exog: int | None = None,
# k_exog: int | None = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete, no need to leave flotsam in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My apologies, I missed that. I will delete it in the next push.

return exog_dims


def _validate_endog_names(endog_names) -> int:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to validate_names, and add a optional: bool =True argument so it can either error or return None. Then you can eliminate _get_state_names in the regression component and use this instead. Also can use it for the exog names in SARIMAX, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a var_name argument as well so that if it does raise a value error the message will clearly state what variable is missing.


@pytest.mark.filterwarnings(
"ignore::RuntimeWarning"
) # Needed this due to RuntimeWarning: divide by zero encountered in matmul
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you on a Mac? This is a known bug with Mx chips, see here: numpy/numpy#29820

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I am on a Mac. Should I run in x86 using rosetta instead until they fix the issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No its fine, it doesn't actually do anything. But you don't need to filterwarnings either. You can just do it locally for your own testing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that is reasonable. I removed the filter before pushing new commits.

Comment on lines 204 to 219
# def test_create_varmax_with_exogenous_k_exog_int(self, data):
# mod = BayesianVARMAX(
# endog_names=["realgdp", "realcons", "realinv"],
# order=(1, 0),
# exog_state_names=["exogenous_0", "exogenous_1"],
# verbose=False,
# measurement_error=False,
# stationary_initialization=False,
# )
# assert mod.k_exog == 2
# assert mod.exog_state_names == ["exogenous_0", "exogenous_1"]
# assert mod.data_names == ["exogenous_data"]
# assert mod.param_dims["beta_exog"] == ("observed_state", "exogenous")
# assert mod.coords["exogenous"] == ["exogenous_0", "exogenous_1"]
# assert mod.param_info["beta_exog"]["shape"] == (mod.k_endog, 2)
# assert mod.param_info["beta_exog"]["dims"] == ("observed_state", "exogenous")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(also applies to other commented out blocks below)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, will do! Didn't want to delete anything before you approve of it.

}
else:
exog_names = exog_state_names or [f"exogenous_{i}" for i in range(k_exog)]
exog_names = exog_state_names
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be misunderstanding your question, but I removed the or statement because there no longer is a k_exog parameter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant why keep this, since all it does is rename a variable. There should be a more elegant way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are absolutely right. That is silly. I changed it to directly pass in exog_state_names.

@Dekermanjian Dekermanjian force-pushed the remove_kendog_kexog_ssm branch from 9a3e24d to 330dc19 Compare October 29, 2025 23:12
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

Successfully merging this pull request may close these issues.

Remove k_endog argument from statespace model constructors VARMAX input validation functionality should be moved out to a helper

2 participants