Skip to content

Commit

Permalink
final change before rewrite of variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacLN committed Feb 2, 2016
1 parent 12540a5 commit 0af52e9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
17 changes: 12 additions & 5 deletions src/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ function Model(foc::Expr,states::Expr,policy::Expr,vars::Expr,params::Expr;BF=Qu
else
push!(static.args,vars.args[i])
end
else
warn("$(vars.args[i].args[1]) not succesfully parsed")
end
end

Expand Down Expand Up @@ -118,10 +120,15 @@ function Model(foc::Expr,endogenous::Expr,exogenous::Expr,policy::Expr,static::E
Static,
ones(length(State.G),Policy.n),
params,
eval(:($(gensym(:F))(M) = @fastmath $(buildfunc(subs(foc,Dict(zip(vlist[:,1],vlist[:,2]))),:(M.error))) )),
eval(:($(gensym(:J))(M,i) = @fastmath $(buildJ(vec(subs(jacobian(foc,[Expr(:ref,v,0) for v in Policy.names]),Dict(zip(vlist[:,1],vlist[:,2])))))) )),
eval(:($(gensym(:Fslow))(M) = @fastmath $(buildfunc(addpweights!(subs(focslow,Dict(zip(vlist[:,1],vlist[:,2]))),Future.nP),:(M.error))) )),
eval(:( $(gensym(:Jslow))(M,i) = @fastmath $(buildJ(vec(addpweights!(subs(Js,Dict(zip(vlist[:,1],vlist[:,2]))),Future.nP)))) )),
eval(:($(gensym(:E))(M) = @fastmath $(buildfunc(addpweights!(subs(expects,Dict(zip(vlist[:,1],vlist[:,2]))),Future.nP),:(M.temporaries.E))))),
# eval(:($(gensym(:F))(M) = @fastmath $(buildfunc(subs(foc,Dict(zip(vlist[:,1],vlist[:,2]))),:(M.error))) )),
# eval(:($(gensym(:J))(M,i) = @fastmath $(buildJ(vec(subs(jacobian(foc,[Expr(:ref,v,0) for v in Policy.names]),Dict(zip(vlist[:,1],vlist[:,2])))))) )),
# eval(:($(gensym(:Fslow))(M) = @fastmath $(buildfunc(addpweights!(subs(focslow,Dict(zip(vlist[:,1],vlist[:,2]))),Future.nP),:(M.error))) )),
# eval(:( $(gensym(:Jslow))(M,i) = @fastmath $(buildJ(vec(addpweights!(subs(Js,Dict(zip(vlist[:,1],vlist[:,2]))),Future.nP)))) )),
# eval(:($(gensym(:E))(M) = @fastmath $(buildfunc(addpweights!(subs(expects,Dict(zip(vlist[:,1],vlist[:,2]))),Future.nP),:(M.temporaries.E))))),
eval(:($(gensym(:F))(M) = @fastmath $(buildfunc(subs(foc,vlist),:(M.error))) )),
eval(:($(gensym(:J))(M,i) = @fastmath $(buildJ(vec(subs(jacobian(foc,[Expr(:ref,v,0) for v in Policy.names]),vlist)))) )),
eval(:($(gensym(:Fslow))(M) = @fastmath $(buildfunc(addpweights!(subs(focslow,vlist),Future.nP),:(M.error))) )),
eval(:( $(gensym(:Jslow))(M,i) = @fastmath $(buildJ(vec(addpweights!(subs(Js,vlist),Future.nP)))) )),
eval(:($(gensym(:E))(M) = @fastmath $(buildfunc(addpweights!(subs(expects,vlist),Future.nP),:(M.temporaries.E))))),
Temporaries(zeros(length(State.G),Future.n),zeros(Policy.n,Policy.n)))
end
18 changes: 10 additions & 8 deletions src/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,23 +156,25 @@ function addpweights!(x,nP)
return x
end


function getvlist(State::StateVariables,Policy::PolicyVariables,Future::FutureVariables,Auxillary::AuxillaryVariables,Aggregate::AggregateVariables,expects)
vlist = Dict()

vlist = vcat([[Expr(:ref,State.names[i],-1) Expr(:ref,:(M.state.X),:i,i)] for i = 1:State.nendo]...)
[push!(vlist,Expr(:ref,State.names[i],-1) => Expr(:ref,:(M.state.X),:i,i)) for i = 1:State.nendo]

vlist = vcat(vlist,vcat([[Expr(:ref,State.names[i],0) Expr(:ref,:(M.state.X),:i,i)] for i = State.nendo+1:State.n]...))
[push!(vlist,Expr(:ref,State.names[i],0) => Expr(:ref,:(M.state.X),:i,i)) for i = State.nendo+1:State.n]

vlist = vcat(vlist,vcat([[Expr(:ref,State.names[i],1) Expr(:ref,:(M.future.state),:(i+(j-1)*length(M.state.G)),i)] for i = State.nendo+1:State.n]...))
[push!(vlist,Expr(:ref,State.names[i],1) => Expr(:ref,:(M.future.state),:(i+(j-1)*length(M.state.G)),i)) for i = State.nendo+1:State.n]

vlist = vcat(vlist,vcat([[Expr(:ref,Policy.names[i],0) Expr(:ref,:(M.policy.X),:i,i)] for i = 1:Policy.n]...))
[push!(vlist,Expr(:ref,Policy.names[i],0) => Expr(:ref,:(M.policy.X),:i,i)) for i = 1:Policy.n]

Auxillary.n>0 ? vlist = vcat(vlist,vcat([[Expr(:ref,Auxillary.names[i],0) Expr(:ref,:(M.auxillary.X),:i,i)] for i = 1:Auxillary.n]...)) : nothing
Auxillary.n>0 ? [push!(vlist,Expr(:ref,Auxillary.names[i],0) => Expr(:ref,:(M.auxillary.X),:i,i)) for i = 1:Auxillary.n]: nothing

Aggregate.n>0 ? vlist = vcat(vlist,vcat([[Expr(:ref,Aggregate.names[i],0) Expr(:ref,:(M.aggregate.X),:i,i)] for i = 1:Aggregate.n]...)) : nothing
Aggregate.n>0 ? [push!(vlist,Expr(:ref,Aggregate.names[i],-1) => Expr(:ref,:(M.aggregate.X),:i,i)) for i = 1:Aggregate.n] : nothing

vlist = vcat(vlist,vcat([[Expr(:ref,Future.names[i],1) Expr(:ref,:(M.future.X),:(i+(j-1)*length(M.state.G)),i)] for i = 1:length(Future.names)]...))
[push!(vlist,Expr(:ref,Future.names[i],1) => Expr(:ref,:(M.future.X),:(i+(j-1)*length(M.state.G)),i)) for i = 1:length(Future.names)]

vlist = vcat(vlist,vcat([[Expr(:ref,:Expect,i) :(M.temporaries.E[i,$i])] for i = 1:length(expects.args)]...))
[push!(vlist,Expr(:ref,:Expect,i) => :(M.temporaries.E[i,$i])) for i = 1:length(expects.args)]

return vlist
end
Expand Down
2 changes: 1 addition & 1 deletion src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ type StaticVariables
for i = 1:length(snames)
s = snames[i]
targ = static[s]
targ = subs(targ,Dict(zip(vlist[:,1],vlist[:,2])))
targ = subs(targ,vlist)
push!(bigS.args[2].args,:(M.static.X[i,$i] = $targ))
end

Expand Down
6 changes: 4 additions & 2 deletions test/foctest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ BF=QuadraticBF
c = (0,5,0.4)
],:[
λ = c^-σc
R = 1-δ+(α)*ηz*A^-1)*H^(1-α)
W = (1-α)*ηz*A^α*H^(-α)
R = 1-δ+(α)*ηz*A[-1]^-1)*H^(1-α)
W = (1-α)*ηz*A[-1]^α*H^(-α)
A = (b,40)
H = (η,0.9)
],:[
Expand Down Expand Up @@ -48,6 +48,8 @@ for i = 1:length(vars.args)
else
push!(static.args,vars.args[i])
end
else
warn("$(vars.args[i].args[1]) not succesfully parsed")
end
end

Expand Down

0 comments on commit 0af52e9

Please sign in to comment.