Skip to content

Commit

Permalink
Merge pull request #52 from synthicity/sep-interaction-draw
Browse files Browse the repository at this point in the history
Draw samples individually for choosers
  • Loading branch information
fscottfoti committed May 4, 2015
2 parents f44f965 + 3f0ebed commit fe0e29d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions activitysim/mnl.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ def interaction_dataset(choosers, alternatives, sample_size=None):
alts_idx = np.arange(numalts)

if sample_size < numalts:
sample = np.random.choice(
alts_idx, sample_size * numchoosers, replace=True)
sample = np.concatenate(tuple(
np.random.choice(alts_idx, sample_size, replace=False)
for _ in range(numchoosers)))
else:
sample = np.tile(alts_idx, numchoosers)

Expand Down
4 changes: 2 additions & 2 deletions activitysim/tests/test_mnl.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def test_interaction_dataset_sampled(
interaction_choosers, interaction_alts, random_seed):
expected = pd.DataFrame({
'attr': ['a'] * 2 + ['b'] * 2 + ['c'] * 2 + ['b'] * 2,
'prop': [10, 40, 20, 10, 40, 40, 40, 40],
'prop': [30, 40, 10, 30, 40, 10, 20, 10],
'chooser_idx': ['w'] * 2 + ['x'] * 2 + ['y'] * 2 + ['z'] * 2},
index=[1, 4, 2, 1, 4, 4, 4, 4])
index=[3, 4, 1, 3, 4, 1, 2, 1])

interacted = mnl.interaction_dataset(
interaction_choosers, interaction_alts, sample_size=2)
Expand Down

0 comments on commit fe0e29d

Please sign in to comment.