Computes the current estimate of the standard deviation.

    Note that the standard deviation is not defined until at least two samples
    were seen.

    Returns:
      Tensor of current variance.
175371
def _std(self):
    
    variance = tf.cond(
        self._count > 1,
        lambda: self._var_sum / tf.cast(self._count - 1, tf.float32),
        lambda: tf.ones_like(self._var_sum) * float('nan'))
    # The epsilon corrects for small negative variance values caused by
    # the algorithm. It was empirically chosen to work with all environments
    # tested.
    return tf.sqrt(variance + 1e-4)
299407
def estimate(self):
        
        E = self.alpha * float(self.m ** 2) / np.power(2.0, - self.M).sum()
        if E <= 2.5 * self.m:             # Small range correction
            V = self.m - np.count_nonzero(self.M)
            return int(self.m * np.log(self.m / float(V))) if V > 0 else int(E)
        # intermidiate range correction -> No correction
        elif E <= float(long(1) << self.precision) / 30.0:
            return int(E)
        else:
            return int(-(long(1) << self.precision) *
                       np.log(1.0 - E / (long(1) << self.precision)))
1166730
def _get_stddevs(self, C, mag, stddev_types, num_sites):
        
        std = C['c16'] + np.zeros(num_sites)

        if mag < 7.4:
            std -= 0.07 * mag
        else:
            std -= 0.518

        # only the 'total' standard deviation is supported, therefore the
        # std is always the same for all types
        stddevs = [std for _ in stddev_types]

        return stddevs
1355950
def _get_stddevs(self, C, stddev_types, num_sites):
        
        assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
            for stddev_type in stddev_types)
        stddevs = [np.zeros(num_sites) + C['SigmaTot'] for _ in stddev_types]
        return stddevs
849995
function() {
			// Get the mean
			var mean = this.mean();

			// Get a new stats object to work with
			var nums = this.clone();

			// Map each element of nums to the square of the element minus the
			// mean
			nums.map(function(num) {
				return Math.pow(num - mean, 2);
			});

			// Return the standard deviation
			return Math.sqrt(nums.sum() / (nums.size() - 1));
		}
646330
def get_relative_error(self):
        
        if not self.moment_tensor:
            raise ValueError('Moment tensor not defined!')

        numer = np.tensordot(self.moment_tensor.tensor_sigma,
                             self.moment_tensor.tensor_sigma)

        denom = np.tensordot(self.moment_tensor.tensor,
                             self.moment_tensor.tensor)
        self.e_rel = sqrt(numer / denom)
        return self.e_rel
292715
def _compute_derivatives(self):
        
        derivatives = []
        for i, (timestamp, value) in enumerate(self.time_series_items):
            if i > 0:
                pre_item = self.time_series_items[i - 1]
                pre_timestamp = pre_item[0]
                pre_value = pre_item[1]
                td = timestamp - pre_timestamp
                derivative = (value - pre_value) / td if td != 0 else value - pre_value
                derivative = abs(derivative)
                derivatives.append(derivative)
        # First timestamp is assigned the same derivative as the second timestamp.
        if derivatives:
            derivatives.insert(0, derivatives[0])
        self.derivatives = derivatives
1224930
def get_deviations(self):
        

        mean_vec = self.mean()

        df = self.loc[:,:].copy()
        for col in df.columns:
            df.loc[:,col] -= mean_vec[col]
        return type(self).from_dataframe(pst=self.pst,df=df)
421304
def covariance(self):
        
        if self._covariance is None:
            # LiK, _ = dtrtrs(self.woodbury_chol, self._K, lower=1)
            self._covariance = (
            np.atleast_3d(self._K) - np.tensordot(np.dot(np.atleast_3d(self.woodbury_inv).T, self._K), self._K,
                                                  [1, 0]).T).squeeze()
            # self._covariance = self._K - self._K.dot(self.woodbury_inv).dot(self._K)
        return self._covariance
240641
def u(self):
        ''
        self._check_estimated()
        u_mod = self.u_pc_1
        N = self._R.shape[0]
        u_input = np.zeros(N+1)
        u_input[0:N] = self._R.dot(u_mod[0:-1])  # in input basis
        u_input[N] = u_mod[-1] - self.mean.dot(self._R.dot(u_mod[0:-1]))
        return u_input
1081067
def Var(self, mu=None):
        
        if mu is None:
            mu = self.Mean()

        var = 0.0
        for x, p in self.d.iteritems():
            var += p * (x - mu) ** 2
        return var
248736
def _get_lr_tensor(self):
    
    lr = tf.squared_difference(1.0, tf.sqrt(self._mu)) / self._h_min
    return lr
97432
def get_currentDim(self):
        '''
        
        '''
        selfDim = self._dimensions.copy()
        if not isinstance(selfDim,dimStr):
            if selfDim.has_key('_ndims') : nself = selfDim.pop('_ndims')
            else : 
                self.warning(1, 'self._dimensions does not have the _ndims key')
                nself = len(selfDim)
        else : nself = selfDim['_ndims']
        curDim = [[key for key in selfDim.keys()],[selfDim[key] for key in selfDim.keys()]]
        return curDim, nself
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
24797
def get_stddevs(self, mag, imt, stddev_types, num_sites):
        
        tau = self._get_tau(imt, mag)
        phi = self._get_phi(imt, mag)
        sigma = np.sqrt(tau ** 2. + phi ** 2.)
        stddevs = []
        for stddev_type in stddev_types:
            assert stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
            if stddev_type == const.StdDev.TOTAL:
                stddevs.append(sigma + np.zeros(num_sites))
            elif stddev_type == const.StdDev.INTRA_EVENT:
                stddevs.append(phi + np.zeros(num_sites))
            elif stddev_type == const.StdDev.INTER_EVENT:
                stddevs.append(tau + np.zeros(num_sites))
        return stddevs
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
150820
def _get_deviation_of_mean(self, series, multiplier=3):
        
        capped_series = np.minimum(
            series, series.mean() + multiplier * series.std())
        count = pd.value_counts(series != capped_series)
        count = count[True] if True in count else 0
        perc = self._percent(count / self.length)
        return count, perc