def Log(self): result = BootStrap(self.nboot, name='log(' + str(self) + ')') result.cfgvals = logNA(self.cfgvals) result.bootvals = logNA(self.bootvals) if hasattr(self, 'n_block') and self.n_block > 1: result.block_cfgvals = {} result.block_bootvals = {} for ikey, idata in self.block_cfgvals.items(): result.block_cfgvals = logNA(self.cfgvals) for ikey, idata in self.block_cfgvals.items(): result.block_bootvals = logNA(self.bootvals) return result
def ChitFitFunDer(x, p): Denom = (x[0] * (logNA(x[0]) + p[2]))**(-1) return np.array([Denom * x[0], Denom, -x[0] * (Denom**2)])
def uWerrMine(self,data='PreDef',fun='PreDef', Sparam='PreDef',WipeData=True,save_covar=True): ''' Main function for computing the total autocorrelation of quantity, following the method in [1]_. Parameters ---------- data: {'PreDef'} [variable, (replicas), montecarlo time] optional data to perform autocorrelation analysis over. Not passing in any data will default to the data stored in the object fun: {'PreDef'} function(*variable) optional function descibing how to combine the indipendant statistical quantities. Not passing in any function will default to the data stored in the object Sparam: {'PreDef'} float optional S parameter for Autocorrlation analysis WipeData: {True} optional Wipe the internal configuration data after computing the autocorrelation statistical quantities. save_covar: {True} optional Saves the covariance matrix as an internal variable References ---------- .. [1] U. Wolff [ALPHA Collaboration], ``Monte Carlo errors with less errors,'' Comput.\ Phys.\ Commun.\ {\bf 156}, 143 (2004) Erratum: [Comput.\ Phys.\ Commun.\ {\bf 176}, 383 (2007)] doi:10.1016/S0010-4655(03)00467-3, 10.1016/j.cpc.2006.12.001 [hep-lat/0306017]. ''' self.GetFuns() if data == 'PreDef': if isinstance(self.values,str): print('data not imported for ',self.name) else: data = self.values if fun == 'PreDef': if isinstance(self.Fun,str): print('Function and derivative have not been defined for ',self.name) else: fun,funder = self.Fun,self.FunDer if Sparam=='PreDef': Sparam = self.Sparam avgdata = [data[icol].mean() for icol in data] glen = 0 if isinstance(data.index,pa.MultiIndex): if self.has_reps: data_numpy = [] for icol in data: data_numpy.append([]) for istream,stream_data in data[icol].groupby(level='stream'): # glen = max(glen,stream_data.size) glen += stream_data.size data_numpy[-1].append(stream_data[istream].values) data_numpy = np.array(data_numpy) else: data_numpy = np.swapaxes(data.values,0,1) glen = data_numpy.shape[1] else: data_numpy = np.swapaxes(data.values,0,1) glen = data_numpy.shape[1] ## (31) matrix of autocorrelations w.r.t ab= variables G_ab_t = [] for adat in data_numpy: G_ab_t.append([ self.autocorr(adat,bdat) for bdat in data_numpy]) # G_ab_t.append([ self.MyCorrelate(adat,bdat) for bdat in data_numpy]) G_ab_t = np.array(G_ab_t) if save_covar: self.covar = [] G_ab_0 = G_ab_t[:,:,0] for ia,Ga in enumerate(G_ab_t[:,:,0]): for ib,Gab in enumerate(Ga): self.covar.append(Gab/np.sqrt(G_ab_0[ia,ia]*G_ab_0[ib,ib])) self.covar = np.array(self.covar).reshape(G_ab_0.shape) self.covar_NoNorm = G_ab_0/glen ## (33) alpha function derivates (w.r.t variables) f_a = np.array(funder(*avgdata)) f_ab = [] for if_a in f_a: f_ab.append([if_b*if_a for if_b in f_a]) f_ab = np.array(f_ab) # print 'debug' , data.shape, G_ab_t.shape, f_ab.shape, (f_ab * G_ab_t[:,:,0]).shape,np.sum(f_ab * G_ab_t[:,:,0]).shape # print 'debug',self.name, # print f_ab * G_ab_t[:,:,5] # print ## (33) GFt = [np.sum(f_ab * G_ab) for G_ab in np.rollaxis(G_ab_t,-1) ] ## (35) CFW = np.array([GFt[0]]+[GFt[0] + 2*np.sum(GFt[1:W+1]) for W in range(1,len(GFt))]) # Bias corrections (49) CFW = self.BiasCorrect(CFW,glen) ## (34) nuF = CFW[0] ## equation (41) tauint = CFW / (2*nuF) ## From Paper tau = [] for it,itauint in enumerate(tauint): if itauint <= 0.5: tau.append(0.00000001) else: ## (51) tau.append(Sparam/logNA((2*itauint+1)/(2*itauint-1))) # ## From Matlab # tau = [] # for iGFt in GFt: # if iGFt <= 0.0: # tau.append(0.0000001) # else: # tau.append(Sparam/logNA((iGFt+1)/iGFt)) ## (52) Wopt = self.gW(np.array(tau),glen) ## (42) dtauint = self.VarTau(tauint,glen) ## average, error(W), tau(W), tauerr(W), GFt(W), Wopt ## average, error[Woptimal], tau[Woptimal], tauerr[Woptimal] self.Avg = fun(*avgdata) self.Avg_paras = avgdata # self.Avg = np.mean([fun(*ival) for ival in np.swapaxes(data,0,1)]) try: self.Std = np.sqrt(np.abs(CFW[Wopt])/float(glen)) self.Std_corr = np.sqrt(np.abs(CFW[0])/float(glen)) self.Wopt = Wopt self.GFt = GFt self.tau = tauint[Wopt] self.tauerr = dtauint[Wopt] except Exception as err: print('NaN for Autocorr') Wopt = -1 self.Std = np.sqrt(np.abs(CFW[Wopt])/float(glen)) self.Std_corr = np.sqrt(np.abs(CFW[0])/float(glen)) self.Wopt = Wopt self.GFt = GFt self.tau = tauint[Wopt] self.tauerr = dtauint[Wopt] self.StdW = np.sqrt(np.abs(CFW)/float(glen)) self.tauW = tauint self.tauerrW = dtauint if WipeData: self.RemoveVals() self.RemoveFuns()
def ChitFitFun(x, p): Denom = (x[0] * (logNA(x[0]) + p[2]))**(-1) return (p[0] * x[0] + p[1]) * Denom
def LogFFDer_x0(x, p): return [logNA(x[0])]
def LogFitFun_x0(x, p): return p[0] * logNA(x[0])
def LogFFDer(x, p): return [logNA(x[0]), makexunit(x[0])]
def LogFitFun(x, p): return p[0] * logNA(x[0]) + p[1]