spectral normalization
497121
def _spectral_norm(self):
        
        w = self.params.get('weight').data(self.ctx)
        w_mat = nd.reshape(w, [w.shape[0], -1])

        _u = self.u.data(self.ctx)
        _v = None

        for _ in range(POWER_ITERATION):
            _v = nd.L2Normalization(nd.dot(_u, w_mat))
            _u = nd.L2Normalization(nd.dot(_v, w_mat.T))

        sigma = nd.sum(nd.dot(_u, w_mat) * _v)
        if sigma == 0.:
            sigma = EPSILON

        with autograd.pause():
            self.u.set_data(_u)

        return w / sigma
1347053
def normalize_bboxes(bboxes, rows, cols):
    """"""
    return [normalize_bbox(bbox, rows, cols) for bbox in bboxes]
827195
def laplacian_pca(self, coordinates, num_dims=None, beta=0.5):
    ''''''
    X = np.atleast_2d(coordinates)
    L = self.laplacian(normed=True)
    kernel = X.dot(X.T)
    kernel /= eigsh(kernel, k=1, which='LM', return_eigenvectors=False)
    L /= eigsh(L, k=1, which='LM', return_eigenvectors=False)
    W = (1-beta)*(np.identity(kernel.shape[0]) - kernel) + beta*L
    if num_dims is None:
      vals, vecs = np.linalg.eigh(W)
    else:
      vals, vecs = eigh(W, eigvals=(0, num_dims-1), overwrite_a=True)
    return X.T.dot(vecs).dot(vecs.T).T
1146495
def normalizedGraylevelVariance(img):
    '''''''
    mean, stdev = cv2.meanStdDev(img)
    s = stdev[0]**2 / mean[0]
    return s[0]
659827
def _normalize_license(data):
    """"""
    license = data.get('license', None)
    if not license:
        # try to get license from classifiers
        license = _license_from_classifiers(data)
    if license:
        if license in SDPX_LICENSES.keys():
            data['license'] = SDPX_LICENSES[license]
        else:
            data['license'] = "%s (FIXME:No SPDX)" % (license)
    else:
        data['license'] = ""
138937
def normalize(v):
    ''''''
    if 0 == np.linalg.norm(v):
        return v
    return v / np.linalg.norm(v)
40600
def normalize_bbox(coords, ymax, scaler=2):
    
    return [
        coords[0] * scaler,
        ymax - (coords[3] * scaler),
        coords[2] * scaler,
        ymax - (coords[1] * scaler),
    ]
1184640
def normalize(xs):
    '''
    
    '''
    x_min, x_max = np.min(xs), np.max(xs)
    return (xs - x_min) / (x_max - x_min)
429986
def spectral_pars_from_catalog(cat):
    """"""

    spectrum_type = cat['SpectrumType']
    pars = get_function_defaults(cat['SpectrumType'])
    par_idxs = {k: i for i, k in
                enumerate(get_function_par_names(cat['SpectrumType']))}

    for k in pars:
        pars[k]['value'] = cat['param_values'][par_idxs[k]]

    if spectrum_type == 'PowerLaw':

        pars['Index']['value'] *= -1.0
        pars['Index']['scale'] = -1.0
        pars['Scale']['scale'] = 1.0
        pars['Index']['max'] = max(5.0, pars['Index']['value'] + 1.0)
        pars['Index']['min'] = min(0.0, pars['Index']['value'] - 1.0)
        pars['Prefactor'] = make_parameter_dict(pars['Prefactor'])
        pars['Scale'] = make_parameter_dict(pars['Scale'], True, False)
        pars['Index'] = make_parameter_dict(pars['Index'], False, False)

    elif spectrum_type == 'LogParabola':

        pars['norm'] = make_parameter_dict(pars['norm'], False, True)
        pars['Eb'] = make_parameter_dict(pars['Eb'], True, False)
        pars['alpha'] = make_parameter_dict(pars['alpha'], False, False)
        pars['beta'] = make_parameter_dict(pars['beta'], False, False)

    elif spectrum_type == 'PLSuperExpCutoff':

        pars['Index1']['value'] *= -1.0
        pars['Index1']['scale'] = -1.0
        pars['Index2']['scale'] = 1.0
        pars['Prefactor'] = make_parameter_dict(pars['Prefactor'])
        pars['Scale'] = make_parameter_dict(pars['Scale'], True, False)
        pars['Index1'] = make_parameter_dict(pars['Index1'], False, False)
        pars['Index2'] = make_parameter_dict(pars['Index2'], False, False)
        pars['Cutoff'] = make_parameter_dict(pars['Cutoff'], False, True)

    elif spectrum_type == 'PLSuperExpCutoff2':

        pars['Index1']['value'] *= -1.0
        pars['Index1']['scale'] = -1.0
        pars['Index2']['scale'] = 1.0
        pars['Prefactor'] = make_parameter_dict(pars['Prefactor'])
        pars['Scale'] = make_parameter_dict(pars['Scale'], True, False)
        pars['Index1'] = make_parameter_dict(pars['Index1'], False, False)
        pars['Index2'] = make_parameter_dict(pars['Index2'], False, False)
        pars['Expfactor'] = make_parameter_dict(pars['Expfactor'], False, True)
    else:
        raise Exception('Unsupported spectral type:' + spectrum_type)

    return pars
396902
def _embedding_kernel_pca(matrix, dimensions=3, affinity_matrix=None,
                          sigma=1):
    
    if affinity_matrix is None:
        aff = rbf(matrix, sigma)
    else:
        aff = affinity_matrix
    kpca = sklearn.decomposition.KernelPCA(kernel='precomputed',
                                           n_components=dimensions)
    return kpca.fit_transform(aff)
377086
def normalize( trainingset ):
    
    
    def encoder( dataset ):
        for instance in dataset:
            if np.any(stds == 0):
                nonzero_indexes = np.where(stds!=0)
                instance.features[nonzero_indexes] = instance.features[nonzero_indexes] / stds[nonzero_indexes]
            else:
                instance.features = instance.features / stds
        return dataset
    #end
    
    training_data = np.array( [instance.features for instance in trainingset ] )
    stds = training_data.std(axis=0)
    
    return encoder
719006
def normalize_vector(v):
    
    norm = np.linalg.norm(v)
    return v/norm if not norm == 0 else v
173227
function normalize (specs) {
  const arrayedSpecs = Array.isArray(specs) ? specs : [specs]
  const objectifiedSpecs = arrayedSpecs.map(normalizeSpec)
  return objectifiedSpecs
}
1307924
def batch_norm_relu(inputs, is_training, relu=True):
  """"""
  inputs = mtf.layers.batch_norm(
      inputs,
      is_training,
      BATCH_NORM_DECAY,
      epsilon=BATCH_NORM_EPSILON,
      init_zero=(not relu))
  if relu:
    inputs = mtf.relu(inputs)
  return inputs
213890
def l2_batch_normalize(x, epsilon=1e-12, scope=None):
  
  with tf.name_scope(scope, "l2_batch_normalize") as name_scope:
    x_shape = tf.shape(x)
    x = tf.contrib.layers.flatten(x)
    x /= (epsilon + reduce_max(tf.abs(x), 1, keepdims=True))
    square_sum = reduce_sum(tf.square(x), 1, keepdims=True)
    x_inv_norm = tf.rsqrt(np.sqrt(epsilon) + square_sum)
    x_norm = tf.multiply(x, x_inv_norm)
    return tf.reshape(x_norm, x_shape, name_scope)
26448
def normalize(v, axis=None, eps=1e-10):
  """"""
  return v / max(anorm(v, axis=axis, keepdims=True), eps)
976081
def _normalize_eigensystem(u, lv, rv):
    
    # first normalize the stationary distribution separately
    lv[:, 0] = lv[:, 0] / np.sum(lv[:, 0])

    for i in range(1, lv.shape[1]):
        # the remaining left eigenvectors to satisfy
        # <\phi_i, \phi_i>_{\mu^{-1}} = 1
        lv[:, i] = lv[:, i] / np.sqrt(np.dot(lv[:, i], lv[:, i] / lv[:, 0]))

    for i in range(rv.shape[1]):
        # the right eigenvectors to satisfy <\phi_i, \psi_j> = \delta_{ij}
        rv[:, i] = rv[:, i] / np.dot(lv[:, i], rv[:, i])

    return u, lv, rv