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

Create new disutility params #170

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions soepy/pre_processing/model_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,16 @@ def group_parameters(model_params_dict_expanded):
dtype=float,
)

for key_ in list(model_params_dict_expanded["disutil_work"].keys()):
if "child" in key_:
model_params_dict_flat[key_] = model_params_dict_expanded["disutil_work"][
key_
]
for i in ["child_0_2_", "child_3_5_", "child_6_10_"]:
for j in ["f", "p"]:
model_params_dict_flat[i + j] = np.array(
[
model_params_dict_expanded["disutil_work"][i + j + "_educ_low"],
model_params_dict_expanded["disutil_work"][i + j + "_educ_middle"],
model_params_dict_expanded["disutil_work"][i + j + "_educ_high"],
],
dtype=float,
)

for i in ["no", "yes"]:
for j in ["f", "p"]:
Expand Down
32 changes: 23 additions & 9 deletions soepy/shared/shared_auxiliary.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ def calculate_log_wage_systematic(


@numba.guvectorize(
["f8[:],f8[:],f8[:],f8[:],f8[:],f8[:],f8,f8,f8,f8,f8,f8,i8[:], f8, f8[:], f8[:]"],
[
"f8[:],f8[:],f8[:],f8[:],f8[:],f8[:],f8[:],f8[:],f8[:],f8[:],f8[:],f8[:],i8[:], f8, f8[:], f8[:]"
],
"(num_unobs_types),(num_unobs_types), (num_edu_types),(num_edu_types),"
"(num_edu_types),(num_edu_types), (),(),(),(),(),(),(num_state_vars),"
"(num_edu_types),(num_edu_types), (num_edu_types),(num_edu_types),(num_edu_types),(num_edu_types),(num_edu_types),(num_edu_types),(num_state_vars),"
"(),(num_choices)->(num_choices)",
nopython=True,
target="cpu",
Expand Down Expand Up @@ -129,24 +131,36 @@ def calculate_non_consumption_utility(
non_consumption_utility_state[2] += no_kids_f[educ_level]
elif child_bin == 1:
non_consumption_utility_state[1] += (
yes_kids_f[educ_level] + yes_kids_p[educ_level] + child_0_2_f + child_0_2_p
yes_kids_f[educ_level]
+ yes_kids_p[educ_level]
+ child_0_2_f[educ_level]
+ child_0_2_p[educ_level]
)

non_consumption_utility_state[2] += yes_kids_f[educ_level] + child_0_2_f
non_consumption_utility_state[2] += (
yes_kids_f[educ_level] + child_0_2_f[educ_level]
)
elif child_bin == 2:
non_consumption_utility_state[1] += (
yes_kids_f[educ_level] + yes_kids_p[educ_level] + child_3_5_f + child_3_5_p
yes_kids_f[educ_level]
+ yes_kids_p[educ_level]
+ child_3_5_f[educ_level]
+ child_3_5_p[educ_level]
)
non_consumption_utility_state[2] += (
yes_kids_f[educ_level] + child_3_5_f[educ_level]
)
non_consumption_utility_state[2] += yes_kids_f[educ_level] + child_3_5_f

elif child_bin == 3:
non_consumption_utility_state[1] += (
yes_kids_f[educ_level]
+ yes_kids_p[educ_level]
+ child_6_10_f
+ child_6_10_p
+ child_6_10_f[educ_level]
+ child_6_10_p[educ_level]
)
non_consumption_utility_state[2] += (
yes_kids_f[educ_level] + child_6_10_f[educ_level]
)
non_consumption_utility_state[2] += yes_kids_f[educ_level] + child_6_10_f
else: # Mothers with kids older than 10 only get fixed disutility
non_consumption_utility_state[1] += (
yes_kids_f[educ_level] + yes_kids_p[educ_level]
Expand Down
28 changes: 20 additions & 8 deletions soepy/test/random_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,16 @@ def random_init(constr=None):
model_params_init_dict["yes_kids_f_educ_low"],
model_params_init_dict["yes_kids_f_educ_middle"],
model_params_init_dict["yes_kids_f_educ_high"],
model_params_init_dict["child_0_2_f"],
model_params_init_dict["child_3_5_f"],
model_params_init_dict["child_6_10_f"],
) = np.random.uniform(0.001, 0.2, 9).tolist()
model_params_init_dict["child_0_2_f_educ_high"],
model_params_init_dict["child_3_5_f_educ_high"],
model_params_init_dict["child_6_10_f_educ_high"],
model_params_init_dict["child_0_2_f_educ_middle"],
model_params_init_dict["child_3_5_f_educ_middle"],
model_params_init_dict["child_6_10_f_educ_middle"],
model_params_init_dict["child_0_2_f_educ_low"],
model_params_init_dict["child_3_5_f_educ_low"],
model_params_init_dict["child_6_10_f_educ_low"],
) = np.random.uniform(0.001, 0.2, 15).tolist()

(
model_params_init_dict["no_kids_p_educ_low"],
Expand All @@ -204,10 +210,16 @@ def random_init(constr=None):
model_params_init_dict["yes_kids_p_educ_low"],
model_params_init_dict["yes_kids_p_educ_middle"],
model_params_init_dict["yes_kids_p_educ_high"],
model_params_init_dict["child_0_2_p"],
model_params_init_dict["child_3_5_p"],
model_params_init_dict["child_6_10_p"],
) = np.random.uniform(-1.5, -0.001, 9).tolist()
model_params_init_dict["child_0_2_p_educ_high"],
model_params_init_dict["child_3_5_p_educ_high"],
model_params_init_dict["child_6_10_p_educ_high"],
model_params_init_dict["child_0_2_p_educ_middle"],
model_params_init_dict["child_3_5_p_educ_middle"],
model_params_init_dict["child_6_10_p_educ_middle"],
model_params_init_dict["child_0_2_p_educ_low"],
model_params_init_dict["child_3_5_p_educ_low"],
model_params_init_dict["child_6_10_p_educ_low"],
) = np.random.uniform(-1.5, -0.001, 15).tolist()

model_params_init_dict["delta"] = np.random.uniform(0.8, 0.99)
model_params_init_dict["mu"] = np.random.uniform(-0.7, -0.4)
Expand Down
Binary file modified soepy/test/resources/regression_vault.soepy.pkl
Binary file not shown.
19 changes: 12 additions & 7 deletions soepy/test/test_childless.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,21 @@ def input_data():
)

params_ind_list = [
("disutil_work", "yes_kids_f_educ_middle"),
("disutil_work", "yes_kids_p_educ_middle"),
("disutil_work", "yes_kids_p_educ_low"),
("disutil_work", "yes_kids_p_educ_high"),
("disutil_work", "child_0_2_f"),
("disutil_work", "child_3_5_f"),
("disutil_work", "yes_kids_f_educ_"),
("disutil_work", "yes_kids_p_educ_"),
("disutil_work", "child_0_2_f_educ_"),
("disutil_work", "child_3_5_f_educ_"),
("disutil_work", "child_6_10_f_educ_"),
("disutil_work", "child_0_2_p_educ_"),
("disutil_work", "child_3_5_p_educ_"),
("disutil_work", "child_6_10_p_educ_"),
]

for param_ind in params_ind_list:
model_params_df.loc[param_ind, "value"] *= factor
for educ in ["low", "middle", "high"]:
model_params_df.loc[
(param_ind[0], param_ind[1] + educ), "value"
] *= factor

model_spec = read_model_spec_init(model_spec_init_dict, model_params_df)

Expand Down