Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into normalize-data
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed May 24, 2018
2 parents eb4ed01 + 79f815a commit d832f16
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions urbansim/urbanchoice/mnl.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ 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
utilities = utilities.subtract(utilities.max(0))

exponentiated_utility = utilities.exp(inplace=True)
if clamp:
exponentiated_utility.inftoval(1e20)
Expand Down Expand Up @@ -265,6 +268,10 @@ def mnl_estimate(data, chosen, numalts, GPU=False, coeffrange=(-3, 3),
approx_grad=False,
bounds=bounds
)

if bfgs_result[2]['warnflag'] > 0:
logger.warn("mnl did not converge correctly: %s", bfgs_result)

beta = bfgs_result[0]
stderr = mnl_loglik(
beta, data, chosen, numalts, weights, stderr=1, lcgrad=lcgrad)
Expand Down
6 changes: 6 additions & 0 deletions urbansim/urbanchoice/pmat.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ def cumsum(self, axis):
# elif self.typ == 'cuda':
# return PMAT(misc.cumsum(self.mat,axis=axis))

def max(self, axis):
if self.typ == 'numpy':
return PMAT(np.max(self.mat, axis=axis))
elif self.typ == 'cuda':
return PMAT(self.mat.max(axis=axis))

def argmax(self, axis):
if self.typ == 'numpy':
return PMAT(np.argmax(self.mat, axis=axis))
Expand Down

0 comments on commit d832f16

Please sign in to comment.