def EMA(x, a, c, xa, xc, xsca, xscc, sigmaa, sigmac, b): #c=f*c #assume that xsca=xscc and sigmaa=sigmac sqrt2 = np.sqrt(2.) #print xa,xc,a,c,scdtm,fc #print (xsc - x[0]) / xa, (sigmaa ** 2) / 2. / (xa ** 2), (xsc - x[0]) / xc, (sigmac ** 2) / 2. / (xc ** 2) aexpterm = np.exp((xsca - x) / xa + (sigmaa**2) / 2. / (xa**2)) aexpterm[np.isinf(aexpterm) == True] = 0. EMA1=0.5 * a * aexpterm \ * serfc((xsca - x) / sqrt2 / sigmaa + sigmaa / sqrt2 / xa) if (np.absolute(a) < 1.e-20) | (np.absolute(sigmaa) < 1.e-20): EMA1[:] = 0. # in the case of gamma distribution if np.absolute(xa - xc) / xa < 1.e-10: tsterm = (x - xscc) / (sigmac**2) - 1. / xc erfterm = serf((sigmac**2 - xc * (x - xscc)) / sqrt2 / sigmac / xc) gausterm = np.exp(-1 * ((x - xscc)**2) / 2. / (sigmac**2)) convterm = sigmac**2 / 2. * tsterm * np.exp( ((sigmac * tsterm)**2) / 2.) * (1. - erfterm) + sigmac / sqrt2 / np.sqrt(np.pi) outEMA = EMA1 + convterm * gausterm * c / xc + b outEMA[np.isnan(outEMA) | np.isinf(outEMA)] = EMA1[np.isnan(outEMA) | np.isinf(outEMA)] + b return outEMA scdtm = c * xa / (xa - xc) bexpterm = np.exp((xscc - x) / xa + (sigmac**2) / 2. / (xa**2)) bexpterm[np.isinf(bexpterm) == True] = 0. EMA2 = 0.5 * scdtm *bexpterm \ * serfc((xscc - x) / sqrt2 / sigmac + sigmac / sqrt2 / xa) cexpterm = np.exp((xscc - x) / xc + (sigmac**2) / 2. / (xc**2)) cexpterm[np.isinf(cexpterm) == True] = 0. EMA3 = -0.5 * scdtm *cexpterm \ * serfc((xscc - x) / sqrt2 / sigmac + sigmac / sqrt2 / xc) if (np.absolute(scdtm) < 1.e-20) | (np.absolute(sigmac) < 1.e-20): EMA2[:] = 0. EMA3[:] = 0. return EMA1 + EMA2 + EMA3 + b
def EMALeft(x, a, xa, xsc, sigmaa): sqrt2 = np.sqrt(2.) #print xa,xc,a,c,scdtm,fc #print (xsc - x[0]) / xa, (sigmaa ** 2) / 2. / (xa ** 2), (xsc - x[0]) / xc, (sigmac ** 2) / 2. / (xc ** 2) return 0.5 * a* np.exp((xsc - x) / xa + (sigmaa ** 2) / 2. / (xa ** 2)) \ * serfc((xsc - x) /sqrt2 / sigmaa + sigmaa /sqrt2 / xa)
def EMG2D(x, y, a, x0, ux, uy, sigma, b, eta): xp = x - ux yp = y - uy sqrt2 = np.sqrt(2.) sigmay = np.zeros(x.shape) + sigma sigmay = np.sqrt(sigma**2 + np.absolute(xp) * eta) yfactor = np.exp(-0.5 * (yp**2) / (sigmay**2)) / sigmay return a / 2 / np.sqrt(np.pi) / sqrt2 / x0 * np.exp( sigma**2 / 2. / (x0**2) - xp / x0) * serfc( (sigma / x0 - xp / sigma) / sqrt2) * yfactor + b
def EMARight(x, c, xa, xc, xsc, sigmac): sqrt2 = np.sqrt(2.) if (np.absolute(xc - xa) / xa < 0.0001): xt = 0. else: xt = 1. / (1. / xc - 1. / xa) scdtm = c * xt / xc #return \ #0.5*scdtm* np.exp((xsc - x) / xa + (sigmaa ** 2) / 2. / (xa ** 2)) \ #* erfc((xsc - x) /sqrt2 / sigmaa + sigmaa /sqrt2 / xa) \ return -0.5 * scdtm * np.exp((xsc - x) / xc + (sigmac ** 2) / 2. / (xc ** 2))\ * serfc((xsc - x) /sqrt2 / sigmac + sigmac /sqrt2 / xc)
def EMAMiddle(x, c, xa, xc, xsc, sigmac): sqrt2 = np.sqrt(2.) if (np.absolute(xc - xa) / xa < 0.0001): xt = 0. else: xt = 1. / (1. / xc - 1. / xa) scdtm = c * xt / xc # print xa,xc,a,c,scdtm,fc # print (xsc - x[0]) / xa, (sigmaa ** 2) / 2. / (xa ** 2), (xsc - x[0]) / xc, (sigmac ** 2) / 2. / (xc ** 2) return 0.5 * scdtm * np.exp((xsc - x) / xa + (sigmac ** 2) / 2. / (xa ** 2)) \ * serfc((xsc - x) /sqrt2 / sigmac + sigmac /sqrt2 / xa)
def EMG(x, a, x0, xsc, sigma, b, **kwargs): sqrt2 = np.sqrt(2.) if 'Gaussian' in kwargs: return a / np.sqrt(2 * np.pi) / sigma * np.exp(-1 * (x**2) / 2 / (sigma**2)) + b # else: # efct=sigma**2/(x-xsc)/x0 # ld=a / (1 + efct) * np.exp(-1 * (x - xsc) / x0 * (1 - 0.5 * efct)) + b # ld[x<=xsc]=b # # return ld else: expterm = np.exp((xsc - x) / x0 + (sigma**2) / 2. / (x0**2)) expterm[ np.isinf(expterm) == True] = 0. #since erfc function in large exp term is very small return 0.5 * a / x0 * expterm * serfc( (xsc - x) / sqrt2 / sigma + sigma / sqrt2 / x0) + b