Calculates mean field
551997
def mean_field(self):
        """"""
        mean_field = []
        for sp_oper in [self.oper['O'], self.oper['O_d']]:
            avgO = np.array([self.expected(op) for op in sp_oper])
            avgO[abs(avgO) < 1e-10] = 0.
            mean_field.append(avgO*self.param['ekin'])

        return np.array(mean_field)
1233281
def _compute_mean(map1, map2):
        
        data = (map1.data + map2.data) / 2.
        return HpxMap(data, map1.hpx)
372682
def _get_mean(self, sites, rup, dists, imt, stddev_types):
        
        # Zhao et al. 2006 - Vs30 + Rrup
        mean_zh06, stds1 = super().get_mean_and_stddevs(sites, rup, dists, imt,
                                                        stddev_types)
        #
        # Atkinson and Macias (2009) - Rrup
        gmpe = AtkinsonMacias2009()
        mean_am09, stds2 = gmpe.get_mean_and_stddevs(sites, rup, dists, imt,
                                                     stddev_types)
        #
        # Abrahamson et al. (2015) - Rrup + vs30 + backarc
        gmpe = AbrahamsonEtAl2015SInter()
        mean_ab15, stds3 = gmpe.get_mean_and_stddevs(sites, rup, dists, imt,
                                                     stddev_types)
        #
        # Ghofrani and Atkinson (2014) - Rrup + vs30
        gmpe = GhofraniAtkinson2014()
        mean_ga14, stds4 = gmpe.get_mean_and_stddevs(sites, rup, dists, imt,
                                                     stddev_types)
        # Computing adjusted mean and stds
        cff = self.SITE_COEFFS[imt]
        mean_adj = (np.log(np.exp(mean_zh06)*cff['mf'])*0.1 +
                    mean_am09*0.5 + mean_ab15*0.2 +
                    np.log(np.exp(mean_ga14)*cff['mf'])*0.2)
        return mean_adj
1054304
def mse(mean, estimator):
    
    return np.mean((np.asarray(estimator) - np.asarray(mean)) ** 2, axis=0)
386364
def calculate_sample_mean(self, Data_sample_or_site):
        '''
        
        '''

        pars = {}
        tmp_B = []
        for spec in list(Data_sample_or_site.keys()):
            if 'B' in list(Data_sample_or_site[spec].keys()):
                tmp_B.append(Data_sample_or_site[spec]['B'])
        if len(tmp_B) < 1:
            pars['N'] = 0
            pars['pass_or_fail'] = 'fail'
            return pars

        tmp_B = np.array(tmp_B)
        pars['pass_or_fail'] = 'pass'
        pars['N'] = len(tmp_B)
        pars['B_uT'] = np.mean(tmp_B)
        if len(tmp_B) > 1:
            pars['B_std_uT'] = np.std(tmp_B, ddof=1)
            pars['B_std_perc'] = 100 * (pars['B_std_uT'] / pars['B_uT'])
        else:
            pars['B_std_uT'] = 0
            pars['B_std_perc'] = 0
        pars['sample_int_interval_uT'] = (max(tmp_B) - min(tmp_B))
        pars['sample_int_interval_perc'] = 100 * \
            (pars['sample_int_interval_uT'] / pars['B_uT'])
        pars['fail_list'] = []
        # check if pass criteria
        #----------
        # int_n
        if self.acceptance_criteria['average_by_sample_or_site']['value'] == 'sample':
            average_by_sample_or_site = 'sample'
        else:
            average_by_sample_or_site = 'site'

        if average_by_sample_or_site == 'sample':
            cutoff_value = self.acceptance_criteria['sample_int_n']['value']
        else:
            cutoff_value = self.acceptance_criteria['site_int_n']['value']
        if cutoff_value != -999:
            if pars['N'] < cutoff_value:
                pars['pass_or_fail'] = 'fail'
                pars['fail_list'].append("int_n")
        #----------
        # int_sigma ; int_sigma_perc
        pass_sigma, pass_sigma_perc = False, False
        if self.acceptance_criteria['average_by_sample_or_site']['value'] == 'sample':
            sigma_cutoff_value = self.acceptance_criteria['sample_int_sigma']['value']
        else:
            sigma_cutoff_value = self.acceptance_criteria['site_int_sigma']['value']

        if sigma_cutoff_value != -999:
            if pars['B_std_uT'] * 1e-6 <= sigma_cutoff_value:
                pass_sigma = True

        if self.acceptance_criteria['average_by_sample_or_site']['value'] == 'sample':
            sigma_perc_cutoff_value = self.acceptance_criteria['sample_int_sigma_perc']['value']
        else:
            sigma_perc_cutoff_value = self.acceptance_criteria['site_int_sigma_perc']['value']
        if sigma_perc_cutoff_value != -999:
            if pars['B_std_perc'] <= sigma_perc_cutoff_value:
                pass_sigma_perc = True

        if not (sigma_cutoff_value == -999 and sigma_perc_cutoff_value == -999):
            if not (pass_sigma or pass_sigma_perc):
                pars['pass_or_fail'] = 'fail'
                pars['fail_list'].append("int_sigma")

        pass_int_interval, pass_int_interval_perc = False, False
        if self.acceptance_criteria['average_by_sample_or_site']['value'] == 'sample':
            cutoff_value = self.acceptance_criteria['sample_int_interval_uT']['value']
            if cutoff_value != -999:
                if pars['sample_int_interval_uT'] <= cutoff_value:
                    pass_int_interval = True

            cutoff_value_perc = self.acceptance_criteria['sample_int_interval_perc']['value']
            if cutoff_value_perc != -999:
                if pars['sample_int_interval_perc'] <= cutoff_value_perc:
                    pass_int_interval_perc = True

            if not (cutoff_value == -999 and cutoff_value_perc == -999):
                if not (pass_int_interval or pass_int_interval_perc):
                    pars['pass_or_fail'] = 'fail'
                    pars['fail_list'].append("int_interval")

            # if cutoff_value != -999 or cutoff_value_perc != -999:
            #    if not (pass_int_interval or pass_int_interval_perc):
            #        pars['pass_or_fail']='fail'
            #        pars['fail_list'].append("int_interval")

            #
            #
            #
            #
            # if (acceptance_criteria['sample_int_sigma_uT']==0 and acceptance_criteria['sample_int_sigma_perc']==0) or\
            #    (pars['B_uT'] <= acceptance_criteria['sample_int_sigma_uT'] or pars['B_std_perc'] <= acceptance_criteria['sample_int_sigma_perc']):
            #        if ( pars['sample_int_interval_uT'] <= acceptance_criteria['sample_int_interval_uT'] or pars['sample_int_interval_perc'] <= acceptance_criteria['sample_int_interval_perc']):
            #            pars['pass_or_fail']='pass'
        return(pars)
856699
def mean(self, *args, **kwargs):
        
        nv.validate_window_func('mean', args, kwargs)
        return self._apply('ewma', **kwargs)
876404
def _compute_mean(self, C, f0, f1, f2, SC, mag, rrup, idxs, mean,
                      scale_fac):
        
        mean[idxs] = (C['c1'] +
                      C['c2'] * mag +
                      C['c3'] * (mag ** 2) +
                      (C['c4'] + C['c5'] * mag) * f1[idxs] +
                      (C['c6'] + C['c7'] * mag) * f2[idxs] +
                      (C['c8'] + C['c9'] * mag) * f0[idxs] +
                      C['c10'] * rrup[idxs] +
                      self._compute_stress_drop_adjustment(SC, mag, scale_fac))
1327818
def _get_mean(self, sites, C, ln_y_ref, exp1, exp2, v1):
        
        # we do not support estimating of basin depth and instead
        # rely on it being available (since we require it).
        z1pt0 = sites.z1pt0

        # we consider random variables being zero since we want
        # to find the exact mean value.
        eta = epsilon = 0

        ln_y = (
            # first line of eq. 13b
            ln_y_ref + C['phi1'] *
            np.log(np.clip(sites.vs30, -np.inf, v1) / 1130)
            # second line
            + C['phi2'] * (exp1 - exp2)
            * np.log((np.exp(ln_y_ref) + C['phi4']) / C['phi4'])
            # third line
            + C['phi5']
            * (1.0 - 1.0 / np.cosh(
                C['phi6'] * (z1pt0 - C['phi7']).clip(0, np.inf)))
            + C['phi8'] / np.cosh(0.15 * (z1pt0 - 15).clip(0, np.inf))
            # fourth line
            + eta + epsilon
        )

        return ln_y
474681
def _compute_mean(self, C, g, mag, hypo_depth, dists, imt):
        

        delta = 0.00750 * 10 ** (0.507 * mag)

        # computing R for different values of mag
        if mag < 6.5:
            R = np.sqrt(dists.rhypo ** 2 + delta ** 2)
        else:
            R = np.sqrt(dists.rrup ** 2 + delta ** 2)

        mean = (
            # 1st term
            C['c1'] + C['c2'] * mag +
            # 2nd term
            C['c3'] * R -
            # 3rd term
            C['c4'] * np.log10(R) +
            # 4th term
            C['c5'] * hypo_depth
        )
        # convert from base 10 to base e
        if imt == PGV():
            mean = np.log(10 ** mean)
        else:
            # convert from cm/s**2 to g
            mean = np.log((10 ** mean) * 1e-2 / g)
        return mean
496203
def plot_mean_field_conv(N=1, n=0.5, Uspan=np.arange(0, 3.6, 0.5)):
    

    sl = Spinon(slaves=2*N, orbitals=N, avg_particles=2*n,
                       hopping=[0.5]*2*N, orbital_e=[0]*2*N)
    hlog = solve_loop(sl, Uspan, [0.])[1]

    f, (ax1, ax2) = plt.subplots(2, sharex=True)
    for field in hlog:
        field = np.asarray(field)
        ax1.semilogy(abs(field[1:]-field[:-1]))
        ax2.plot(field)#, label = 'h, U = {}'.format(Uint))

    plt.title('Convergence of selfconsintent mean field')
    ax1.set_ylabel('$\\Delta h$')
    ax2.set_ylabel('mean field $h$')
    plt.xlabel('iterations')

    return hlog
998991
def mean_fill(adf):
        
        ordpt = adf.values[0]
        if not pd.isnull(ordpt):
            return ordpt

        fdmn = adf.iloc[1:-1].mean()
        if not pd.isnull(fdmn):
            return fdmn

        flspt = adf.values[-1]
        if not pd.isnull(flspt):
            return flspt

        return nan
1107433
def get_average(self, field=None):
        

        if not field:
            raise AttributeError("Please provide field to apply aggregation to!")
        agg = A("avg", field=field)
        self.aggregations['avg_' + field] = agg
        return self
1085985
def _compute_mean(self, C, mag, r):
        
        mean = (C['c1'] +
                self._compute_term1(C, mag) +
                self._compute_term2(C, mag, r))
        return mean
450498
function mean( out, x ) {
	var len = x.length,
		i;
	if ( out.length !== len ) {
		throw new Error( 'mean()::invalid input arguments. Input and output matrices must be the same length.' );
	}
	for ( i = 0; i < len; i++ ) {
		out.data[ i ] = MEAN( x.data[ i ] );
	}
	return out;
}
658849
def _compute_mean(self, C, mag, rrup):
        
        mean = np.zeros_like(rrup)

        mean += C['c1'] + C['c2'] * mag + C['c3'] * (8.5 - mag) ** 2

        idx = rrup > 70.
        mean[idx] += C['c7'] * (np.log(rrup[idx]) - np.log(70.))

        idx = rrup > 130.
        mean[idx] += C['c8'] * (np.log(rrup[idx]) - np.log(130.))

        R = np.sqrt(
            rrup ** 2 + (C['c5'] * np.exp(C['c6'] * mag)) ** 2
        )
        mean += C['c4'] * np.log(R) + (C['c9'] + C['c10'] * mag) * rrup

        return mean
1317803
def compute_balance_mean(self, ts, t):
        
        """ For changed words we expect an increase in the mean, and so only 1 """
        return np.mean(ts[t + 1:]) - np.mean(ts[:t + 1])
874304
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        R = (dists.rrup)
        M = rup.mag
        # get constants
        Ssr = self.get_Ssr_term(sites.vs30)
        Shr = self.get_Shr_term(sites.vs30)
        rake = rup.rake
        F = self.get_fault_term(rake)

        # compute mean
        mean = -3.512 + (0.904 * M) - (1.328 * np.log(np.sqrt(R**2
               + (0.149 * np.exp(0.647 * M))**2))) \
               + (1.125 - 0.112 * np.log(R) - 0.0957 * M) * F \
               + (0.440 - 0.171 * np.log(R)) * Ssr \
               + (0.405 - 0.222 * np.log(R)) * Shr
        stddevs = self.get_stddevs(mean, stddev_types)
        return mean, stddevs