#NEWLINE# def mnl_probs( data , beta , numalts ) : #NEWLINE# #INDENT# logging . debug ( 'start: calculate MNL probabilities' ) #NEWLINE# clamp = ( data . typ == 'numpy' ) #NEWLINE# utilities = beta . multiply ( data ) #NEWLINE# if ( numalts == 0 ) : #NEWLINE# #INDENT# raise Exception ( 'Number of alternatives is zero' ) #NEWLINE# #UNINDENT# utilities . reshape ( numalts , ( utilities . size ( ) / numalts ) ) #NEWLINE# exponentiated_utility = utilities . exp ( inplace = True ) #NEWLINE# if clamp : #NEWLINE# #INDENT# exponentiated_utility . inftoval ( 1e+20 ) #NEWLINE# #UNINDENT# if data : #NEWLINE# #INDENT# exponentiated_utility . clamptomin ( 1e-300 ) #NEWLINE# #UNINDENT# sum_exponentiated_utility = exponentiated_utility . sum ( axis = 0 ) #NEWLINE# probs = exponentiated_utility . divide_by_row ( sum_exponentiated_utility , inplace = True ) #NEWLINE# if clamp : #NEWLINE# #INDENT# probs . nantoval ( 1e-300 ) #NEWLINE# #UNINDENT# if clamp : #NEWLINE# #INDENT# probs . clamptomin ( 1e-300 ) #NEWLINE# #UNINDENT# logging . debug ( 'finish: calculate MNL probabilities' ) #NEWLINE# return probs