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

Random walk, random method #3682

Merged
merged 10 commits into from
Nov 18, 2019
Merged

Conversation

ColCarroll
Copy link
Member

Was updating the stochastic volatility notebook, and wanted to sample from the prior predictive for Gaussian Random Walk. This PR:

  • Makes that work
  • Updates the StochasticVolatility notebook
  • Updates the S&P 500 data to go up until yesterday (so 11 years of returns)

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

You'll be able to see Jupyter notebook diff and discuss changes. Powered by ReviewNB.

@ColCarroll
Copy link
Member Author

Note that the new data, which ships with the library, is 128kb, compared with the current 14kb. I can zip it (which pandas can read just fine) to get that down to 48kb.

The final image in the notebook now looks like this, in case anyone is interested in what the last 11 years have looked like. I have also put the old final image below for comparison:

image

image

@junpenglao
Copy link
Member

Could you try to modify the prior a bit more to get rid of the rhat warning?

@fonnesbeck
Copy link
Member

Yeah, I would swap samples and tuning, and take 1000 after 2000 burnin (that's a pretty reasonable default for a lot of models).

@codecov
Copy link

codecov bot commented Nov 16, 2019

Codecov Report

Merging #3682 into master will increase coverage by 0.07%.
The diff coverage is 93.18%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3682      +/-   ##
==========================================
+ Coverage   89.82%   89.89%   +0.07%     
==========================================
  Files         134      134              
  Lines       20133    20166      +33     
==========================================
+ Hits        18084    18129      +45     
+ Misses       2049     2037      -12
Impacted Files Coverage Δ
pymc3/tests/test_distributions_random.py 99.13% <90.9%> (-0.14%) ⬇️
pymc3/distributions/timeseries.py 71.65% <93.93%> (+11.9%) ⬆️

@ColCarroll
Copy link
Member Author

Sampling works now (2000 draw, 2000 tune -- it works ~usually with 1000/1000 but I wanted to do it without just picking the "right" random seed).

Also updated the shape handling if you really want a vectorized mu or sd.

@ColCarroll
Copy link
Member Author

Hoping to merge this tonight if there are no further suggestions!

RELEASE-NOTES.md Outdated Show resolved Hide resolved
pymc3/distributions/timeseries.py Outdated Show resolved Hide resolved
pymc3/distributions/timeseries.py Outdated Show resolved Hide resolved
pymc3/distributions/timeseries.py Show resolved Hide resolved
pymc3/tests/test_distributions_random.py Show resolved Hide resolved
def _random(self, sigma, mu, size):
"""Implement a Gaussian random walk as a cumulative sum of normals."""
rv = stats.norm(mu, sigma)
return rv.rvs(size).cumsum(axis=0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Careful with axis=0. If mu is an RV, its drawn value will have the size prepend, and that will shift the time series axis further to the right.

Copy link
Contributor

@lucianopaz lucianopaz left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks @colcarrol!

@lucianopaz lucianopaz merged commit 2b7f302 into pymc-devs:master Nov 18, 2019
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.

None yet

4 participants