def _multinomial_loss(w, X, Y, alpha, sample_weight):
 n_classes = Y.shape[1]
 n_features = X.shape[1]
 fit_intercept = (w.size == (n_classes * (n_features + 1)))
 w = w.reshape(n_classes, (-1))
 sample_weight = sample_weight[:, np.newaxis]
 if fit_intercept:
  intercept = w[:, (-1)]
  w = w[:, :(-1)]
 else:
  intercept = 0
 p = safe_sparse_dot(X, w.T)
 p += intercept
 p -= logsumexp(p, axis=1)[:, np.newaxis]
 loss = (- ((sample_weight * Y) * p).sum())
 loss += ((0.5 * alpha) * squared_norm(w))
 p = np.exp(p, p)
 return (loss, p, w)

def _multinomial_loss ( w , X , Y , alpha , sample_weight ) : n_classes = Y . shape [ 1 ] n_features = X . shape [ 1 ] fit_intercept = ( w . size == ( n_classes * ( n_features + 1 ) ) ) w = w . reshape ( n_classes , ( - 1 ) ) sample_weight = sample_weight [ : , np . newaxis ] if fit_intercept : intercept = w [ : , ( - 1 ) ] w = w [ : , : ( - 1 ) ] else : intercept = 0 p = safe_sparse_dot ( X , w . T ) p += intercept p -= logsumexp ( p , axis = 1 ) [ : , np . newaxis ] loss = ( - ( ( sample_weight * Y ) * p ) . sum ( ) ) loss += ( ( 0.5 * alpha ) * squared_norm ( w ) ) p = np . exp ( p , p ) return ( loss , p , w )
computes multinomial loss and class probabilities .