From 334e1a37da04a6512be446a94334800c65b674fa Mon Sep 17 00:00:00 2001 From: Daisuke Oyama Date: Mon, 23 Oct 2017 12:04:33 +0900 Subject: [PATCH] FIX: Replace `np.isfinite(cn)` with `cn * EPS < 1` --- quantecon/matrix_eqn.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/quantecon/matrix_eqn.py b/quantecon/matrix_eqn.py index b546ab820..01dceaab5 100644 --- a/quantecon/matrix_eqn.py +++ b/quantecon/matrix_eqn.py @@ -18,6 +18,9 @@ from scipy.linalg import solve_discrete_lyapunov as sp_solve_discrete_lyapunov +EPS = np.finfo(float).eps + + def solve_discrete_lyapunov(A, B, max_it=50, method="doubling"): r""" Computes the solution to the discrete lyapunov equation @@ -163,7 +166,7 @@ def solve_discrete_riccati(A, B, Q, R, N=None, tolerance=1e-10, max_iter=500): for gamma in candidates: Z = R + gamma * BB cn = np.linalg.cond(Z) - if np.isfinite(cn): + if cn * EPS < 1: Q_tilde = - Q + dot(N.T, solve(Z, N + gamma * BTA)) + gamma * I G0 = dot(B, solve(Z, B.T)) A0 = dot(I - gamma * G0, A) - dot(B, solve(Z, N))