Calculate the scaled residual
<br> ||Ax-b||_oo/( ||A||_oo . ||x||_oo + ||b||_oo ), with
<br> ||x||_oo = max(||x[i]||)
965016
public static double calculateScaledResidual(DoubleMatrix2D A, DoubleMatrix2D X, DoubleMatrix2D B){
		double residual = -Double.MAX_VALUE;
		double niX = Algebra.DEFAULT.normInfinity(X);
		double niB = Algebra.DEFAULT.normInfinity(B);
		if(Double.compare(niX, 0.)==0 && Double.compare(niB, 0.)==0){
			return 0;
		}else{
			double num = Algebra.DEFAULT.normInfinity(Algebra.DEFAULT.mult(A, X).assign(B,	Functions.minus));
			double den = Algebra.DEFAULT.normInfinity(A) * niX + niB;
			residual =  num / den;
			//log.debug("scaled residual: " + residual);
			
			return residual;
		}
	}
1292066
def Max(a, axis, keep_dims):
    
    return np.amax(a, axis=axis if not isinstance(axis, np.ndarray) else tuple(axis),
                   keepdims=keep_dims),
426905
Scalar<?> calculateImpliedRiskAversion(final PrimitiveMatrix assetWeights, final PrimitiveMatrix assetReturns) {

        Scalar<?> retVal = myCovariances.multiply(assetWeights).solve(assetReturns).toScalar(0, 0);

        if (retVal.isSmall(PrimitiveMath.ONE)) {
            retVal = BigScalar.ONE;
        } else if (!retVal.isAbsolute()) {
            retVal = retVal.negate();
        }

        return retVal;
    }
1051358
def ax(mt, x, m=1):
    
    return (mt.Nx[x] / mt.Dx[x] - 1) + (float(m - 1) / float(m * 2))
910304
def compute_residuals(self):
        

        # The full primary residual is straightforward to compute from
        # the primary residuals for the baseline algorithm and for the
        # additional variables
        r0 = self.rsdl_r(self.AXnr, self.Y)
        r1 = self.AX1nr - self.Y1 - self.S
        r = np.sqrt(np.sum(r0**2) + np.sum(r1**2))

        # The full dual residual is more complicated to compute than the
        # full primary residual
        ATU = self.swapaxes(self.U) + sl.irfftn(
            np.conj(self.Zf) * sl.rfftn(self.U1, self.cri.Nv, self.cri.axisN),
            self.cri.Nv, self.cri.axisN)
        s = self.rho * np.linalg.norm(ATU)

        # The normalisation factor for the full primal residual is also not
        # straightforward
        nAX = np.sqrt(np.linalg.norm(self.AXnr)**2 +
                      np.linalg.norm(self.AX1nr)**2)
        nY = np.sqrt(np.linalg.norm(self.Y)**2 +
                     np.linalg.norm(self.Y1)**2)
        rn = max(nAX, nY, np.linalg.norm(self.S))

        # The normalisation factor for the full dual residual is
        # straightforward to compute
        sn = self.rho * np.sqrt(np.linalg.norm(self.U)**2 +
                                np.linalg.norm(self.U1)**2)

        # Final residual values and stopping tolerances depend on
        # whether standard or normalised residuals are specified via the
        # options object
        if self.opt['AutoRho', 'StdResiduals']:
            epri = np.sqrt(self.Nc)*self.opt['AbsStopTol'] + \
                rn*self.opt['RelStopTol']
            edua = np.sqrt(self.Nx)*self.opt['AbsStopTol'] + \
                sn*self.opt['RelStopTol']
        else:
            if rn == 0.0:
                rn = 1.0
            if sn == 0.0:
                sn = 1.0
            r /= rn
            s /= sn
            epri = np.sqrt(self.Nc)*self.opt['AbsStopTol']/rn + \
                self.opt['RelStopTol']
            edua = np.sqrt(self.Nx)*self.opt['AbsStopTol']/sn + \
                self.opt['RelStopTol']

        return r, s, epri, edua
594429
def poly2o_residual(params, data, mask):
    """"""
    bg = poly2o_model(params, shape=data.shape)
    res = (data - bg)[mask]
    return res.flatten()
838064
def rsdl_rn(self, AX, Y):
        

        # Avoid computing the norm of the value returned by cnst_c()
        # more than once
        if not hasattr(self, '_nrm_cnst_c'):
            self._nrm_cnst_c = np.linalg.norm(self.cnst_c())
        return max((np.linalg.norm(AX), np.linalg.norm(self.cnst_B(Y)),
                    self._nrm_cnst_c))
184722
def fun_residuals(params, xnor, ynor, w, bbox, k, ext):
    """"""

    spl = LSQUnivariateSpline(
        x=xnor,
        y=ynor,
        t=[item.value for item in params.values()],
        w=w,
        bbox=bbox,
        k=k,
        ext=ext,
        check_finite=False
    )
    return spl.get_residual()
593370
public static double calculateScaledResidual(double[][] A, double[] x, double[] b){
		DoubleMatrix2D AMatrix = DoubleFactory2D.dense.make(A); 
		DoubleMatrix1D xVector = DoubleFactory1D.dense.make(x);
		DoubleMatrix1D bVector = DoubleFactory1D.dense.make(b);
		return calculateScaledResidual(AMatrix, xVector, bVector);
	}
790415
def compute_residuals(self):
        """"""

        if self.opt['AutoRho', 'StdResiduals']:
            r = np.linalg.norm(self.rsdl_r(self.AXnr, self.Y))
            s = np.linalg.norm(self.rsdl_s(self.Yprev, self.Y))
            epri = np.sqrt(self.Nc) * self.opt['AbsStopTol'] + \
                self.rsdl_rn(self.AXnr, self.Y) * self.opt['RelStopTol']
            edua = np.sqrt(self.Nx) * self.opt['AbsStopTol'] + \
                self.rsdl_sn(self.U) * self.opt['RelStopTol']
        else:
            rn = self.rsdl_rn(self.AXnr, self.Y)
            if rn == 0.0:
                rn = 1.0
            sn = self.rsdl_sn(self.U)
            if sn == 0.0:
                sn = 1.0
            r = np.linalg.norm(self.rsdl_r(self.AXnr, self.Y)) / rn
            s = np.linalg.norm(self.rsdl_s(self.Yprev, self.Y)) / sn
            epri = np.sqrt(self.Nc) * self.opt['AbsStopTol'] / rn + \
                self.opt['RelStopTol']
            edua = np.sqrt(self.Nx) * self.opt['AbsStopTol'] / sn + \
                self.opt['RelStopTol']

        return r, s, epri, edua
352964
def r(w, Xs):
    '''
    '''
    n = len(Xs)
    P = projection_matrix(w)
    c = C(w, Xs)

    return np.sqrt(sum(np.dot(c - X, np.dot(P, c - X)) for X in Xs) / n)
1036291
def residuals(self):
        
        _ = self.rotated()
        _[:,-1] = 0
        _ = N.dot(_,self.axes)
        return self.arr - _
1101441
def klm(p, q):
    """"""
    p, q = flatten(p), flatten(q)
    return max(abs(p * np.nan_to_num(np.log(p / q))))
649843
def _finalize_iteration(self, yk, resnorm):
        '''
        '''
        self.xk = None
        # compute error norm if asked for
        if self.linear_system.exact_solution is not None:
            self.xk = self._get_xk(yk)
            self.errnorms.append(utils.norm(
                self.linear_system.exact_solution - self.xk,
                ip_B=self.linear_system.ip_B))

        rkn = None

        # compute explicit residual if asked for or if the updated residual
        # is below the tolerance or if this is the last iteration
        if self.explicit_residual or \
            resnorm/self.linear_system.MMlb_norm <= self.tol \
                or self.iter+1 == self.maxiter:
            # compute xk if not yet done
            if self.xk is None:
                self.xk = self._get_xk(yk)

            # compute residual norm
            _, _, rkn = self.linear_system.get_residual(self.xk,
                                                        compute_norm=True)

            # store relative residual norm
            self.resnorms.append(rkn/self.linear_system.MMlb_norm)

            # no convergence?
            if self.resnorms[-1] > self.tol:
                # no convergence in last iteration -> raise exception
                # (approximate solution can be obtained from exception)
                if self.iter+1 == self.maxiter:
                    self._finalize()
                    raise utils.ConvergenceError(
                        ('No convergence in last iteration '
                         '(maxiter: {0}, residual: {1}).')
                        .format(self.maxiter, self.resnorms[-1]), self)
                # updated residual was below but explicit is not: warn
                elif not self.explicit_residual \
                        and resnorm/self.linear_system.MMlb_norm <= self.tol:
                    warnings.warn(
                        'updated residual is below tolerance, explicit '
                        'residual is NOT! (upd={0} <= tol={1} < exp={2})'
                        .format(resnorm, self.tol, self.resnorms[-1]))
        else:
            # only store updated residual
            self.resnorms.append(resnorm/self.linear_system.MMlb_norm)

        return rkn
975286
def _call(self, x):
        """"""
        if self.operator is None:
            return self.vector.inner(x) + self.constant
        elif self.vector is None:
            return x.inner(self.operator(x)) + self.constant
        else:
            tmp = self.operator(x)
            tmp += self.vector
            return x.inner(tmp) + self.constant
780138
def _scalar_type_std_res(self, counts, total, colsum, rowsum):
        
        expected_counts = expected_freq(counts)
        residuals = counts - expected_counts
        variance = (
            np.outer(rowsum, colsum)
            * np.outer(total - rowsum, total - colsum)
            / total ** 3
        )
        return residuals / np.sqrt(variance)
781093
def _residual(self, x, in_filter, out_filter, stride,
                activate_before_residual=False):
    """"""
    if activate_before_residual:
      with tf.variable_scope('shared_activation'):
        x = self._layer_norm('init_bn', x)
        x = self._relu(x, self.hps.relu_leakiness)
        orig_x = x
    else:
      with tf.variable_scope('residual_only_activation'):
        orig_x = x
        x = self._layer_norm('init_bn', x)
        x = self._relu(x, self.hps.relu_leakiness)

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

    with tf.variable_scope('sub2'):
      x = self._layer_norm('bn2', x)
      x = self._relu(x, self.hps.relu_leakiness)
      x = self._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

    return x