diff --git a/urbansim/urbanchoice/mnl.py b/urbansim/urbanchoice/mnl.py index 41e06385..f3b2b30a 100644 --- a/urbansim/urbanchoice/mnl.py +++ b/urbansim/urbanchoice/mnl.py @@ -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)