-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Sl/numba tauchen #227
Sl/numba tauchen #227
Conversation
efbe114
to
5e9a6af
Compare
Speedup very impressive. I have a not-so-important comment. In the loop, Something like: def _fill_tauchen(x, P, n, rho, sigma, step):
for i in range(n):
w = x[0] - rho * x[i] + step / 2
P[i, 0] = std_norm_cdf(w / sigma)
for j in range(1, n - 1):
P[i, j] = -std_norm_cdf(w / sigma)
w += step
P[i, j] += std_norm_cdf(w / sigma)
P[i, n-1] = 1 - std_norm_cdf(w / sigma) or def _fill_tauchen(x, P, n, rho, sigma, step):
step_sigma = step / sigma
for i in range(n):
w = (x[0] - rho * x[i] + step / 2) / sigma
P[i, 0] = std_norm_cdf(w)
for j in range(1, n - 1):
P[i, j] = -std_norm_cdf(w)
w += step_sigma
P[i, j] += std_norm_cdf(w)
P[i, n-1] = 1 - std_norm_cdf(w) (Speedup may be negligible though.) |
The performance gains seem indeed quite good. There is probably no point in looking for further improvements, since it is unlikely that I still did a bit of digging. Most performance costs seem to come from the |
I agree with @albop that it is probably futile to look for more performance gains, but fwiw this was faster on my computer (but only marginally and we lose the benefit of the function being jitted).
|
The Anyway, I would be happy merging either this or Chase's function. I'm indifferent between the two. Also agree with @albop that searching for milliseconds here probably doesn't need to be a priority. I just didn't like waiting 35+ seconds to initialize a model when I knew it could take under a second ;) |
I have slight preference for the numbaized function. Cleaner and the difference is pretty negligible (and sounds like it will get better for free). |
Yes, @cc7768, it will get better over time.
On my machine, this test produces the following timing:
It is a bit more than 20 times faster than the cpython version ! |
With the libm version of Just to be clear: my vote goes to keep the numbaized version exactly as it is and not bother with including more optimization. |
Thanks for checking out those benchmarks. I think that as long as @jstac is ok with this, we can merge as is |
Thanks all for the discussion. I've been following and I've learned from reading it. It makes sense to Numba-fy the routine and I agree that we don't need to search for the last drop of speed here. As a general comment for this PR and others, you guys are in charge of QE.py and QE.jl so please feel free to merge without my input. They are really your libraries now, and you are better equipped to take the lead than I am. If it's a change that affects the lectures, I'd appreciate if you let me know (although it's not actually your responsibility, and in any case I follow the discussions in the PRs). It will be the job of Tom and I to keep the lectures up to date with changes that you guys make to the libraries. For QuantEcon.applications, Tom and I still need to take charge of changes there, since that repo just serves the lectures at this stage. |
Sounds great, thanks @jstac! |
@spencerlyon2 thanks for this update. Do you mind if we delete the branch? |
Not at all. Let's keep things tidy // Spencer
|
I needed a faster version of tauchen, so I dropped the loops into numba.
Here are the before timings (on the actual size problem I'm working on in the application):
After timings:
Not quite as quick as the Julia, but much closer (julia timings below).