Compute total standard deviation, see tables 3 and 4, pages 227 and
        228.
769070
def _compute_std(self, C, stddevs, idx):
        
        for stddev in stddevs:
            stddev[idx] += C['sigma']
1367907
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        # extract dictionaries of coefficients specific to required
        # intensity measure type
        C = self.COEFFS[imt]

        mean = self._compute_mean(C, rup, dists, sites, imt)

        stddevs = self._get_stddevs(C, stddev_types, sites.vs30.shape[0])

        return mean, stddevs
1245710
def get_stddevs(self, C, nsites, stddev_types):
        
        stddevs = []
        zeros_array = np.zeros(nsites)
        for stddev in stddev_types:
            assert stddev in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
            if stddev == const.StdDev.TOTAL:
                stddevs.append(np.sqrt(C["tau"] ** 2. + C["phi"] ** 2.) +
                               zeros_array)
            elif stddev == const.StdDev.INTER_EVENT:
                stddevs.append(C["tau"] + zeros_array)
            elif stddev == const.StdDev.INTRA_EVENT:
                stddevs.append(C["phi"] + zeros_array)
        return stddevs
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);
  }
1048914
def stats():
    ''''''
    import re
    import sys
    import math
    values = []
    for line in sys.stdin:
        values.extend(map(float, re.findall(r'\d+\.?\d+', line)))

    mean = sum(values) / len(values)
    variance = sum((val - mean) ** 2 for val in values) / len(values)
    print '%3i items; mean: %10.5f; std-dev: %10.5f' % (
        len(values), mean, math.sqrt(variance))
660071
def get_mean_and_stddevs(self, sites, rup, dists, imt, stds_types):
        

        mean_list = []
        stddvs_list = []

        # Loop over averaging periods
        for period in self.avg_periods:
            imt_local = SA(float(period))
            # compute mean and standard deviation
            mean, stddvs = self.gmpe.get_mean_and_stddevs(sites, rup, dists,
                                                          imt_local,
                                                          stds_types)
            mean_list.append(mean)
            stddvs_list.append(stddvs[0])  # Support only for total!

        mean_avgsa = 0.
        stddvs_avgsa = 0.

        for i1 in range(self.tnum):
            mean_avgsa += mean_list[i1]
            for i2 in range(self.tnum):
                rho = self.corr_func.get_correlation(self.avg_periods[i1],
                                                     self.avg_periods[i2])
                stddvs_avgsa += rho * stddvs_list[i1] * stddvs_list[i2]

        mean_avgsa /= self.tnum
        stddvs_avgsa = np.sqrt(stddvs_avgsa)/self.tnum

        return mean_avgsa, [stddvs_avgsa]
118508
def _get_stddevs(self, C, sites, pga1100, sigma_pga, stddev_types):
        
        std_intra = self._compute_intra_event_std(C,
                                                  sites.vs30,
                                                  pga1100,
                                                  sigma_pga)

        std_inter = C['t_lny'] * np.ones_like(sites.vs30)
        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(self._get_total_sigma(C, std_intra, std_inter))
            elif stddev_type == const.StdDev.INTRA_EVENT:
                stddevs.append(std_intra)
            elif stddev_type == const.StdDev.INTER_EVENT:
                stddevs.append(std_inter)
        return stddevs
46961
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
                   for stddev_type in stddev_types)

        C = self.COEFFS[imt]

        imean = (self._compute_magnitude_scaling(C, rup.mag) +
                 self._compute_distance_scaling(C, dists.rrup, rup.mag))
        # Original GMPE returns log10 acceleration in cm/s/s
        # Converts to natural logarithm of g
        mean = np.log((10.0 ** (imean - 2.0)) / g)
        mean = self._compute_site_scaling(sites.vs30, mean)
        istddevs = self._compute_stddevs(
            C, dists.rrup.shape, stddev_types
        )
        # Convert from common logarithm to natural logarithm
        stddevs = np.log(10 ** np.array(istddevs))
        return mean, 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
989778
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        # extracting dictionary of coefficients
        C = self.COEFFS[imt]

        mag = self._convert_magnitude(rup.mag)

        # computing the magnitude term. Equation 19, page 2291
        f1 = self._compute_magnitude_scaling_term(C, mag)

        # computing the geometrical spreading term. Equation 20, page 2291
        f2 = self._compute_geometrical_spreading_term(C, dists.rrup)

        # computing the anelastic attenuation term. Equation 21, page 2291
        f3 = self._compute_anelastic_attenuation_term(C, dists.rrup, mag)

        # computing the mean ln(IMT) using equation 18 at page 2290
        mean = f1 + f2 + f3

        mean = self._clip_mean(imt, mean)

        # computing the total standard deviation
        stddevs = self._get_stddevs(C, stddev_types, num_sites=len(dists.rrup),
                                    mag=mag)

        return mean, stddevs
485759
def _get_stddevs(self, C, stddev_types, num_sites, mag, c1_rrup,
                     log_phi_ss, mean_phi_ss):
        
        phi_ss = _compute_phi_ss(C, mag, c1_rrup, log_phi_ss, mean_phi_ss)

        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(np.sqrt(
                               C['tau'] * C['tau'] +
                               phi_ss * phi_ss) +
                               np.zeros(num_sites))

            elif stddev_type == const.StdDev.INTRA_EVENT:
                stddevs.append(phi_ss + np.zeros(num_sites))

            elif stddev_type == const.StdDev.INTER_EVENT:
                stddevs.append(C['tau'] + np.zeros(num_sites))
        return stddevs
113788
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        

        sites.vs30 = 600 * np.ones(len(sites.vs30))

        mean, stddevs = super(AkkarBommer2010SWISS01, self).\
            get_mean_and_stddevs(sites, rup, dists, imt, stddev_types)

        tau_ss = 'tau'
        log_phi_ss = np.log(10)
        mean, stddevs = _apply_adjustments(
            AkkarBommer2010.COEFFS, self.COEFFS_FS_ROCK[imt], tau_ss,
            mean, stddevs, sites, rup, dists.rjb, imt, stddev_types,
            log_phi_ss)

        return mean,  np.log(10 ** np.array(stddevs))
575790
def variance(self) -> Optional[float]:  #, ddof: int = 0) -> float:
        
        # TODO: Add DOF
        # http://stats.stackexchange.com/questions/6534/how-do-i-calculate-a-weighted-standard-deviation-in-excel
        if self._stats:
            if self.total > 0:
                return (self._stats["sum2"] - self._stats["sum"] ** 2 / self.total) / self.total
            else:
                return np.nan
        else:
            return None
857592
def _get_stddevs(self, C, stddev_types, num_sites, mag):
        
        stddevs = []
        sigma = (C['c14'] + C['c15'] * mag) if mag < 7.2 else C['c16']
        vals = sigma * np.ones((num_sites))
        for _ in stddev_types:
            stddevs.append(vals)
        return stddevs
678750
def calc_deviation(values, average):
    
    size = len(values)
    if size < 2:
        return 0
    calc_sum = 0.0

    for number in range(0, size):
        calc_sum += math.sqrt((values[number] - average) ** 2)
    return math.sqrt((1.0 / (size - 1)) * (calc_sum / size))
86290
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        # pylint: disable=too-many-arguments
        

        # extract dictionary of coefficients specific to required
        # intensity measure type
        coeffs = self.COEFFS[imt]
        coeffs.update(self.CONSTS)

        # equation (1) is in terms of common logarithm
        log_mean = (self._compute_magnitude(rup, coeffs) +
                    self._compute_distance(dists, coeffs) +
                    self._get_site_amplification(sites, coeffs) +
                    self._get_mechanism(rup, coeffs))
        # so convert to g and thence to the natural logarithm
        mean = log_mean*np.log(10.0) - np.log(g)

        # convert standard deviations from common to natural logarithm
        log_stddevs = self._get_stddevs(coeffs, stddev_types, len(sites.vs30))
        stddevs = log_stddevs*np.log(10.0)

        return mean, stddevs
1023800
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        mean = self._get_mean(sites.vs30, rup.mag, dists.rrup, imt, scale_fac=0)
        stddevs = self._get_stddevs(stddev_types, num_sites=sites.vs30.size)

        return mean, stddevs