#NEWLINE# def global_contrast_normalize( X , scale = 1.0 , subtract_mean = True , use_std = False , sqrt_bias = 0.0 , min_divisor = 1e-08 ) : #NEWLINE# #INDENT# '\n    Global contrast normalizes by (optionally) subtracting the mean\n    across features and then normalizes by either the vector norm\n    or the standard deviation (across features, for each example).\n\n    Parameters\n    ----------\n    X : ndarray, 2-dimensional\n        Design matrix with examples indexed on the first axis and         features indexed on the second.\n\n    scale : float, optional\n        Multiply features by this const.\n\n    subtract_mean : bool, optional\n        Remove the mean across features/pixels before normalizing.         Defaults to `True`.\n\n    use_std : bool, optional\n        Normalize by the per-example standard deviation across features         instead of the vector norm. Defaults to `False`.\n\n    sqrt_bias : float, optional\n        Fudge factor added inside the square root. Defaults to 0.\n\n    min_divisor : float, optional\n        If the divisor for an example is less than this value,         do not apply it. Defaults to `1e-8`.\n\n    Returns\n    -------\n    Xp : ndarray, 2-dimensional\n        The contrast-normalized features.\n\n    Notes\n    -----\n    `sqrt_bias` = 10 and `use_std = True` (and defaults for all other\n    parameters) corresponds to the preprocessing used in [1].\n\n    References\n    ----------\n    .. [1] A. Coates, H. Lee and A. Ng. "An Analysis of Single-Layer\n       Networks in Unsupervised Feature Learning". AISTATS 14, 2011.\n       http://www.stanford.edu/~acoates/papers/coatesleeng_aistats_2011.pdf\n    ' #NEWLINE# assert ( X . ndim == 2 ) , 'X.ndim must be 2' #NEWLINE# scale = float ( scale ) #NEWLINE# assert ( scale >= min_divisor ) #NEWLINE# mean = X . mean ( axis = 1 ) #NEWLINE# if subtract_mean : #NEWLINE# #INDENT# X = ( X - mean [ : , numpy . newaxis ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# X = X . copy ( ) #NEWLINE# #UNINDENT# if subtract_mean : #NEWLINE# #INDENT# ddof = 1 #NEWLINE# if ( X . shape [ 1 ] == 1 ) : #NEWLINE# #INDENT# ddof = 0 #NEWLINE# #UNINDENT# normalizers = ( numpy . sqrt ( ( sqrt_bias + X . var ( axis = 1 , ddof = ddof ) ) ) / scale ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# normalizers = ( numpy . sqrt ( ( sqrt_bias + ( X ** 2 ) . sum ( axis = 1 ) ) ) / scale ) #NEWLINE# #UNINDENT# normalizers [ ( normalizers < min_divisor ) ] = 1.0 #NEWLINE# X /= normalizers [ : , numpy . newaxis ] #NEWLINE# return X