Skip to content

Commit

Permalink
support cuda in fix for numeric overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed May 4, 2018
1 parent d84469d commit 9794d9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions urbansim/urbanchoice/mnl.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ def mnl_probs(data, beta, numalts):
utilities.reshape(numalts, utilities.size() // numalts)

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

exponentiated_utility = utilities.exp(inplace=True)
if clamp:
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 9794d9e

Please sign in to comment.