Fraction of variance explained.
510126
def var_explained(y_true, y_pred):
    
    var_resid = K.var(y_true - y_pred)
    var_y_true = K.var(y_true)
    return 1 - var_resid / var_y_true
1271477
public static double variance(FlatDataCollection flatDataCollection, boolean isSample) {
        /* Uses the formal Variance = E(X^2) - mean^2 */
        int n = 0;
        double mean = 0.0;
        double squaredMean = 0.0;
        Iterator<Double> it = flatDataCollection.iteratorDouble();
        while(it.hasNext()) {
            Double v = it.next();
            if(v != null) {
                ++n;
                mean+=v;
                squaredMean+=v*v;
            }
        }

        if(n<=1) {
            throw new IllegalArgumentException("The provided collection must have more than 1 elements.");
        }
        
        mean/=n;
        squaredMean/=n;
        
        double variance = squaredMean - mean*mean;
        
        /* Unbiased for sample */
        if(isSample) {
            variance*=n/(n-1.0);
        }
        
        return variance;
    }
334982
function resolveFraction(frac) {
  frac = `${frac}`;
  if (Patterns.Percentage.test(frac)) {
    return parseFloat(frac) / 100;
  } else if (Patterns.Number.test(frac)) {
    return parseFloat(frac);
  } else
    throw new Error('Unknown fraction format: ', inp);
}
1184571
def sde(self): 
         
        
        variance = float(self.variance.values)
        lengthscale = float(self.lengthscale.values)

        lamda = np.sqrt(5.0)/lengthscale
        kappa = 5.0/3.0*variance/lengthscale**2        
        
        F = np.array(((0, 1,0), (0, 0, 1), (-lamda**3, -3.0*lamda**2, -3*lamda)))
        L = np.array(((0,),(0,),(1,)))
        Qc = np.array((((variance*400.0*np.sqrt(5.0)/3.0/lengthscale**5),),))
        H = np.array(((1,0,0),))        
        
        Pinf = np.array(((variance,0,-kappa), (0, kappa, 0), (-kappa, 0, 25.0*variance/lengthscale**4)))
        P0 = Pinf.copy()
        # Allocate space for the derivatives         
        dF = np.empty((3,3,2))        
        dQc = np.empty((1,1,2))        
        dPinf = np.empty((3,3,2))
        
         # The partial derivatives 
        dFvariance = np.zeros((3,3))
        dFlengthscale = np.array(((0,0,0),(0,0,0),(15.0*np.sqrt(5.0)/lengthscale**4, 
                                   30.0/lengthscale**3, 3*np.sqrt(5.0)/lengthscale**2)))
        dQcvariance = np.array((((400*np.sqrt(5)/3/lengthscale**5,),)))
        dQclengthscale = np.array((((-variance*2000*np.sqrt(5)/3/lengthscale**6,),)))        
        
        dPinf_variance = Pinf/variance
        kappa2 = -2.0*kappa/lengthscale
        dPinf_lengthscale = np.array(((0,0,-kappa2),(0,kappa2,0),(-kappa2, 
                                    0,-100*variance/lengthscale**5)))        
        # Combine the derivatives 
        dF[:,:,0] = dFvariance
        dF[:,:,1] = dFlengthscale        
        dQc[:,:,0] = dQcvariance         
        dQc[:,:,1] = dQclengthscale        
        dPinf[:,:,0] = dPinf_variance
        dPinf[:,:,1] = dPinf_lengthscale
        dP0 = dPinf.copy()
        
        return (F, L, Qc, H, Pinf, P0, dF, dQc, dPinf, dP0)
18825
def Kdiag(self, X, target):
        """"""
        self._K_diag_computations(X)
        target+= self.variance*self._K_diag_dvar
521183
def variance
      μ = mean
      reduce(0) { |m, i| m + (i - μ).square } / (length - 1)
    end
222330
def variance(self):
        '''
        
        '''
        alpha = self.__success + self.__default_alpha
        beta = self.__failure + self.__default_beta

        try:
            variance = alpha * beta / ((alpha + beta) ** 2) * (alpha + beta + 1)
        except ZeroDivisionError:
            variance = 0.0
        return variance
25822
private static Stats calcStats(List<Double> nums) {
    double sum = 0.0, mean = 0.0, variance = 0.0, stdDev = 0.0;
    for (Double d : nums) {
      sum += d.doubleValue();
    }
    if (nums.size() > 0) {
      mean = sum / nums.size();
    }

    sum = 0.0;
    for (Double d : nums) {
      sum += (d.doubleValue() - mean) * (d.doubleValue() - mean);
    }
    if (nums.size() > 0) {
      variance = sum / nums.size();
    }

    stdDev = Math.sqrt(variance);
    return new Stats(mean, variance, stdDev);
  }
909227
function( c, variance ){
            variance = typeof variance === 'number' ? variance : 0;
            var range = new ColorRange();
            range.name = this.name;
            if( c ){
                var hue = c.hue() + variance * MathUtils.normalizedRandom();
                range.hueConstraint = [ new FloatRange(hue,hue) ];
                range.alphaConstraint = [ new FloatRange(c.alpha(),c.alpha()) ];
            } else {
                range.hueConstraint = [].concat(this.hueConstraint);
                range.alphaConstraint = [].concat(this.alphaConstraint);
            }
            range.saturationConstraint = [].concat(this.saturationConstraint);
            range.brightnessConstraint = [].concat(this.brightnessConstraint);
            range.black = this.black.copy();
            range.white = this.white.copy();
            return range;
        }
1046327
def percent_b(data, period, upper_bb_std=2.0, lower_bb_std=2.0):
    
    lb = lower_bollinger_band(data, period, lower_bb_std)
    ub = upper_bollinger_band(data, period, upper_bb_std)
    percent_b = ((np.array(data) - lb) / (ub - lb)) * 100
    return percent_b
326373
def posterior(self, x, s=1.):
        """"""
        pr0 = 1. / self.sigma**2  # prior precision
        prd = x.size / s**2  # data precision
        varp = 1. / (pr0 + prd)  # posterior variance
        mu = varp * (pr0 * self.mu + prd * x.mean())
        return TruncNormal(mu=mu, sigma=np.sqrt(varp), a=self.a, b=self.b)
100242
def semiconvergents(x):
    """"""

    (q, n), d = divmod(x.numerator, x.denominator), x.denominator
    yield Fraction(q)
    p0, q0, p1, q1 = 1, 0, q, 1
    while n:
        (q, n), d = divmod(d, n), n
        for _ in range(q):
            p0, q0 = p0+p1, q0+q1
            yield Fraction(p0, q0)
        p0, q0, p1, q1 = p1, q1, p0, q0
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); };
}
264230
public static float[] stddev (int[] values, int start, int length)
    {
        // first we need the mean
        float mean = 0f;
        for (int ii = start, end = start + length; ii < end; ii++) {
            mean += values[ii];
        }
        mean /= length;

        // next we compute the variance
        float variance = 0f;
        for (int ii = start, end = start + length; ii < end; ii++) {
            float value = values[ii] - mean;
            variance += value * value;
        }
        variance /= (length - 1);

        // the standard deviation is the square root of the variance
        return new float[] { mean, variance, (float)Math.sqrt(variance) };
    }
126419
@Override
	public double varianceOfStockPrice(double time) {
		return Math.pow(initialValue, 2) * Math.exp(2 * riskFreeRate * time)
				* (Math.exp(Math.pow(volatility, 2) * time) - 1);
	}
1326018
private static double AndersonDarling(double[] x) {
        int n = x.length;
        Arrays.sort(x);

        for (int i = 0; i < n; i++) {
            x[i] = GaussianDistribution.getInstance().cdf(x[i]);
            // in case overflow when taking log later.
            if (x[i] == 0) x[i] = 0.0000001;
            if (x[i] == 1) x[i] = 0.9999999;
        }

        double A = 0.0;
        for (int i = 0; i < n; i++) {
            A -= (2*i+1) * (Math.log(x[i]) + Math.log(1-x[n-i-1]));
        }

        A = A / n - n;
        A *= (1 + 4.0/n - 25.0/(n*n));

        return A;
    }
983557
public double variance(double m1, Object pt1, Object ptSqr1, double m2, Object pt2, Object ptSqr2) {
		// compute the total mass
		double m0 = m1 + m2;
		// compute the new sum
		Object pt0 = newCopy(pt1);
		add(pt0, pt2);
		// compute the new sum of squares
		Object ptSqr0 = newCopy(ptSqr1);
		add(ptSqr0, ptSqr2);
		// compute the variance
		return variance(m0, pt0, ptSqr0);
	}