This will return the squared loss of the given
points
@param x the x coordinates to use
@param y the y coordinates to use
@param w_0 the first weight

@param w_1 the second weight
@return the squared loss of the given points
543705
public static double squaredLoss(double[] x, double[] y, double w_0, double w_1) {
        double sum = 0;
        for (int j = 0; j < x.length; j++) {
            sum += Math.pow((y[j] - (w_1 * x[j] + w_0)), 2);
        }
        return sum;
    }
1264889
def _calc(self, y, w):
        '''

        '''
        if self.discrete:
            self.lclass_ids = weights.lag_categorical(w, self.class_ids,
                                                      ties="tryself")
        else:
            ly = weights.lag_spatial(w, y)
            self.lclass_ids, self.lag_cutoffs, self.m = self._maybe_classify(
                ly, self.m, self.lag_cutoffs)
            self.lclasses = np.arange(self.m)

        T = np.zeros((self.m, self.k, self.k))
        n, t = y.shape
        for t1 in range(t - 1):
            t2 = t1 + 1
            for i in range(n):
                T[self.lclass_ids[i, t1], self.class_ids[i, t1],
                    self.class_ids[i, t2]] += 1

        P = np.zeros_like(T)
        for i, mat in enumerate(T):
            row_sum = mat.sum(axis=1)
            row_sum = row_sum + (row_sum == 0)
            p_i = np.matrix(np.diag(1. / row_sum) * np.matrix(mat))
            P[i] = p_i
        return T, P
967553
def calc_t(w1, w2, weight_fn=None):
    
    if not w1 or not w2:
        return 0

    s1 = analyze(w1, weight_fn)
    s2 = analyze(w2, weight_fn)
    delta_s = s2['avg'] - s1['avg']

    if delta_s == 0:
        return 0
    if s1['variance'] == 0 and s2['variance'] == 0:
        return float('inf')

    return delta_s / (((s1['variance'] / s1['n']) + (s2['variance'] / s2['n'])) ** 0.5)
989122
def G(w, Xs):
    ''''''
    n = len(Xs)
    P = projection_matrix(w)
    Ys = [np.dot(P, X) for X in Xs]
    A = calc_A(Ys)
    A_hat = calc_A_hat(A, skew_matrix(w))

    
    u = sum(np.dot(Y, Y) for Y in Ys) / n
    v = np.dot(A_hat, sum(np.dot(Y, Y) * Y for Y in Ys)) / np.trace(np.dot(A_hat, A))

    return sum((np.dot(Y, Y) - u - 2 * np.dot(Y, v)) ** 2 for Y in Ys)
633789
public void set(double x1, double y1, double z1, double w1) {
		double mag = (1.0/Math.sqrt( x1*x1 + y1*y1 + z1*z1 + w1*w1 ));
		this.x = x1*mag;
		this.y = y1*mag;
		this.z = z1*mag;
		this.w = w1*mag;
	}
930144
public static double Y(int n, double x) {
        double by, bym, byp, tox;

        if (n == 0) return Y0(x);
        if (n == 1) return Y(x);

        tox = 2.0 / x;
        by = Y(x);
        bym = Y0(x);
        for (int j = 1; j < n; j++) {
            byp = j * tox * by - bym;
            bym = by;
            by = byp;
        }
        return by;
    }
1244813
public static double rmsdMin(Point3d[] x, Point3d[] y) {

		if (x.length != y.length) {
			throw new IllegalArgumentException(
					"Point arrays are not of the same length.");
		}

		double sum = 0.0;
		for (int i = 0; i < x.length; i++) {
			double minDist = Double.MAX_VALUE;
			for (int j = 0; j < y.length; j++) {
				minDist = Math.min(minDist, x[i].distanceSquared(y[j]));
			}
			sum += minDist;
		}
		return Math.sqrt(sum / x.length);
	}
1216767
public float rSum(float[] y, float[] w) {
    float tmp1 = (float) 0.0, tmp2 = (float) 0.0;
    for (int i = 0; i < y.length; i++) {
      tmp1 += y[i] * w[i];
      tmp2 += w[i];
    }

    return correctTo01(tmp1 / tmp2);
  }
1243610
@Pure
	public double distance(double x, double y) {
		if (isValidPrimitive()) {
			final GeoLocationPoint p = getGeoPosition();
			return Point2D.getDistancePointPoint(p.getX(), p.getY(), x, y);
		}
		return Double.NaN;
	}
646702
@Pure
	public static GeodesicPosition EL2_WSG84(double x, double y) {
		final Point2d ntfLambdaPhi = NTFLambert_NTFLambdaPhi(x, y,
				LAMBERT_2E_N,
				LAMBERT_2E_C,
				LAMBERT_2E_XS,
				LAMBERT_2E_YS);
		return NTFLambdaPhi_WSG84(ntfLambdaPhi.getX(), ntfLambdaPhi.getY());
	}
1198977
@Pure
	public static GeodesicPosition L2_WSG84(double x, double y) {
		final Point2d ntfLambdaPhi = NTFLambert_NTFLambdaPhi(x, y,
				LAMBERT_2_N,
				LAMBERT_2_C,
				LAMBERT_2_XS,
				LAMBERT_2_YS);
		return NTFLambdaPhi_WSG84(ntfLambdaPhi.getX(), ntfLambdaPhi.getY());
	}
40717
def l1_loss(tensor, weight=1.0, scope=None):
  
  with tf.name_scope(scope, 'L1Loss', [tensor]):
    weight = tf.convert_to_tensor(weight,
                                  dtype=tensor.dtype.base_dtype,
                                  name='loss_weight')
    loss = tf.multiply(weight, tf.reduce_sum(tf.abs(tensor)), name='value')
    tf.add_to_collection(LOSSES_COLLECTION, loss)
    return loss
1185798
public double learn(double[] x) {
        if (x.length != n) {
            throw new IllegalArgumentException(String.format("Invalid input vector size: %d, expected: %d", x.length, n));
        }

        projection.ax(x, y);

        for (int j = 0; j < p; j++) {
            for (int i = 0; i < n; i++) {
                double delta = x[i];
                for (int l = 0; l <= j; l++) {
                    delta -= projection.get(l, i) * y[l];
                }
                projection.add(j, i, r * y[j] * delta);

                if (Double.isInfinite(projection.get(j, i))) {
                    throw new IllegalStateException("GHA lost convergence. Lower learning rate?");
                }
            }
        }

        projection.ax(x, y);
        projection.atx(y, wy);
        return Math.squaredDistance(x, wy);
    }
797176
def l2_regression_sq_loss(y, target, name=None):
  
  with tf.name_scope(name, 'l2_regression_sq', [y, target]) as scope:
    y = tf.convert_to_tensor(y, name='y')
    target = tf.convert_to_tensor(target, name='target')
    return reduce_batch_sum(tf.square(y - target), name=scope)
669290
def weight(w)
      OpenStruct.new({
      :x=> w[0] * p0.left + w[1] * p1.left + w[2] * p2.left + w[3] * p3.left,
      :y=> w[0] * p0.top  + w[1] * p1.top  + w[2] * p2.top  + w[3] * p3.top
      })
    end
1358952
static public double xy(double[] x, double[] y) {
    double result = 0.0;
    for (int i = 0; i < x.length; i++) {
      result += (x[i] * y[i]);
    }

    return (result);
  }
45005
@Pure
	public static Point2d L2_L4(double x, double y) {
		final Point2d ntfLambdaPhi = NTFLambert_NTFLambdaPhi(x, y,
				LAMBERT_2_N,
				LAMBERT_2_C,
				LAMBERT_2_XS,
				LAMBERT_2_YS);
		return NTFLambdaPhi_NTFLambert(
				ntfLambdaPhi.getX(), ntfLambdaPhi.getY(),
				LAMBERT_4_N,
				LAMBERT_4_C,
				LAMBERT_4_XS,
				LAMBERT_4_YS);
	}