Skip to content

Commit

Permalink
Non-binary incidence (#127)
Browse files Browse the repository at this point in the history
* update package version number as well

* Allow non-binary incidence (#123)

* Allow non-binary incidence

* style

* update tests to pass

* add some progress indication

* tidy up validation script, use histogram for a histogram

* fix render and some typos

Co-authored-by: bstabler <[email protected]>
  • Loading branch information
jamiecook and bstabler authored Oct 20, 2020
1 parent 5c3a163 commit 2c2536e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion populationsim/balancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def np_balancer(
yy + relaxed_constraint / float(importance))

# update HH weights
weights_final[incidence[c] > 0] *= gamma[c]
weights_final *= pow(gamma[c], incidence[c])

# clip weights to upper and lower bounds
weights_final = np.clip(weights_final, weights_lower_bound, weights_upper_bound)
Expand Down
2 changes: 1 addition & 1 deletion populationsim/simul_balancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def np_simul_balancer(
yy + (relaxed_constraint / float(importance)))

# update HH weights
sub_weights[z][incidence[c] > 0] *= gamma[z, c]
sub_weights[z] *= pow(gamma[z, c], incidence[c])

# clip weights to upper and lower bounds
sub_weights[z] = np.clip(sub_weights[z], weights_lower_bound, weights_upper_bound)
Expand Down
7 changes: 5 additions & 2 deletions populationsim/steps/sub_balancing.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,12 @@ def sub_balancing(settings, crosswalk, control_spec, incidence_table):
# only want ones for which there are (non-zero) controls
parent_ids = parent_controls_df.index.intersection(parent_ids)

for parent_id in parent_ids:
num_parent_ids = len(parent_ids)
for idx, parent_id in enumerate(parent_ids, start=1):

logger.info("balancing seed %s, %s %s" % (seed_id, parent_geography, parent_id))
log_msg = "balancing {}/{} seed {}, {} {}"
log_msg = log_msg.format(idx, num_parent_ids, seed_id, parent_geography, parent_id)
logger.info(log_msg)

initial_weights = weights_df[weights_df[parent_geography] == parent_id]
initial_weights = initial_weights.set_index(settings.get('household_id_col'))
Expand Down
4 changes: 2 additions & 2 deletions populationsim/tests/test_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def teardown_function(func):


TAZ_COUNT = 36
TAZ_100_HH_COUNT = 25
TAZ_100_HH_COUNT = 33
TAZ_100_HH_REPOP_COUNT = 26


Expand All @@ -51,7 +51,7 @@ def test_full_run1():
'meta_control_factoring',
'final_seed_balancing',
'integerize_final_seed_weights',
'sub_balancing.geography = TRACT',
'sub_balancing.geography=TRACT',
'sub_balancing.geography=TAZ',
'expand_households',
'summarize',
Expand Down
38 changes: 19 additions & 19 deletions scripts/validation.ipynb

Large diffs are not rendered by default.

0 comments on commit 2c2536e

Please sign in to comment.