Calculate low-rank component of the cost

        This method returns the nuclear norm error of the deconvolved data in
        matrix form

        Returns
        -------
        float low-rank cost component
549109
def _cost_method(self, *args, **kwargs):
        

        cost_val = self.thresh * nuclear_norm(cube2matrix(args[0]))

        if 'verbose' in kwargs and kwargs['verbose']:
            print(' - NUCLEAR NORM (X):', cost_val)

        return cost_val
108202
def obfn_dfd(self):
        
        """

        Ef = sl.inner(self.Zf, self.obfn_fvarf(), axis=self.cri.axisM) \
          - self.Sf
        return (np.linalg.norm(self.W * sl.irfftn(Ef, self.cri.Nv,
                                                  self.cri.axisN))**2) / 2.0
411808
def obfn_dfd(self):
        
        """

        return 0.5*np.linalg.norm((self.D.dot(self.obfn_fvar()) - self.S))**2
1131832
def TP0(dv, u):
    ''''''
    return np.linalg.norm(np.array(dv)) + np.linalg.norm(np.array(u))
93237
def batchnorm_2d(nf:int, norm_type:NormType=NormType.Batch):
    ""
    bn = nn.BatchNorm2d(nf)
    with torch.no_grad():
        bn.bias.fill_(1e-3)
        bn.weight.fill_(0. if norm_type==NormType.BatchZero else 1.)
    return bn
566277
def get_pvalue(value, ci):
    
    from scipy.stats import norm
    se = (ci[1] - ci[0]) / (2.0 * 1.96)
    z = value / se
    pvalue = -2 * norm.cdf(-np.abs(z))
    return pvalue
914863
def obfn_cns(self):
        
        """

        return np.linalg.norm((self.Pcn(self.X) - self.X))
347171
def _get_noise(self, residuals: np.ndarray) -> float:
        
        return np.mean(np.abs(residuals))
837579
def get_explicit_resnorms(self, indices=None):
        ''''''
        res = self.get_explicit_residual(indices)

        # apply preconditioner
        linear_system = self._deflated_solver.linear_system
        Mres = linear_system.M * res

        # compute norms
        resnorms = numpy.zeros(res.shape[1])
        for i in range(resnorms.shape[0]):
            resnorms[i] = utils.norm(res[:, [i]], Mres[:, [i]],
                                     ip_B=linear_system.ip_B)
        return resnorms
86371
def _create_batch_norm_variables(self, dtype):
    """"""
    # The paper recommends a value of 0.1 for good gradient flow through the
    # tanh nonlinearity (although doesn't say whether this is for all gammas,
    # or just some).
    gamma_initializer = tf.constant_initializer(0.1)

    if self._use_batch_norm_h:
      self._gamma_h = tf.get_variable(
          self.GAMMA_H,
          shape=[4 * self._hidden_size],
          dtype=dtype,
          initializer=self._initializers.get(self.GAMMA_H, gamma_initializer),
          partitioner=self._partitioners.get(self.GAMMA_H),
          regularizer=self._regularizers.get(self.GAMMA_H))
    if self._use_batch_norm_x:
      self._gamma_x = tf.get_variable(
          self.GAMMA_X,
          shape=[4 * self._hidden_size],
          dtype=dtype,
          initializer=self._initializers.get(self.GAMMA_X, gamma_initializer),
          partitioner=self._partitioners.get(self.GAMMA_X),
          regularizer=self._regularizers.get(self.GAMMA_X))
    if self._use_batch_norm_c:
      self._gamma_c = tf.get_variable(
          self.GAMMA_C,
          shape=[self._hidden_size],
          dtype=dtype,
          initializer=self._initializers.get(self.GAMMA_C, gamma_initializer),
          partitioner=self._partitioners.get(self.GAMMA_C),
          regularizer=self._regularizers.get(self.GAMMA_C))
      self._beta_c = tf.get_variable(
          self.BETA_C,
          shape=[self._hidden_size],
          dtype=dtype,
          initializer=self._initializers.get(self.BETA_C),
          partitioner=self._partitioners.get(self.BETA_C),
          regularizer=self._regularizers.get(self.BETA_C))
672993
def batch_norm(self,
                   input_layer=None,
                   decay=0.999,
                   scale=False,
                   epsilon=0.001):
        """"""
        if input_layer is None:
            input_layer = self.top_layer
        else:
            self.top_size = None
        name = "batchnorm" + str(self.counts["batchnorm"])
        self.counts["batchnorm"] += 1

        with tf.variable_scope(name) as scope:
            if self.use_tf_layers:
                bn = tf.contrib.layers.batch_norm(
                    input_layer,
                    decay=decay,
                    scale=scale,
                    epsilon=epsilon,
                    is_training=self.phase_train,
                    fused=True,
                    data_format=self.data_format,
                    scope=scope)
            else:
                bn = self._batch_norm_without_layers(input_layer, decay, scale,
                                                     epsilon)
        self.top_layer = bn
        self.top_size = bn.shape[
            3] if self.data_format == "NHWC" else bn.shape[1]
        self.top_size = int(self.top_size)
        return bn
98839
def obfn_reg(self):
        

        rl1 = np.linalg.norm((self.wl1 * self.obfn_gvar()).ravel(), 1)
        rl2 = 0.5*np.linalg.norm(self.obfn_gvar())**2
        return (self.lmbda*rl1 + self.mu*rl2, rl1, rl2)
517990
def _cost_method(self, *args, **kwargs):
        

        cost_val = np.sum(np.abs(self.weights * self._linear.op(args[0])))

        if 'verbose' in kwargs and kwargs['verbose']:
            print(' - L1 NORM (X):', cost_val)

        return cost_val
503612
def _cost_method(self, *args, **kwargs):
        

        cost_val = 0.5 * np.linalg.norm(self.obs_data - self.op(args[0])) ** 2

        if 'verbose' in kwargs and kwargs['verbose']:
            print(' - DATA FIDELITY (X):', cost_val)

        return cost_val
1237628
def obfn_reg(self):
        
        """
        l1 = np.sum(mp_wl1*np.abs(self.obfn_gvar()))
        return (self.lmbda*l1, l1)
910003
def _residual(x, in_filter, out_filter, stride,
              activate_before_residual=False):
  """"""
  if activate_before_residual:
    with tf.variable_scope('shared_activation'):
      x = _batch_norm('init_bn', x)
      x = _relu(x, 0.1)
      orig_x = x
  else:
    with tf.variable_scope('residual_only_activation'):
      orig_x = x
      x = _batch_norm('init_bn', x)
      x = _relu(x, 0.1)

  with tf.variable_scope('sub1'):
    x = _conv('conv1', x, 3, in_filter, out_filter, stride)

  with tf.variable_scope('sub2'):
    x = _batch_norm('bn2', x)
    x = _relu(x, 0.1)
    x = _conv('conv2', x, 3, out_filter, out_filter, [1, 1, 1, 1])

  with tf.variable_scope('sub_add'):
    if in_filter != out_filter:
      orig_x = tf.nn.avg_pool(orig_x, stride, stride, 'VALID')
      orig_x = tf.pad(
          orig_x, [[0, 0], [0, 0],
                   [0, 0], [(out_filter - in_filter) // 2,
                            (out_filter - in_filter) // 2]])
    x += orig_x

  tf.logging.debug('image after unit %s', x.get_shape())
  return x
1183411
def _compute(self, arrays, dates, assets, mask):
        
        return masked_rankdata_2d(
            arrays[0],
            mask,
            self.inputs[0].missing_value,
            self._method,
            self._ascending,
        )