Esempio n. 1
0
def test_regression_simulation(inputs):
    init_dict = random_init(inputs)

    # Draw parameter
    param_1 = np.random.normal(17.5, 2)
    param_2 = np.random.normal(21, 2)
    param_3 = np.random.normal(-2, 0.1)
    param_4 = np.random.normal(0.2, 0.1)
    params = np.array([param_1, param_2, param_3, param_4])

    disc_fac = init_dict["simulation"]["discount_factor"]
    probs = np.array(init_dict["simulation"]["known_trans"])
    num_states = 800

    trans_mat = create_transition_matrix(num_states, probs)

    costs = calc_obs_costs(num_states, cubic_costs, params, 0.00001)

    ev = calc_fixp(trans_mat, costs, disc_fac)[0]

    df = simulate(init_dict["simulation"], ev, costs, trans_mat)

    v_disc = discount_utility(df, disc_fac)

    assert_allclose(v_disc / ev[0], 1, rtol=1e-02)
Esempio n. 2
0
def test_trans_mat_rows_one():
    rand_dict = random_init()
    control = np.ones(rand_dict["estimation"]["states"])
    assert_array_almost_equal(
        create_transition_matrix(
            rand_dict["estimation"]["states"],
            np.array(rand_dict["simulation"]["known_trans"]),
        ).sum(axis=1),
        control,
    )
Esempio n. 3
0
def test_regression_simulation(inputs):
    init_dict = random_init(inputs)
    df, unobs, utilities, num_states = simulate(init_dict["simulation"])
    num_buses = init_dict["simulation"]["buses"]
    num_periods = init_dict["simulation"]["periods"]
    beta = init_dict["simulation"]["beta"]
    params = np.array(init_dict["simulation"]["params"])
    probs = np.array(init_dict["simulation"]["known probs"])
    v_disc_ = [0.0, 0.0]
    v_disc = discount_utility(
        v_disc_, num_buses, num_periods, num_periods, utilities, beta
    )
    trans_mat = create_transition_matrix(num_states, probs)
    costs = myopic_costs(num_states, lin_cost, params)
    v_calc = calc_fixp(num_states, trans_mat, costs, beta)
    un_ob_av = 0
    for bus in range(num_buses):
        un_ob_av += unobs[bus, 0, 0]
    un_ob_av = un_ob_av / num_buses
    assert_allclose(v_disc[1] / (v_calc[0] + un_ob_av), 1, rtol=1e-02)
Esempio n. 4
0
def inputs_sim(inputs):
    out = {}
    out["init_dict"] = init_dict = random_init(inputs)["simulation"]

    # Draw parameter
    param1 = np.random.normal(10.0, 2)
    param2 = np.random.normal(2.3, 0.5)
    params = np.array([param1, param2])

    disc_fac = init_dict["discount_factor"]
    probs = np.array(init_dict["known_trans"])
    num_states = 300

    out["trans_mat"] = trans_mat = create_transition_matrix(num_states, probs)
    out["costs"] = costs = calc_obs_costs(num_states, lin_cost, params, 0.001)
    out["ev"] = ev = calc_fixp(trans_mat, costs, disc_fac)[0]
    out["df"] = simulate(
        init_dict,
        ev,
        costs,
        trans_mat,
    )
    return out