Skip to content

ValueError: LQMarkov with beta=1 #508

Closed

Description

@oyamad
Π = np.array([[0.8, 0.2],
              [0.2, 0.8]])
Qs = np.array([[[0.9409]], [[0.870489]]])
Rs = np.array([[[1., 0., 1.],
                [0., 0., 0.],
                [1., 0., 1.]],
               [[1., 0., 1.],
                [0., 0., 0.],
                [1., 0., 1.]]])
Ns = np.array([[[-0.97, 0., -0.97]],
               [[-0.933, 0., -0.933]]])
As = np.array([[[0., 0., 0.],
                [0., 1., 0.],
                [0., 5., 0.8]],
               [[0., 0., 0.],
                [0., 1., 0.],
                [0., 5., 0.8]]])
B = np.array([[1., 0., 0.]]).T
Bs = [B, B]
C = np.array([[0., 0., 1.]]).T
Cs = [C, C]

lq_markov_mat1 = qe.LQMarkov(Π, Qs, Rs, As, Bs,
                             Cs=Cs, Ns=Ns, beta=1.)
lq_markov_mat1.stationary_values()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-15-022c46ef29a8> in <module>
----> 1 lq_markov_mat1.stationary_values()

/usr/local/lib/python3.7/site-packages/quantecon/lqcontrol.py in stationary_values(self)
    506 
    507         # == Solve for P(s) by iterating discrete riccati system== #
--> 508         Ps = solve_discrete_riccati_system(Π, As, Bs, Cs, Qs, Rs, Ns, beta)
    509 
    510         # == calculate F and d == #

/usr/local/lib/python3.7/site-packages/quantecon/matrix_eqn.py in solve_discrete_riccati_system(Π, As, Bs, Cs, Qs, Rs, Ns, beta, tolerance, max_iter)
    290 
    291         if iteration > max_iter:
--> 292             raise ValueError(fail_msg.format(max_iter))
    293 
    294         else:

ValueError: Convergence failed after 1000 iterations.

Activity

  1. duncanhobbs commented on Sep 24, 2019

    @duncanhobbs
    Contributor

    I tested this same example with different values of beta below. I still get a convergence error when beta is larger than 0.972.

    beta error after 1000 iterations:

    1 51.302186197106494

    0.99 0.0022754969468223862

    0.98 1.0506482794880867e-07

    0.975 7.403286872431636e-10

    0.974 2.764863893389702e-10

    0.973 1.0368239600211382e-10

    0.972 converged in 966 iterations

  2. bktaha commented on Jun 12, 2020

    @bktaha
    Contributor

    This should be addressed by PR #550
    I did not link the PR here, so this has remained open.

  3. jstac commented on Jun 12, 2020

    @jstac
    Contributor

    Many thanks for your contributions @bktaha .

    @shizejin , could you please confirm and close when ready?

  4. oyamad commented on Jun 13, 2020

    @oyamad
    MemberAuthor

    @shizejin Is the model well defined with beta >= 1? Shouldn't the input with beta >= 1 be rejected?

    Refer to the discussion at #506.

  5. shizejin commented on Jun 13, 2020

    @shizejin
    Member

    Hi @bktaha we are concerned about the nonexistence of stable solution when beta >= 1 and this shall not be solved by simply adding more iterations. You may check that the example @oyamad raised in this thread fails to converge after 10000 iterations (thanks to your work, we can now freely choose the number of iterations). But again, PR #550 shall have nothing to do with this issue.

    @jstac @oyamad

  6. bktaha commented on Jun 13, 2020

    @bktaha
    Contributor

    Oh, I assumed that non-convergence for beta >= 1 was expected behavior. In this snippet from the test file for lqcontrol;

    def test_raise_error(self):
    # test raising error for not converging
    lq_markov_mat = self.lq_markov_mat2
    self.assertRaises(ValueError, lq_markov_mat.stationary_values)

    the stationary_values method is expected to raise a ValueError for lq_markov_mat2 which is initialized with beta = 1.05.

  7. added a commit that references this issue on May 4, 2026
    f5cd14e
  8. oyamad commented on Jul 15, 2026

    @oyamad
    MemberAuthor

    Below it is the output of Claude Code Fable 5 (with minor edits):


    The appropriate restriction on beta is conditional on Cs — it is not a property of beta alone. Writing the value function as $V(x, s) = x' P(s) x + d(s)$, there are two separate issues.

    1. Constant terms. The $d(s)$ satisfy $d(i) = \beta \sum_j \Pi_{ij} \left[ \mathrm{tr}\big(P(j) C(i) C(i)'\big) + d(j) \right]$, i.e., $d(i)$ is the discounted sum of per-period noise costs, which cannot be driven to zero. Since $\Pi$ is a stochastic matrix, $I - \beta \Pi$ is invertible iff $\beta &lt; 1$, and with some $C(s) \neq 0$ no finite solution exists at $\beta = 1$: total cost is $+\infty$ under every policy, so the problem is ill posed. Hence $\beta \geq 1$ with $C(s) \neq 0$ for some $s$ should be rejected at construction, mirroring what LQ has done since #509 (cf. the discussion in #506).

    2. Deterministic case. With all $C(s) = 0$, $\beta = 1$ — and in principle even $\beta &gt; 1$ — is well posed whenever the scaled jump system $(\sqrt{\beta} A(s), \sqrt{\beta} B(s), \Pi)$ is mean-square stabilizable (Costa–Fragoso–Marques), so it should not be rejected unconditionally. But stationary_values must then set $d = 0$ directly: it currently solves the singular system $(I - \Pi) d = 0$ and raises LinAlgError even when the $P(s)$ iteration converges fine.

    Two consequences worth noting:

    • The non-convergence in the example above is nonexistence, not slow convergence: the constant state ($x_2 \equiv 1$) is an uncontrollable unit eigenvalue of every $A(s)$ that carries positive cost, so the scaled system is not mean-square stabilizable at $\beta = 1$ and no fixed point exists — no max_iter helps (confirmed with max_iter=1_000_000). By contrast, non-convergence for $\beta$ slightly below $1$ is mere slow convergence, where increasing max_iter does help.
    • Simply letting $\beta = 1$ through to the Riccati solver preserves no valid use case while the singular $d$-solve is in place: e.g. with $C(s) \neq 0$ and stable dynamics, the $P(s)$ iteration converges and the computation then dies at the $d$ step with an uninformative LinAlgError.

    Concretely, a proposed fix is: (i) in LQMarkov.__init__, raise ValueError if beta >= 1 and (Cs != 0).any(); (ii) in stationary_values, set ds = 0 when all Cs are zero instead of solving the linear system.

  9. oyamad commented on Aug 12, 2026

    @oyamad
    MemberAuthor

    This has not been fixed yet. Reopening...

  10. reopened this on Aug 12, 2026
  11. added a commit that references this issue on Aug 15, 2026
    bbedcda
  12. added a commit that references this issue on Sep 9, 2026
    e504433
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions