Skip to content

Commit

Permalink
fix numeric overflow
Browse files Browse the repository at this point in the history
fix non-convergence in tests
  • Loading branch information
Eh2406 committed May 4, 2018
1 parent eab97ea commit d84469d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions urbansim/urbanchoice/mnl.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def mnl_probs(data, beta, numalts):
raise Exception("Number of alternatives is zero")
utilities.reshape(numalts, utilities.size() // numalts)

# https://stats.stackexchange.com/questions/304758/softmax-overflow
if clamp:
utilities.mat -= utilities.mat.max(0)

exponentiated_utility = utilities.exp(inplace=True)
if clamp:
exponentiated_utility.inftoval(1e20)
Expand Down

0 comments on commit d84469d

Please sign in to comment.