Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: LQMarkov with beta=1 #508

Open
oyamad opened this issue Sep 7, 2019 · 6 comments
Open

ValueError: LQMarkov with beta=1 #508

oyamad opened this issue Sep 7, 2019 · 6 comments
Labels

Comments

@oyamad
Copy link
Member

oyamad commented Sep 7, 2019

Π = 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.
@oyamad oyamad added the bug label Sep 7, 2019
@duncanhobbs
Copy link
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

bktaha added a commit to bktaha/QuantEcon.py that referenced this issue Jun 5, 2020
mmcky pushed a commit that referenced this issue Jun 12, 2020
* Fix: ValueError `LQMarkov` with beta>0.972 (#508)

* add line breaks to comply with pep8

* add docstring for max_iter parameter in LQMarkov

* move max_iter to kwarg of stationary_values, fix docstring, and indents for pep8

* edit line break for style consistency
@bktaha
Copy link
Contributor

bktaha commented Jun 12, 2020

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

@jstac
Copy link
Contributor

jstac commented Jun 12, 2020

Many thanks for your contributions @bktaha .

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

@oyamad
Copy link
Member Author

oyamad commented Jun 13, 2020

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

Refer to the discussion at #506.

@shizejin
Copy link
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

@bktaha
Copy link
Contributor

bktaha commented Jun 13, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants