Comments (24)
from pymc-experimental.
from pymc-experimental.
I can take a look, but this is just a debug function. Why are you using it? There is a large test suite that checks that the statespace models match the statsmodels outputs.
from pymc-experimental.
I use it because it makes data generation for a given state-space model easy, much better than statsmodel (as far as I know).
from pymc-experimental.
In this specific case, statsmodels expects sigma squared, whereas the structural model expects sigma. If you remove the square root from the structural model (but not the statsmodel argument), you will get the same output, modulo random draws. I don't think setting the seed is enough to guarantee the same outputs between the two functions, because there might be differences in how/when each random number is generated (all at once vs one-by-one in loop, for example).
I'm not sure what your exact use-case in, but in general I suggest you use the usual PyMC API to generate draws from the statespace models, rather than the testing function.
from pymc-experimental.
from pymc-experimental.
measurement_error = st.MeasurementError(name="obs")
IRW = st.LevelTrendComponent(order=2, innovations_order=[0, 1])
# Change sigma_trend to remove the square root
param_dict = {
"initial_trend": [0., 0.01], "sigma_trend": np.array([5e-7]),
"sigma_obs": np.array([0.]),
}
mod = IRW + measurement_error
nobs = 1024 # we simulate a time series of length Nobs
x, y = simulate_from_numpy_model(mod, np.random.default_rng(2163), param_dict, steps=nobs)
# sm part unchanged
fig, ax = plt.subplots()
ax.plot(y, label='Structural')
ax.plot(y_sim, label='Statsmodels')
ax.legend()
plt.show()
This now looks correct to me?
from pymc-experimental.
from pymc-experimental.
Yeah that's a fair point, the name is not consistent with what you get. Currently, whatever number you pass in is directly plugged into the Q matrix at whatever position on the main diagonal, so either it should be squared internally (this is what statsmodels does) or the name should be changed.
My preference would be to square things internally and keep the name the same, because no other PyMC distributions are parameterized by the variance directly. Does that seem reasonable?
from pymc-experimental.
from pymc-experimental.
from pymc-experimental.
It applies to all shocks in all structural models I believe. I will have to check them all.
from pymc-experimental.
from pymc-experimental.
You'll have to pip install the main branch from github. We haven't done a new release yet, so just doing pip install pymc-experimental
won't have the patch
from pymc-experimental.
from pymc-experimental.
It's similar to what you did before when you were installing from my branch, but now just targeting the main branch. Should be something like:
pip install git+https://github.com/pymc-devs/pymc-experimental.git
from pymc-experimental.
from pymc-experimental.
Make sure you pip uninstall pymc-experimental first
from pymc-experimental.
from pymc-experimental.
from pymc-experimental.
I just tested the command on my computer and it seems like it works. There hasn't been a release, so the version won't be bumped by this command.
You can check the source code by e.g. st.MeasurementError??
(in a Jupyter notebook) and check that you see the sigma being squared in the make_symbolic_graph
method, like this:
def make_symbolic_graph(self) -> None:
error_sigma = self.make_and_register_variable(f"sigma_{self.name}", shape=(self.k_endog,))
diag_idx = np.diag_indices(self.k_endog)
idx = np.s_["obs_cov", diag_idx[0], diag_idx[1]]
self.ssm[idx] = error_sigma**2
from pymc-experimental.
from pymc-experimental.
Everything works as it appears now. You put a prior on sigma (the standard deviation), which is then squared and placed on the diagonal of the covariance matrix.
from pymc-experimental.
from pymc-experimental.
Related Issues (20)
- Add .to_zarr to model builder save function HOT 4
- Add notebook example on how to use BlackJax SMC from pymc models
- Consider renaming to pymc-extras
- Re-working `as_model` HOT 10
- Pathfinder gives confident wrong answer with small sample prediction HOT 5
- Error message from build_statespace_graph when cycle is one of the model components.
- Add test for MarginalModel where variable depends on two marginalized variables
- including cyclic or seasonal components causes error messages from build_statespace_graph since last bug fix
- Support batched constant arguments when marginalising `DiscreteUniform` HOT 1
- use dict instead of treedict in marginalized model HOT 1
- `statespace`: Leveraging RegressionComponent yields error HOT 6
- Error messages when using the pymc or nutpie NUTS samplers in combination with pymc-experimental HOT 8
- MarginalModel fails with Data containers
- `test_histogram_approximation` failing due to warning in newer JAX release HOT 5
- `MarginalModel.unmarginalize` doesn't accept `var_names` HOT 2
- `recover_marginals` should have a progress bar
- Support marginalization of HMM with higher lag orders
- In model_builder, _validate_data changes input type HOT 1
- MarginalModel freezes mutable dim lengths HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pymc-experimental.