Explained variance, also known as R^2.
974316
def padded_variance_explained(predictions,
                              labels,
                              weights_fn=common_layers.weights_all):
  """"""
  predictions, labels = common_layers.pad_with_zeros(predictions, labels)
  targets = labels
  weights = weights_fn(targets)

  y_bar = tf.reduce_mean(weights * targets)
  tot_ss = tf.reduce_sum(weights * tf.pow(targets - y_bar, 2))
  res_ss = tf.reduce_sum(weights * tf.pow(targets - predictions, 2))
  r2 = 1. - res_ss / tot_ss
  return r2, tf.reduce_sum(weights)
117601
def mass_2d(self,R,Rs,rho0,r_trunc):

        

        x = R / Rs
        tau = r_trunc / Rs
        gx = self._g(x,tau)
        m_2d = 4 * rho0 * Rs * R ** 2 * gx / x ** 2 * np.pi
        return m_2d
385222
def variance(self):
        """"""
        _self = self._discard_value(None)
        if not _self.total():
            return 0.0
        mean = _self.mean()
        weighted_central_moment = sum(
            count * (value - mean)**2 for value, count in iteritems(_self)
        )
        return weighted_central_moment / float(_self.total())
1093719
def explained_variance(pred:Tensor, targ:Tensor)->Rank0Tensor:
    ""
    pred,targ = flatten_check(pred,targ)
    var_pct = torch.var(targ - pred) / torch.var(targ)
    return 1 - var_pct
991471
public synchronized double variance()
    {
        long n = 0;
        double mean = 0;
        double s = 0.0;

        for (double x : m_times.m_values)
        {
            n++;
            double delta = x - mean;
            mean += delta / n;
            s += delta * (x - mean);
        }

        return (s / n);
    }
1350567
public double variance(double m1, Object pt1, Object ptSqr1, double m2, Object pt2) {
		// compute the total mass
		double m0 = m1 + m2;
		// compute the new sum
		Object pt0 = newCopy(pt1);
		addScaled(pt0, m2, pt2);
		// compute the new sum of squares
		Object ptSqr0 = newCopy(ptSqr1);
		addScaledSqr(ptSqr0, m2, pt2);
		// compute the variance
		return variance(m0, pt0, ptSqr0);
	}
86089
def variance_K(K, verbose=False):
    """"""
    c = SP.sum((SP.eye(len(K)) - (1.0 / len(K)) * SP.ones(K.shape)) * SP.array(K))
    scalar = (len(K) - 1) / c
    return 1.0/scalar
918530
public static function variance($values, $sample = true)
    {
        $numberOfValues = count($values);
        $mean = self::mean($values);

        $squaredDifferences = [];
        foreach ($values as $value) {
            $squaredDifferences[] = self::squaredDifference($value, $mean);
        }
        $sumOfSquaredDifferences = self::sum($squaredDifferences);

        if ($sample) {
            $variance = $sumOfSquaredDifferences / ($numberOfValues - 1);
        } else {
            $variance = $sumOfSquaredDifferences / $numberOfValues;
        }

        return $variance;
    }
272013
public double variance(double m, Object pt, Object ptSqr) {
		Object x = newCopy(ptSqr);
//		// Var is E(X^2) - E(X)^2, but squaring pt1 introduces an extra factor which is the total mass, so:
		subtractScaledSqr(x, 1 / m, pt);
		return sum(x);
	}
738702
def sde(self):
        
        variance = float(self.variance.values)
        lengthscale = float(self.lengthscale)

        F  = np.array(((-1.0/lengthscale,),))
        L  = np.array(((1.0,),))
        Qc = np.array( ((2.0*variance/lengthscale,),) )
        H = np.array(((1.0,),))
        Pinf = np.array(((variance,),))
        P0 = Pinf.copy()

        dF = np.zeros((1,1,2));
        dQc = np.zeros((1,1,2));
        dPinf = np.zeros((1,1,2));

        dF[:,:,0] = 0.0
        dF[:,:,1] = 1.0/lengthscale**2

        dQc[:,:,0] = 2.0/lengthscale
        dQc[:,:,1] = -2.0*variance/lengthscale**2

        dPinf[:,:,0] = 1.0
        dPinf[:,:,1] = 0.0

        dP0 = dPinf.copy()

        return (F, L, Qc, H, Pinf, P0, dF, dQc, dPinf, dP0)
718824
function VarianceFunction(win) {
  var self = this, m, m2, d, n;
  self.name = "vars";
  self.type = "simple";
  self.init = function() { m = 0; m2 = 0; d = 0; n = 0; };
  self.accumulate = function(v) { n+=1; d = v - m; m = d/n + m; m2 = m2 + d*(v - m); };
  self.compensate = function(v) { n-=1; d = m - v; m = m + d/n; m2 = d*(v - m) + m2; };
  self.emit = function()  { return m2/(n-1); };
  self.make = function(win) { return new VarianceFunction(win); };
}
48227
def allan_variance(data, dt, tmax=10):
    
    allanvar = []
    nmax = len(data) if len(data) < tmax / dt else int(tmax / dt)
    for i in range(1, nmax+1):
        databis = data[len(data) % i:]
        y = databis.reshape(len(data)//i, i).mean(axis=1)
        allanvar.append(((y[1:] - y[:-1])**2).mean() / 2)
    return dt * np.arange(1, nmax+1), np.array(allanvar)
230973
public static double variance(double[] x, double mean) {
        if (x.length == 0) {
            return Double.NaN;
        }
        if (x.length == 1) {
            return 0.0;
        }
        double result = 0.0;
        for (double i : x) {
            result += (i - mean) * (i - mean);
        }
        result /= -1 + x.length;
        return result;
    }
372625
def flux_r(q_vars: List[fl.Var], i: int, j: int):
    """"""
    return fl.sqrt(flux_r2(q_vars, i, j))
1272384
public function variance(): float
    {
        $a = $this->a;
        $b = $this->b;

        return (($b - $a + 1)**2 - 1) / 12;
    }
377347
def get_R_corr2(x_avg, y_avg, x_segment, y_segment): #
    
    xd = x_segment - x_avg # detrend x_segment
    yd = y_segment - y_avg # detrend y_segment
    if sum(xd**2) * sum(yd**2) == 0: # prevent divide by zero error
        return float('nan')
    rcorr = old_div(sum((xd * yd))**2, (sum(xd**2) * sum(yd**2)))
    return rcorr
1067855
def variance(sample = false)
      a = numerify
      avg = a.average
      sum = a.inject(0) { |sum, value| sum + (value - avg) ** 2}
      (1 / (a.length.to_f - (sample ? 1 : 0)) * sum)
    end