def F_W(a, b, M_0, M_1, M_2, M_3): ''' F_W function, the top level of computation. When b=0, value is immediately phi(a). ''' return np.where(b==0., hlp.psi_catnew(u=a), F_0(a=a, b=b, M_0=M_0)-F_3(a=a, b=b, M_1=M_1, M_2=M_2, M_3=M_3))
def coef_onecubeminus_D(gam, eta): alpha = (eta - 1) / eta return 6 * (hlp.psi_catnew(math.sqrt(2)) * alpha + gam - gam**3 / 6)
def xhat_mult_bernoulli(x, s): return s * np.mean(hlp.psi_catnew(x/s))
def Hfn(eta, gam): out = np.zeros(eta.shape) deltaval = math.fabs((gam - math.sqrt(2))) idx_zero = np.nonzero(eta == 0)[0] idx_one = np.nonzero(eta == 1)[0] idx_half = np.nonzero(eta == 1 / 2)[0] idx_small = np.setdiff1d(np.nonzero(eta < 1 / 2)[0], idx_zero) idx_large = np.setdiff1d(np.nonzero(eta > 1 / 2)[0], idx_one) idx_tricky = np.union1d(np.union1d(idx_half, idx_zero), idx_one) idx_therest = np.setdiff1d(np.arange(eta.size), idx_tricky) eta_large = eta[idx_large] eta_small = eta[idx_small] eta_therest = eta[idx_therest] if (gam <= math.sqrt(2) / 2): # In this case, only solve the double-cube condition. Hvals = Hfn_double(gam=gam, eta=eta_therest) out[idx_therest] = Hvals elif (gam > math.sqrt(2)): # In this case, only solve the single-cube condition. # Deal with larger eta values (above 1/2). out[idx_large] = Hfn_single_large(gam=gam, eta=eta_large) # Deal with smaller eta values (below 1/2). out[idx_small] = Hfn_single_small(gam=gam, eta=eta_small) else: # Otherwise, a bit more checking is required. Q = hlp.psi_catnew(deltaval - gam) / hlp.psi_catnew(deltaval + gam) tocheck = np.where((eta_therest > 1 / 2), ((eta_therest - 1) / eta_therest), (eta_therest / (eta_therest - 1))) Hvals = np.zeros(eta_therest.size) for t in range(eta_therest.size): etaval = np.take(a=eta_therest, indices=[t]) if (Q < tocheck[t]): # Solving the single-cube condition is enough. if (etaval > 1 / 2): Hvals[t] = Hfn_single_large(gam=gam, eta=etaval) else: Hvals[t] = Hfn_single_small(gam=gam, eta=etaval) else: # None are relevant; solve the double-cube condition. Hvals[t] = Hfn_double(gam=gam, eta=etaval) out[idx_therest] = Hvals # Deal with the edges and middle. out = np.where((eta == 1), 0, out) out = np.where((eta == 0), 0, out) out = np.where((eta == 1 / 2), hlp.rho_catnew(gam), out) return out