Skip to content

testing SS#41

Open
JLian401 wants to merge 1 commit intojdebacker:masterfrom
JLian401:1212
Open

testing SS#41
JLian401 wants to merge 1 commit intojdebacker:masterfrom
JLian401:1212

Conversation

@JLian401
Copy link
Copy Markdown

This is an attempt to test SS.py.

print("w = ",w)
print("b_sp1 = ",b_sp1)
print("euler_errors = ",euler_errors)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test will run correctly. I believe it needs an assert statement that will raise an error if the assertion doesn't hold.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jtregde Thanks for the comment. Yes, I should have to make the assert statement inside the function. The problem is I don't know what I can compare at this point. I will continue to think of it.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JLian401 You could solve the SS in the case that you know the answer of (either by finding it analytically (could be hard!) or by using the solution from a version fo the code you trust - then then you could have an assert statement like:

expected_r = r_ss found in previous run/analytical solution 
test_r,w,b_sp1,euler_errors = SS.solve_ss(r_init,params=(beta, sigma, alpha,
                                                           A, delta, xi, omega_SS,
                                                           imm_rates_SS, S))
assert np.allclose(test_r, expected_r)

A = 1.0
delta = 0.1
xi = 0.1
S = 80
Copy link
Copy Markdown
Contributor

@saharnazb saharnazb Dec 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend thinking of 3 periods as we did in class so you can compare the results with SS in that

For 3 periods:
'SS interest rate is ', 1.0036834614021983

The only problem that I can think of is the exogenous labor in that model. I am trying to figure out a solution for that.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right - the answer will be different with exogenous labor.

Maybe you could have your scripts (e.g., SS.py) raise an assertion if the SS is not obtained before the maximum iterations are reached. In that way, this test will fail if the SS isn't found and pass if it is.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdebacker Yes. OK. Milton n I are working on that

Comment on lines +40 to +43
print("r = ",r)
print("w = ",w)
print("b_sp1 = ",b_sp1)
print("euler_errors = ",euler_errors)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no need to print

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. The print was only for checking whether SS works in terms of executability. I would like to use the expected_r in Table 8.2 of Chapter 8 and add the assert statement. But I am still struggling on other parts. For example, there is a valueError issue in SS to apply HH module.

@miltonash
Copy link
Copy Markdown
Contributor

Jet, here is the work @saharnazb and myself have been working on this morning for test_SS.py. I believe this will perform the iteration assertion that @jtregde and @jdebacker were alluding to. The only problem I encountered with the below script is that my Atom linter was giving me "E999 - SyntaxError: can't assign to operator" on line 24 for omega_path_S.T. Thoughts?

import numpy as np
import demographics
import SS


def test_SS():
    '''
    Test that the SS function solves before reaching ss_max_iter
    '''
    r_init = 0.1
    beta = 0.8
    sigma = 1.5
    alpha = 0.3
    A = 1.0
    delta = 0.1
    xi = 0.1
    S = 80
    E = 20
    T = int(round(4.0*S))
    min_year = 0
    max_year = 100
    curr_year = 0
    imm_rates_SS = demographics.get_imm_resid(S, min_yr, max_yr)
    (omega_path_S.T, g_n_SS, omega_SS, 1-mort_rates_S, mort_rates_S, g_n_path,
        imm_rates_mat.T, omega_S_preTP) = \
        demographics.get_pop_objs(E, S, T, min_yr, max_yr, curr_year)
    (ss_iter, r, w, b_sp1, euler_errors) = SS.solve_ss(
                                           r_init, params=(
                                                           beta, sigma, alpha,
                                                           A, delta, xi,
                                                           omega_SS,
                                                           imm_rates_SS, S
                                                           )
                                                       )
    # check that ss_iter is less than ss_max_iter
    assert (ss_iter < ss_max_iter)


test_SS

@jdebacker
Copy link
Copy Markdown
Owner

The numpyarray.T means to transpose the array. Just remove the .T so you are assigning the object form the tuple compute out of get_pop_objs() to a variable name.

@jdebacker
Copy link
Copy Markdown
Owner

The numpyarray.T means to transpose the array. Just remove the .T so you are assigning the object form the tuple compute out of get_pop_objs() to a variable name.

Also, you should get all demographic variables in execute.py and pass them from there. The are exogenous and do not change as you go through the iterations to solve the SS.

@jdebacker
Copy link
Copy Markdown
Owner

Also, you should get all demographic variables in execute.py and pass them from there. The are exogenous and do not change as you go through the iterations to solve the SS.

@saharnazb
Copy link
Copy Markdown
Contributor

saharnazb commented Dec 13, 2019

@jdebacker Yes, He solved the assignment problem with other operators included in there too. 1-mort_rate and both .T. Now it seems he cannot commit them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants