def global_contrast_normalize(X, scale=1.0, subtract_mean=True, use_std=False, sqrt_bias=0.0, min_divisor=1e-08):
 assert (X.ndim == 2), 'X.ndim must be 2'
 scale = float(scale)
 assert (scale >= min_divisor)
 mean = X.mean(axis=1)
 if subtract_mean:
  X = (X - mean[:, numpy.newaxis])
 else:
  X = X.copy()
 if use_std:
  ddof = 1
  if (X.shape[1] == 1):
   ddof = 0
  normalizers = (numpy.sqrt((sqrt_bias + X.var(axis=1, ddof=ddof))) / scale)
 else:
  normalizers = (numpy.sqrt((sqrt_bias + (X ** 2).sum(axis=1))) / scale)
 normalizers[(normalizers < min_divisor)] = 1.0
 X /= normalizers[:, numpy.newaxis]
 return X

def global_contrast_normalize ( X , scale = 1.0 , subtract_mean = True , use_std = False , sqrt_bias = 0.0 , min_divisor = 1e-08 ) : assert ( X . ndim == 2 ) , 'X.ndim must be 2' scale = float ( scale ) assert ( scale >= min_divisor ) mean = X . mean ( axis = 1 ) if subtract_mean : X = ( X - mean [ : , numpy . newaxis ] ) else : X = X . copy ( ) if use_std : ddof = 1 if ( X . shape [ 1 ] == 1 ) : ddof = 0 normalizers = ( numpy . sqrt ( ( sqrt_bias + X . var ( axis = 1 , ddof = ddof ) ) ) / scale ) else : normalizers = ( numpy . sqrt ( ( sqrt_bias + ( X ** 2 ) . sum ( axis = 1 ) ) ) / scale ) normalizers [ ( normalizers < min_divisor ) ] = 1.0 X /= normalizers [ : , numpy . newaxis ] return X
global contrast normalizes by subtracting the mean across features and then normalizes by either the vector norm or the standard deviation .