-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Extend simulate
to multidimensional states
#4
Comments
I think it would be great to extend QuantEcon.LinInterp -- I've received multiple requests to do so. In the short run (before someone finds the time to make that happen), we could use |
I didn't think about Suppose I have a Matrix |
You use Here's a 2d example: lin_basis = Basis(LinParams(nodes_dim1, 0), LinParams(nodes_dim2, 0))
# get coefs from somewhere...
# option one
funeval(coefs, lin_basis, eval_nodes)
# option two (more efficient)
funeval(coefs, basis, (vec_of_1st_dim, vec_of_2nd_dim)) Both of the |
One note about the comment to With that in mind, you can just set |
Maybe I should change the implementation, but the current code only stores |
So here's an example of how you can use function simulate_lin_params!(rng::AbstractRNG, s_path::TS,
res::ContinuousDPs.CDPSolveResult{Algo,N,TR,TS},
s_init) where {Algo,N,TR,TS<:VecOrMat}
ts_length = size(s_path)[end]
cdf = cumsum(res.cdp.weights)
r = rand(rng, ts_length-1)
e_ind = Array{Int}(ts_length-1)
for t in 1:ts_length-1
e_ind[t] = searchsortedlast(cdf, r[t]) + 1
end
basis = Basis(map(LinParams, res.cdp.interp.Scoord, ntuple(i -> 0, ndims(res.cdp))))
X_interp = Interpoland(basis, res.X)
s_ind_front = Base.front(indices(s_path))
e_ind_tail = Base.tail(indices(res.cdp.shocks))
s_path[(s_ind_front..., 1)...] = s_init
for t in 1:ts_length-1
s = s_path[(s_ind_front..., t)...]
e = res.cdp.shocks[(e_ind[t], e_ind_tail...)...]
s_path[(s_ind_front..., t+1)...] = res.cdp.g(s, X_interp(s), e)
end
return s_path
end I've tested this using the monetary policy example from the MF notebook and the opt_Growth example from the other example notebook and it seems to work. The only issue is that it assumes that |
Note that when I say
I really should be more precise and say what you said:
|
Also to answer your question
When you use If I had two dimensions in my basis, then using the Expanded form to evaluate at
|
|
Done. |
So far 1dim linear interpolation
QuantEcon.LinInterp
is used to interpolate the optimal policy function.QuantEcon/QuantEcon.jl#190
The text was updated successfully, but these errors were encountered: