def get_logit_endog(true_params, exog, noise_level):
 N = exog.shape[0]
 Xdotparams = sp.dot(exog, true_params)
 noise = (noise_level * sp.randn(*Xdotparams.shape))
 eXB = sp.column_stack((sp.ones(len(Xdotparams)), sp.exp(Xdotparams)))
 class_probabilities = (eXB / eXB.sum(1)[:, None])
 cdf = class_probabilities.cumsum(axis=1)
 endog = sp.zeros(N)
 for i in range(N):
  endog[i] = sp.searchsorted(cdf[i, :], sp.rand())
 return endog

def get_logit_endog ( true_params , exog , noise_level ) : N = exog . shape [ 0 ] Xdotparams = sp . dot ( exog , true_params ) noise = ( noise_level * sp . randn ( * Xdotparams . shape ) ) eXB = sp . column_stack ( ( sp . ones ( len ( Xdotparams ) ) , sp . exp ( Xdotparams ) ) ) class_probabilities = ( eXB / eXB . sum ( 1 ) [ : , None ] ) cdf = class_probabilities . cumsum ( axis = 1 ) endog = sp . zeros ( N ) for i in range ( N ) : endog [ i ] = sp . searchsorted ( cdf [ i , : ] , sp . rand ( ) ) return endog
gets an endogenous response that is consistent with the true_params .