computes the relative absolute error (condensed using standard deviation formula)
510668
def rae(label, pred):
    """"""
    numerator = np.mean(np.abs(label - pred), axis=None)
    denominator = np.mean(np.abs(label - np.mean(label, axis=None)), axis=None)
    return numerator / denominator
1075229
def almost_eq(arr1, arr2, thresh=1E-11, ret_error=False):
    
    error = np.abs(arr1 - arr2)
    passed = error < thresh
    if ret_error:
        return passed, error
    return passed
1327033
def _fast_normalise(self):
        
        if not self.is_unit():
            mag_squared = np.dot(self.q, self.q)
            if (mag_squared == 0):
                return
            if (abs(1.0 - mag_squared) < 2.107342e-08):
                mag =  ((1.0 + mag_squared) / 2.0) # More efficient. Pade approximation valid if error is small
            else:
                mag =  sqrt(mag_squared) # Error is too big, take the performance hit to calculate the square root properly

            self.q = self.q / mag
951519
function mse(errors) {
  var sum = 0;
  for (var i = 0; i < this.constants.size; i++) {
    sum += Math.pow(errors[i], 2);
  }
  return sum / this.constants.size;
}
1178412
def get_percentage_relative_to(val, other):
    
    val = float(val)
    other = float(other)
    ratio = val / other - 1

    return ratio * 100.0
425938
def hmsStrToDeg(ra):
    """"""
    hour, min, sec = ra.split(':')
    ra_deg = hmsToDeg(int(hour), int(min), float(sec))
    return ra_deg
199748
def standardised_euclidean(x, y, sigma=_mock_ones):
    
    result = 0.0
    for i in range(x.shape[0]):
        result += ((x[i] - y[i]) ** 2) / sigma[i]

    return np.sqrt(result)
1003236
def calculate_clock_skew(self):
        
        n = self.statx_n(self.data_points)

        """
        Required to be able to compute the standard
        deviation.
        """
        if n < 1:
            return Decimal("0")

        avg = self.statx_avg(self.data_points)
        sdev = self.statx_sdev(self.data_points)

        """
        Incrementally remove aberration points.
        """
        for k in range(0, self.clean_steps):
            """
            Remove aberration points: keep only
            the sigma range around the average.
            """
            min_val = avg - sdev
            max_val = avg + sdev

            cleaned_data_points = []
            for i in range(0, n):
                v = self.data_points[i]
                if v < min_val or v > max_val:
                    continue
                cleaned_data_points.append(v)

            self.data_points = cleaned_data_points[:]

            """
            Recompute the new average using the
            "sound" points we kept.
            """
            n = self.statx_n(self.data_points)

            """
            Not enough data to compute standard
            deviation.
            """
            if n < 2:
                break

            avg = self.statx_avg(self.data_points)
            sdev = self.statx_sdev(self.data_points)

            if sdev <= self.max_sdev or n < self.min_data:
                break

        """
        If standard deviation is too large still, we
        cannot update our clock. Collect more points.

        If we don't have a minimum amount of data,
        don't attempt the update yet, continue collecting.
        """
        if sdev > self.max_sdev or n < self.min_data:
            return Decimal("0")

        return avg
248599
def _compute_error(self):
        """"""
        sum_x = sum(self.x_transforms)
        err = sum((self.y_transform - sum_x) ** 2) / len(sum_x)
        return err
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
1109436
def std_err(self):
        

        return np.sqrt(np.sum(np.square(self.resids), axis=0) / self.df_err)
717711
def rmsd(ref_cds, est_cds):
    
    ref_dists = pdist(ref_cds)
    est_dists = pdist(est_cds)
    return np.sqrt(((ref_dists - est_dists)**2).mean())
749613
def _compute_standard_dev(self, rup, imt, C):
        
        sigma_mean = 0.
        if rup.mag <= 7.0:
            sigma_mean = (C['c12'] * rup.mag) + C['c13']
        elif rup.mag > 7.0:
            sigma_mean = (-0.00695 * rup.mag) + C['c14']
        return sigma_mean
1347308
def standard_deviation(data, period):
    
    catch_errors.check_for_period_error(data, period)

    stds = [np.std(data[idx+1-period:idx+1], ddof=1) for idx in range(period-1, len(data))]

    stds = fill_for_noncomputable_vals(data, stds)
    return stds
960055
def averageSize(self):
        """"""
        cm = self.centerOfMass()
        coords = self.coordinates(copy=False)
        if not len(coords):
            return 0
        s, c = 0.0, 0.0
        n = len(coords)
        step = int(n / 10000.0) + 1
        for i in np.arange(0, n, step):
            s += utils.mag(coords[i] - cm)
            c += 1
        return s / c
388571
def calc_uncertainty(quantity, sys_unc, mean=True):
    """"""
    n = len(quantity)
    std = np.nanstd(quantity)
    if mean:
        std /= np.sqrt(n)
    return np.sqrt(std**2 + sys_unc**2)
131766
def _get_stddevs(self, C, stddev_types, num_sites, mag_conversion_sigma):
        
        assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
                   for stddev_type in stddev_types)

        sigma = np.zeros(num_sites) + C['sigma'] * np.log(10)
        sigma = np.sqrt(sigma ** 2 + (C['a'] ** 2) * (mag_conversion_sigma ** 2))
        stddevs = [sigma for _ in stddev_types]

        return stddevs