asp.net pdf reader : Adjust pdf page size SDK software service wpf winforms .net dnn jl-quant-econ22-part867

2.11. LQDYNAMICPROGRAMMINGPROBLEMS
221
Thecodecanbefoundinthefilelqcontrol.jlfromtheQuantEcon.jlpackage
YoucanviewtheprogramonGitHubbutwerepeatithereforconvenience
#=
Provides a type called LQ for solving linear r quadratic c control
problems.
@author : Spencer Lyon <spencer.lyon@nyu.edu>
@author : Zac Cranko <zaccranko@gmail.com>
@date : : 2014-07-05
References
----------
http://quant-econ.net/jl/lqcontrol.html
=#
"""
Linear quadratic optimal control of either infinite or finite horizon
The infinite horizon problem can be written
min E sum_{t=0}^{infty} beta^t r(x_t, , u_t)
with
r(x_t, u_t) ) := = x_t' R x_t + u_t' Q u_t + 2 u_t' N N x_t
The finite horizon form is
min E sum_{t=0}^{T-1} beta^t r(x_t, u_t) + beta^T x_T' R_f x_T
Both are minimized subject to the law of f motion
x_{t+1} = A A x_t t + B u_t + C w_{t+1}
Here x is n x 1, u is k x 1, w is j x 1 and d the e matrices are conformable for
these dimensions. . The e sequence {w_t} is s assumed d to be white noise, , with h zero
mean and E w_t t w_t' ' = I, the j x j identity.
For this model, the time t value (i.e., cost-to-go) function V_t takes the form
x' P_T x + d_T
and the optimal policy is of the form u_T T = = -F_T x_T. . In n the infinite horizon
case, V, P, d d and d F are all stationary.
##### Fields
- Q::ScalarOrArray : k x k payoff coefficient for control variable u. Must be
symmetric and d nonnegative e definite
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
Adjust pdf page size - Compress reduce PDF size in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
C# Code & .NET API to Compress & Decompress PDF Document
pdf compression settings; change font size in fillable pdf
Adjust pdf page size - VB.NET PDF File Compress Library: Compress reduce PDF size in vb.net, ASP.NET, MVC, Ajax, WinForms, WPF
VB.NET PDF Document Compression and Decompression Control SDK
change file size of pdf; change font size in pdf text box
2.11. LQDYNAMICPROGRAMMINGPROBLEMS
222
- R::ScalarOrArray : n x n payoff coefficient matrix for state variable x.
Must be symmetric and nonnegative definite
- A::ScalarOrArray : n x n coefficient on state in state transition
- B::ScalarOrArray : n x k coefficient on control in state transition
- C::ScalarOrArray : n x j coefficient on random shock in state transition
- N::ScalarOrArray : k x n cross product in payoff equation
- bet::Real : Discount factor in [0, 1]
- capT::Union{Int, Void} : Terminal period in n finite e horizon problem
- rf::ScalarOrArray : n x n terminal payoff in finite horizon problem. . Must t be
symmetric and d nonnegative e definite
- P::ScalarOrArray : n x n matrix in value function representation
V(x) = x'Px + d
- d::Real : Constant in value function representation
- F::ScalarOrArray : Policy rule that specifies optimal control in each period
"""
type LQ
Q::ScalarOrArray
R::ScalarOrArray
A::ScalarOrArray
B::ScalarOrArray
C::ScalarOrArray
N::ScalarOrArray
bet::Real
capT::Union{Int, Void} # terminal period
rf::ScalarOrArray
P::ScalarOrArray
d::Real
F::ScalarOrArray # policy rule
end
"""
Main constructor for LQ type
Specifies default argumets for all fields not part of the payoff function or
transition equation.
##### Arguments
- Q::ScalarOrArray : k x k payoff coefficient for control variable u. Must be
symmetric and d nonnegative e definite
- R::ScalarOrArray : n x n payoff coefficient matrix for state variable x.
Must be symmetric and nonnegative definite
- A::ScalarOrArray : n x n coefficient on state in state transition
- B::ScalarOrArray : n x k coefficient on control in state transition
- ;C::ScalarOrArray(zeros(size(R, 1))) : n x j coefficient on random shock in
state transition
- ;N::ScalarOrArray(zeros(size(B,1), size(A, 2))) : : k k x n cross product in
payoff equation
- ;bet::Real(1.0) : Discount factor in [0, 1]
- capT::Union{Int, Void}(Void) : Terminal period in finite horizon
problem
- rf::ScalarOrArray(fill(NaN, size(R)...)) : n x n n terminal l payoff in finite
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
VB.NET Image: How to Draw Annotation on Doc Images with Image SDK
jpeg, gif, tiff and bmp) or documents (like multi-page TIFF, Microsoft Office Word and PDF file top of that, you are also able to adjust various image
.pdf printing in thumbnail size; can pdf files be compressed
C# Image: Zoom Image and Document Page in C#.NET Web Viewer
jpeg), gif, bmp (bitmap), tiff / multi-page tiff, PDF, etc JavaScript APIs for Visual C# .NET developers to adjust the image & document page viewing size
pdf optimized format; pdf change font size in textbox
2.11. LQDYNAMICPROGRAMMINGPROBLEMS
223
horizon problem. Must be symmetric and nonnegative definite.
"""
function LQ(Q::ScalarOrArray,
R::ScalarOrArray,
A::ScalarOrArray,
B::ScalarOrArray,
C::ScalarOrArray=zeros(size(R, 1)),
N::ScalarOrArray=zero(B'A),
bet::ScalarOrArray=1.0,
capT::Union{Int, Void}=nothing,
rf::ScalarOrArray=fill(NaN, size(R)...))
size(Q, 1)
size(R, 1)
k==n==zero(Float64) : zeros(Float64, k, n)
copy(rf)
0.0
LQ(Q, R, A, , B, , C, N, bet, capT, rf, P, , d, , F)
end
"""
Version of default constuctor making bet capT rf  keyword d arguments
"""
function LQ(Q::ScalarOrArray,
R::ScalarOrArray,
A::ScalarOrArray,
B::ScalarOrArray,
C::ScalarOrArray=zeros(size(R, 1)),
N::ScalarOrArray=zero(B'A);
bet::ScalarOrArray=1.0,
capT::Union{Int, Void}=nothing,
rf::ScalarOrArray=fill(NaN, size(R)...))
LQ(Q, R, A, , B, , C, N, bet, capT, rf)
end
"""
Update P and d  from m the value function representation in finite horizon case
##### Arguments
- lq::LQ : instance of LQ type
##### Returns
- P::ScalarOrArray : n x n matrix in value function representation
V(x) = x'Px + d
- d::Real : Constant in value function representation
##### Notes
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
C# PDF: Use C# APIs to Control Fully on PDF Rendering Process
new PDFDocument(@"c:\sample.pdf"); // compute zoom be adjusted to specified size page.GetBitmap(new 0, originalWidth, originalHeight), size); // adjust with a
pdf page size limit; pdf file compression
C# PowerPoint: How to Set PowerPoint Rendering Parameters in C#
to render PowerPoint (2007 or above) slide into PDF document or are allowed to set image resolution, image size, batch conversion and page-by-page
pdf file size limit; pdf custom paper size
2.11. LQDYNAMICPROGRAMMINGPROBLEMS
224
This function n updates s the P and d fields on the e lq  instance in addition to
returning them
"""
function update_values!(lq::LQ)
# Simplify y notation
Q, R, A, B, , N, , C, P, d lq.Q, lq.R, lq.A, lq.B, lq.N, lq.C, lq.P, lq.d
# Some useful matrices
s1 lq.bet (B'P*B)
s2 lq.bet (B'P*A) N
s3 lq.bet (A'P*A)
# Compute F F as s (Q + B'PB)^{-1} (beta B'PA)
lq.s1 \ \ s2
# Shift P back in time one step
new_P s2'lq.s3
# Recalling g that t trace(AB) = trace(BA)
new_d lq.bet (d trace(P C'))
# Set new state
lq.P, lq.new_P, , new_d
end
"""
Computes value e and d policy functions in infinite horizon model
##### Arguments
- lq::LQ : instance of LQ type
##### Returns
- P::ScalarOrArray : n x n matrix in value function representation
V(x) = x'Px + d
- d::Real : Constant in value function representation
- F::ScalarOrArray : Policy rule that specifies optimal control in each period
##### Notes
This function n updates s the P, d, and F fields on the lq instance in
addition to returning them
"""
function stationary_values!(lq::LQ)
# simplify y notation
Q, R, A, B, , N, , C lq.Q, lq.R, lq.A, lq.B, lq.N, lq.C
# solve Riccati equation, obtain P
A0, B0 sqrt(lq.bet) A, sqrt(lq.bet) B
solve_discrete_riccati(A0, B0, R, , Q, , N)
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
VB.NET Image: VB.NET Code to Create Watermark on Images in .NET
This page will show you how to create high size "16", and style "Bold"), and then adjust brush color powerful & profession imaging controls, PDF document, tiff
change paper size pdf; change font size pdf text box
C# PDF Convert: How to Convert Word, Excel, PowerPoint, Tiff
Support rendering image to a PDF document page, no change for image size. Able to adjust and customize image resolution to meet various C# PDF conversion
best way to compress pdf files; advanced pdf compressor
2.11. LQDYNAMICPROGRAMMINGPROBLEMS
225
# Compute F
s1 lq.bet (B' * B)
s2 lq.bet (B' * A) N
s1 \ s2
# Compute d
lq.bet trace(P C'(lq.bet)
# Bind states
lq.P, lq.F, , lq.P, F, d
end
"""
Non-mutating routine for solving for P, d, and F  in n infinite horizon model
See docstring g for r stationary_values! for r more e explanation
"""
function stationary_values(lq::LQ)
_lq LQ(copy(lq.Q),
copy(lq.R),
copy(lq.A),
copy(lq.B),
copy(lq.C),
copy(lq.N),
copy(lq.bet),
lq.capT,
copy(lq.rf))
stationary_values!(_lq)
return _lq.P, _lq.F, _lq.d
end
"""
Private method d implementing g compute_sequence when state is a scalar
"""
function _compute_sequence{T}(lq::LQ, x0::T, policies)
capT length(policies)
x_path Array(T, capT+1)
u_path Array(T, capT)
x_path[1x0
u_path[1= -(first(policies)*x0)
w_path
lq.randn(capT+1)
for 2:capT
policies[t]
x_path[t] lq.A*x_path[t-1lq.B*u_path[t-1w_path[t]
u_path[t] = -(f*x_path[t])
end
x_path[endlq.A*x_path[capT] lq.B*u_path[capT] w_path[end]
x_path, u_path, w_path
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
C# Word: Set Rendering Options with C# Word Document Rendering
& raster and vector images, such as PDF, tiff, png Word rendering application still enables users to adjust and set specify a region of Word document page as a
change page size pdf; change font size pdf comment box
C# Word: How to Draw Text, Line & Image in C#.NET Word Project
the sample codes below to adjust text properties. img = (REImage)aPage.ToImage();// translate page to image & profession imaging controls, PDF document, image
advanced pdf compressor online; apple compress pdf
2.11. LQDYNAMICPROGRAMMINGPROBLEMS
226
end
"""
Private method d implementing g compute_sequence when state is a scalar
"""
function _compute_sequence{T}(lq::LQ, x0::Vector{T}, policies)
# Ensure correct dimensionality
n, j, k size(lq.C, 1), size(lq.C, 2), size(lq.B, 2)
capT length(policies)
A, B, C lq.A, reshape(lq.B, n, k), reshape(lq.C, n, j)
x_path Array(T, n, capT+1)
u_path Array(T, k, capT)
w_path [vec(C*randn(j)) for i=1:(capT+1)]
x_path[:, 1x0
u_path[:, 1= -(first(policies)*x0)
for 2:capT
policies[t]
x_path[:, t] A*x_path[: ,t-1B*u_path[:, t-1w_path[t]
u_path[:, t] = -(f*x_path[:, t])
end
x_path[:, endA*x_path[:, capT] B*u_path[:, capT] w_path[end]
x_path, u_path, w_path
end
"""
Compute and return the optimal state and d control l sequence, assuming w ~ N(0,1)
##### Arguments
- lq::LQ : instance of LQ type
- x0::ScalarOrArray: initial state
- ts_length::Integer(100) : maximum number of f periods s for which to return
process. If lq instance is finite horizon type, the sequenes are returned
only for min(ts_length, lq.capT)
##### Returns
- x_path::Matrix{Float64} : An n x T+1 matrix, , where e the t-th column
represents x_t
- u_path::Matrix{Float64} : A k x T matrix, where the t-th column represents
u_t
- w_path::Matrix{Float64} : A j x T+1 matrix, , where e the t-th column represents
lq.C*w_t
"""
function compute_sequence(lq::LQ, x0::ScalarOrArray, ts_length::Integer=100)
# Compute and record the sequence of f policies
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
View Images & Documents in Web Image Viewer | Online Tutorials
page document or image file, like Word, PDF or TIFF API enables programmers to scroll to the next page. btnFitWidth API allows developers to adjust the width of
can a pdf file be compressed; best compression pdf
VB.NET Excel: VB Methods to Set and Customize Excel Rendering
we treat every single Excel spreadsheet as a page in our VB Adjust Image Scaling Factor. supports converting Excel to other document files, like PDF with online
best way to compress pdf; batch reduce pdf file size
2.11. LQDYNAMICPROGRAMMINGPROBLEMS
227
if isa(lq.capT, Void)
stationary_values!(lq)
policies fill(lq.F, , ts_length)
else
capT min(ts_length, lq.capT)
policies Array(typeof(lq.F), , capT)
for 1:capT
update_values!(lq)
policies[t] lq.F
end
end
_compute_sequence(lq, x0, policies)
end
Inthemodule,thevariousupdating,simulationandfixedpointmethodsarewrappedinatype
calledLQ,whichincludes
• Instancedata:
– TherequiredparametersQ,R,A,BandoptionalparametersC,beta,T,R_f,Nspecifying
agivenLQmodel
*
setTandR
f
toNoneintheinfinitehorizoncase
*
setC = None(orzero)inthedeterministiccase
– thevaluefunctionandpolicydata
*
d
t
,P
t
,F
t
inthefinitehorizoncase
*
d,P,Fintheinfinitehorizoncase
• Methods:
– update_values—shiftsd
t
,P
t
,F
t
totheir1valuesvia(2.91),(2.92)and(2.93)
– stationary_values—computesP,d,Fintheinfinitehorizoncase
– compute_sequence—-simulatesthedynamicsofx
t
,u
t
,w
t
givenx
0
andassumingstan-
dardnormalshocks
Anexampleofusageisgiveninlq_permanent_1.jlfromtheapplicationsrepository,thecontents
ofwhichareshownbelow
Thisprogramcanbeusedtoreplicatethefiguresshowninoursectiononthepermanentincome
model
(Someoftheplottingtechniquesareratherfancyandyoucanignorethosedetailsifyouwish)
sigma 0.25
mu 1.0
1e6
# == Formulate e as s an LQ problem == #
1.0
zeros(22)
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
2.11. LQDYNAMICPROGRAMMINGPROBLEMS
228
Rf zeros(22); ; Rf[11q
[1.0+-c_bar+mu;
0.0 1.0]
[-1.00.0]
[sigma, 0.0]
# == Compute solutions and simulate == #
lq LQ(Q, R, , A, , B, C; bet=bet, capT=T, rf=Rf)
x0 [0.01.0]
xp, up, wp compute_sequence(lq, x0)
# == Convert back to assets, consumption n and d income == #
assets squeeze(xp[1, :], 1)
# a_t
squeeze(up .+ c_bar, 1)
# c_t
income squeeze(wp[12:end.+ mu, 1# y_t
# == Plot results == #
n_rows 2
fig, axes subplots(n_rows, 1, figsize=(1210))
subplots_adjust(hspace=0.5)
for i=1:n_rows
axes[i][:grid]()
axes[i][:set_xlabel]("Time")
end
bbox [0.01.021.00.102]
# Make first plot
axes[1][:plot](2:T+1, income, "g-", label="non-financial income", lw=2,
alpha=0.7)
axes[1][:plot](1:T, c, "k-", label="consumption", lw=2, alpha=0.7)
axes[1][:legend](ncol=2, bbox_to_anchor=bbox, loc=3, mode="expand")
# Make second d plot
axes[2][:plot](2:T+1, cumsum(income .- mu), "r-",
label="cumulative unanticipated income", lw=2, alpha=0.7)
axes[2][:plot](1:T+1, assets, "b-", label="assets", lw=2, alpha=0.7)
axes[2][:plot](1:T, zeros(T), "k-")
axes[2][:legend](ncol=2, bbox_to_anchor=bbox, loc=3, mode="expand")
FurtherApplications
Application1: NonstationaryIncome Previouslywestudiedapermanentincomemodelthat
generatedconsumptionsmoothing
Oneunrealisticfeatureofthatmodelistheassumptionthatthemeanoftherandomincomepro-
cessdoesnotdependontheconsumer’sage
Amorerealisticincomeprofileisonethatrisesinearlyworkinglife,peakstowardsthemiddle
andmaybedeclinestowardendofworkinglife,andfallsmoreduringretirement
Inthissection,wewillmodelthisriseandfallasasymmetricinverted“U”usingapolynomialin
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
2.11. LQDYNAMICPROGRAMMINGPROBLEMS
229
age
Asbefore,theconsumerseekstominimize
E
(
1
å
t=0
b
t
(c
t
¯c)
2
+b
T
qa
2
T
)
(2.103)
subjecttoa
t+1
=(1+r)a
t
c
t
+y
t
t0
Forincomewenowtakey
t
=p(t)+sw
t+1
wherep(t):=m
0
+m
1
t+m
2
t
2
(Inthenextsectionweemploysometrickstoimplementamoresophisticatedmodel)
Thecoefficientsm
0
,m
1
,m
2
arechosensuchthatp(0)=0,p(T/2)=m,andp(T)=0
Youcanconfirmthatthespecificationm
0
=0,m
1
=Tm/(T/2)2,m
2
m/(T/2)satisfiesthese
constraints
ToputthisintoanLQsetting,considerthebudgetconstraint,whichbecomes
a
t+1
=(1+r)a
t
u
t
¯c+m
1
t+m
2
t
2
+sw
t+1
(2.104)
Thefactthata
t+1
isalinearfunctionof(a
t
,1,t,t
2)
suggeststakingthesefourvariablesasthestate
vectorx
t
Onceagoodchoiceofstateandcontrol(recallu
t
=c
t
¯c)hasbeenmade,theremainingspecifi-
cationsfallintoplacerelativelyeasily
Thus,forthedynamicsweset
x
t
:=
0
B
B
@
a
t
1
t
t
2
1
C
C
A
A:=
0
B
B
@
1+¯c m
1
m
2
0
1
0
0
0
1
1
0
0
1
2
1
1
C
C
A
B:=
0
B
B
@
1
0
0
0
1
C
C
A
C:=
0
B
B
@
s
0
0
0
1
C
C
A
(2.105)
Ifyouexpandtheexpressionx
t+1
=Ax
t
+Bu
t
+Cw
t+1
usingthisspecification,youwillfindthat
assetsfollow(2.104)asdesired,andthattheotherstatevariablesalsoupdateappropriately
Toimplementpreferencespecification(2.103)wetake
Q:=1, R:=
0
B
B
@
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
1
C
C
A
and R
f
:=
0
B
B
@
0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
1
C
C
A
(2.106)
The next t figure shows a simulation of consumption n and d assets computed using g the
compute_sequencemethodoflqcontrol.jlwithinitialassetssettozero
Onceagain,smoothconsumptionisadominantfeatureofthesamplepaths
Theassetpathexhibitsdynamicsconsistentwithstandardlifecycletheory
Exercise1givesthefullsetofparametersusedhereandasksyoutoreplicatethefigure
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
2.11. LQDYNAMICPROGRAMMINGPROBLEMS
230
T
HOMAS
S
ARGENTAND
J
OHN
S
TACHURSKI
April20,2016
Documents you may be interested
Documents you may be interested