Skip to content

Commit

Permalink
FIX: Remove 0.0 from candidates in solve_discrete_riccati (#185)
Browse files Browse the repository at this point in the history
* FIX: Remove 0.0 from `candidates` in `solve_discrete_riccati`

QuantEcon/QuantEcon.py#364

* FIX: Replace `isfinite(cn)` with `cn * eps() < 1` in solve_discrete_riccati

QuantEcon/QuantEcon.py#361
  • Loading branch information
oyamad authored and sglyon committed Oct 25, 2017
1 parent 6310172 commit 8d7883a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/matrix_eqn.jl
Expand Up @@ -115,14 +115,14 @@ function solve_discrete_riccati(A::ScalarOrArray, B::ScalarOrArray,
I = eye(k)

current_min = Inf
candidates = [0.0, 0.01, 0.1, 0.25, 0.5, 1.0, 2.0, 10.0, 100.0, 10e5]
candidates = [0.01, 0.1, 0.25, 0.5, 1.0, 2.0, 10.0, 100.0, 10e5]
BB = B' * B
BTA = B' * A

for gamma in candidates
Z = getZ(R, gamma, BB)
cn = cond(Z)
if isfinite(cn)
if cn * eps() < 1
Q_tilde = -Q + N' * (Z \ (N + gamma .* BTA)) + gamma .* I
G0 = B * (Z \ B')
A0 = (I - gamma .* G0) * A - B * (Z \ N)
Expand Down
6 changes: 3 additions & 3 deletions test/test_matrix_eqn.jl
@@ -1,6 +1,6 @@
@testset "Testing matrix_eqn.jl" begin
rough_kwargs = Dict(:atol => 1e-7, :rtol => 1e-7)

@testset "simple test where X is all zero" begin
A = eye(4) .* .95
B = zeros(4, 4)
Expand Down Expand Up @@ -38,14 +38,14 @@
@testset "testing ricatti golden_num_float" begin
val = solve_discrete_riccati(1.0, 1.0, 1.0, 1.0)
gold_ratio = (1 + sqrt(5)) / 2.
@test val[1] == (gold_ratio)
@test isapprox(val[1], gold_ratio; rough_kwargs...)
end

@testset "testing ricatti golden_num_2d" begin
A, B, R, Q = eye(2), eye(2), eye(2), eye(2)
gold_diag = eye(2) .* (1 + sqrt(5)) ./ 2.
val = solve_discrete_riccati(A, B, Q, R)
@test val == (gold_diag)
@test isapprox(val, gold_diag; rough_kwargs...)
end

@testset "test tjm 1" begin
Expand Down

0 comments on commit 8d7883a

Please sign in to comment.