Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Apr 9, 2018
1 parent cd9a255 commit afaa635
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions urbansim/models/tests/test_dcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ def test_mnl_dcm_yaml(basic_dcm, choosers, alternatives):
'log_likelihoods': None,
'fit_parameters': None,
'normalize': False,
'l1': 0.0,
'l2': 0.0,
}

assert yaml.load(basic_dcm.to_yaml()) == expected_dict
Expand Down Expand Up @@ -515,6 +517,8 @@ def test_mnl_dcm_segmented_yaml(grouped_choosers, alternatives):
'log_likelihoods': None,
'fit_parameters': None,
'normalize': False,
'l1': 0.0,
'l2': 0.0,
},
'y': {
'name': 'y',
Expand All @@ -523,6 +527,8 @@ def test_mnl_dcm_segmented_yaml(grouped_choosers, alternatives):
'log_likelihoods': None,
'fit_parameters': None,
'normalize': False,
'l1': 0.0,
'l2': 0.0,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions urbansim/urbanchoice/mnl.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ def mnl_loglik(beta, data, chosen, numalts, weights=None, lcgrad=False,
gradarr = np.reshape(gradarr.get_mat(), (1, gradarr.size()))[0]

loglik -= l1 * np.abs(beta.get_mat()).sum()
gradarr -= l1 * np.sign(beta.get_mat())
gradarr -= l1 * np.sign(beta.get_mat())[0]

loglik -= l2 * np.square(beta.get_mat()).sum()
gradarr -= l1 * beta.get_mat()
gradarr -= l2 * beta.get_mat()[0]

logger.debug('finish: calculate MNL log-likelihood')
return -1 * loglik, -1 * gradarr
Expand Down

0 comments on commit afaa635

Please sign in to comment.