本文整理汇总了Python中numpy.piecewise函数的典型用法代码示例。如果您正苦于以下问题:Python piecewise函数的具体用法?Python piecewise怎么用?Python piecewise使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了piecewise函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _arc_cosine_hypothesis_test
def _arc_cosine_hypothesis_test(ac_output, X, W, b, s):
"""
Runs hypothesis test for Arc Cosine layer.
Inputs:
ac_output -- output of net after running arc cosine layer
X -- input data
W -- weight parameter from train_init_net
b -- bias parameter from train_init_net
s -- degree parameter
"""
# Get output from net
net_output = workspace.FetchBlob(ac_output)
# Computing output directly
x_rand = np.matmul(X, np.transpose(W)) + b
x_pow = np.power(x_rand, s)
if s > 0:
h_rand_features = np.piecewise(x_rand,
[x_rand <= 0, x_rand > 0],
[0, 1])
else:
h_rand_features = np.piecewise(x_rand,
[x_rand <= 0, x_rand > 0],
[0, lambda x: x / (1 + x)])
output_ref = np.multiply(x_pow, h_rand_features)
# Comparing net output and computed output
npt.assert_allclose(net_output, output_ref, rtol=1e-3, atol=1e-3)
开发者ID:Sissipei,项目名称:caffe2,代码行数:29,代码来源:layers_test.py
示例2: EpEvo
def EpEvo(t,eta,j,Gamma0,q):
#
# For now I'm going to set a few params at good values
# Adjust later
z=2.332
#q=power(10.,q)
#q=1.E-3
#E0 = 1.E54
E0 = 1.97E55
#E0 = power(10.,E0)
g = (j+1.-eta)*0.5
n0 = 1.E2
#xd = ((3.-eta)*E0 / ( 4.*pi*n0*Gamma0**2. * mp ) )**(1./3.)
xd = 1.8E16*((1.+j-eta)*(E0/1.E54)/((n0/100.)*(Gamma0/300.)))**(1./3.)
#td = (1.+z)*xd / (Gamma0**2. * c)
td = 6.7*(1.+z)*((1.+j-eta)*(E0/1.E54)/((n0/100.)*(Gamma0/300.)**8.))**(1./3.)
### Calculate X(t) ###
test = td/(2. * g + 1.) *( Gamma0**(2.+1./g) + 2.*g)
condition1 = t<td
condition2 = logical_and(td<=t, t<=test)
X = piecewise(t, [condition1, condition2],\
[lambda t: t/td, \
lambda t: ((2.*g+1.)*(t/td) - 2.*g)**(1./(2.*g+1.)) ])
### Calculate X(t) ###
### Calculate Gamma(X) ###
condition3 = X<1.
condition4 = logical_and(1.<=X, X<=Gamma0**(1./g))
Gamma = piecewise(X, [condition3, condition4],\
[lambda X: Gamma0, \
lambda X: Gamma0*X**(-g) ])
### Calculate Gamma(X) ###
eE0 = 3.E-8 * (1E-3) * n0**(.5)*q*Gamma0**4. /(1.+z)
result = 511.8 * eE0*(Gamma/Gamma0)**4. * (X)**(-eta/2.)
return result
开发者ID:drJfunk,项目名称:mnEpFit,代码行数:60,代码来源:extShock_adi.py
示例3: makewdnoise
def makewdnoise(f,wdstyle,obs='X'):
if wdstyle == 'mldc':
x = 2.0 * math.pi * model.lisaL * f
t = 4 * x**2 * N.sin(x)**2 * (1.0 if obs == 'X' else 1.5)
return t * ( N.piecewise(f,(f >= 1.0e-4 ) & (f < 1.0e-3 ),[lambda f: 10**-44.62 * f**-2.3, 0]) + \
N.piecewise(f,(f >= 1.0e-3 ) & (f < 10**-2.7),[lambda f: 10**-50.92 * f**-4.4, 0]) + \
N.piecewise(f,(f >= 10**-2.7) & (f < 10**-2.4),[lambda f: 10**-62.8 * f**-8.8, 0]) + \
N.piecewise(f,(f >= 10**-2.4) & (f < 10**-2.0),[lambda f: 10**-89.68 * f**-20.0,0]) )
elif wdstyle in wdnoise:
mod, p = wdnoise[wdstyle]
p = p[0] if obs == 'X' else p[1] # assume AE if not X
y = N.log10(f)
if mod == 'rat42':
return 10.0**( (p[0]*y**4+p[1]*y**3+p[2]*y**2+p[3]*y+p[4])/(y**2+p[5]*y+p[6]) )
elif mod == 'poly4':
return 10.0**( p[0]*y**4+p[1]*y**3+p[2]*y**2+p[3]*y+p[4] )
else:
raise NotImplementedError
else:
if '.txt' in wdstyle:
conf = N.loadtxt(wdstyle)
conf[N.isnan(conf[:,1]),1] = 0
return N.interp(f,conf[:,0],conf[:,1])
else:
raise NotImplementedError
开发者ID:LiberTang0,项目名称:lisasolve,代码行数:28,代码来源:tdi.py
示例4: EpEvo
def EpEvo(t,eta,g,Gamma0,q):
#
# For now I'm going to set a few params at good values
# Adjust later
z=2.332
# q=1.E-4
# q=1E-3
E0 = 9.1E53
n0 = 1.E2
#n0 = power(10,n0)
#xd = ((3.-eta)*E0 / ( 4.*pi*n0*Gamma0**2. * mp ) )**(1./3.)
xd = 2.6E16*((1.-eta/3.)*(E0/1.E54)/((n0/100.)*(Gamma0/300.)))**(1./3.)
#td = (1.+z)*xd / (Gamma0**2. * c)
td = 9.7*(1.+z)*((1.-eta/3.)*(E0/1.E54)/((n0/100.)*(Gamma0/300.)**8.))**(1./3.)
### Calculate X(t) ###
test = td/(2. * g + 1.) *( Gamma0**(2.+1./g) + 2.*g)
#frac = t/td
condition1 = t<td
condition2 = logical_and(td<=t, t<=test)
X = piecewise(t, [condition1, condition2],\
[lambda t: t/td, \
lambda t: ((2.*g+1.)*(t/td) - 2.*g)**(1./(2.*g+1.)) ])
### Calculate X(t) ###
### Calculate Gamma(X) ###
condition3 = X<1.
condition4 = logical_and(1.<=X, X<=Gamma0**(1./g))
Gamma = piecewise(X, [condition3, condition4],\
[lambda X: Gamma0, \
lambda X: Gamma0*X**(-g) ])
### Calculate Gamma(X) ###
eE0 = 3.E-8 * (1E-3) * n0**(.5)*q *Gamma0**4. /(1.+z)
# eE0 = 3.E-8 * n0**(.5)*q*Gamma0**4. /(1.+z)
return 511. * eE0*(Gamma/Gamma0)**4. * (X/xd)**(-eta/2.)
开发者ID:drJfunk,项目名称:mnEpFit,代码行数:59,代码来源:extShock_mulit.py
示例5: __init__
def __init__(self, Ymax, Y0, mumax, lag, x):
# x is x data
a1 = np.piecewise(x, [x < lag, x >= lag], [0.0, 1.0])
tc = (Ymax-Y0)/mumax+lag
a2 = np.piecewise(x, [x < tc, x >= tc], [0.0, 1.0])
self.Buchanan = Y0*(1.0-a1)+(Y0 + mumax*(x-lag))*a1*(1.0-a2) + Ymax*a2
print x, self.Buchanan
开发者ID:csivilo,项目名称:IPMP,代码行数:9,代码来源:BuchananFunc.py
示例6: _get_solution
def _get_solution(self):
"""Get the solution from the solver output
Fills the dictionary self.sol with the information:
* 's': The optimal s as a function of time
* 't': The time vector
* 'states': Numerical values of the states defined in self.sys
TODO: perform accurate integration to determine time
TODO: Do exact interpolation
"""
solver = self.prob['solver']
N = self.options['N']
x_opt = np.array(solver.getOutput("x")).ravel()
b_opt = np.reshape(x_opt, (N + 1, -1), order='F')
self.sol['b'] = b_opt
# Determine time on a sufficiently fine spatial grid
s0 = np.linspace(0, 1, 1001)
delta = s0[1] - s0[0]
pieces = [lambda s, b=b_opt, ss=ss, j=j:
sum([bb * (s - ss) ** i / fact[i]
for i, bb in enumerate(b[j])])
for j, ss in enumerate(self.prob['s'][:-1])]
conds = lambda s0: [np.logical_and(self.prob['s'][i] <= s0,
s0 <= self.prob['s'][i+1])
for i in range(N)]
b0_opt = np.piecewise(s0, conds(s0), pieces)
b0_opt[b0_opt < 0] = 0
time = np.cumsum(np.hstack([0, 2 * delta / (np.sqrt(b0_opt[:-1]) +
np.sqrt(b0_opt[1:]))]))
# Resample to constant time-grid
t = np.arange(time[0], time[-1], self.options['Ts'])
st = np.interp(t, time, s0)
# Evaluate solution on equidistant time grid
b_opt = np.c_[[np.piecewise(st, conds(st), pieces, b=b_opt[:, i:])
for i in range(self.sys.order)]].T
st = np.matrix(st)
# Determine s and derivatives from b_opt
b, Ds = self._make_path()[1:]
Ds_f = cas.SXFunction([b], [Ds]) # derivatives of s wrt b
Ds_f.init()
s_opt = np.hstack((st.T, np.array([evalf(Ds_f, bb).toArray().ravel()
for bb in b_opt])))
self.sol['s'] = np.asarray(s_opt)
self.sol['t'] = t
# Evaluate the states
f = cas.SXFunction([self.s], [cas.substitute(cas.vertcat(self.sys.x.values()),
self.sys.y, self.path)])
f_val = np.array([evalf(f, s.T).toArray().ravel() for s in s_opt])
self.sol['states'] = dict([(k, f_val[:, i]) for i, k in
enumerate(self.sys.x.keys())])
开发者ID:wannesvl,项目名称:topaf,代码行数:55,代码来源:pathfollowing.py
示例7: I
def I(w, wa, wb, wc):
wa,wb,wc = float(wa), float(wb), float(wc)
f = (wb - wa) / (wc - wa)
eps = (wc-wa)/1e3
if (wb-wa)>eps and (wc-wb)>eps:
w1 = wa+eps
w2 = wb-eps
w3 = wc-eps
return np.piecewise(w,
[(w <= wa-eps),
(wa-eps < w) & (w <= wa+eps),
(wa+eps < w) & (w < wb-eps),
(wb-eps <= w) & (w <= wb+eps),
(wb+eps < w) & (w < wc-eps),
(wc-eps <= w) & (w < wc+eps),
(wc+eps <= w)],
[0,
4/np.sqrt(f*(1-((w1 - wa) / (wc - wa)))) * K([(1-f)*((w1 - wa) / (wc - wa)) / (f*(1-((w1 - wa) / (wc - wa))))]),
lambda w: 4/np.sqrt(f*(1-((w - wa) / (wc - wa)))) * K((1-f)*((w - wa) / (wc - wa)) / (f*(1-((w - wa) / (wc - wa))))),
4/np.sqrt(f*(1-((w2 - wa) / (wc - wa)))) * K([(1-f)*((w2 - wa) / (wc - wa)) / (f*(1-((w2 - wa) / (wc - wa))))]),
lambda w: 4/np.sqrt(((w - wa) / (wc - wa))*(1-f)) * K((1-((w - wa) / (wc - wa)))*f / (((w - wa) / (wc - wa))*(1-f))),
4/np.sqrt(((w3 - wa) / (wc - wa))*(1-f)) * K([(1-((w3 - wa) / (wc - wa)))*f / (((w3 - wa) / (wc - wa))*(1-f))]),
0])
elif (wb-wa)<=eps:
w2 = wb+eps
w3 = wc-eps
return np.piecewise(w,
[(w <= wa-eps),
(wa-eps < w) & (w <= wb+eps),
(wb+eps < w) & (w < wc-eps),
(wc-eps <= w) & (w < wc+eps),
(wc+eps <= w)],
[0,
4/np.sqrt(((w2 - wa) / (wc - wa))*(1-f)) * K([(1-((w2 - wa) / (wc - wa)))*f / (((w2 - wa) / (wc - wa))*(1-f))]),
lambda w: 4/np.sqrt(((w - wa) / (wc - wa))*(1-f)) * K((1-((w - wa) / (wc - wa)))*f / (((w - wa) / (wc - wa))*(1-f))),
4/np.sqrt(((w3 - wa) / (wc - wa))*(1-f)) * K([(1-((w3 - wa) / (wc - wa)))*f / (((w3 - wa) / (wc - wa))*(1-f))]),
0])
elif (wc-wb)<=eps:
w1 = wa+eps
w2 = wb-eps
return np.piecewise(w,
[(w <= wa-eps),
(wa-eps < w) & (w <= wa+eps),
(wa+eps < w) & (w < wb-eps),
(wb-eps <= w) & (w <= wc+eps),
(wc+eps <= w)],
[0,
4/np.sqrt(f*(1-((w1 - wa) / (wc - wa)))) * K([(1-f)*((w1 - wa) / (wc - wa)) / (f*(1-((w1 - wa) / (wc - wa))))]),
lambda w: 4/np.sqrt(f*(1-((w - wa) / (wc - wa)))) * K((1-f)*((w - wa) / (wc - wa)) / (f*(1-((w - wa) / (wc - wa))))),
4/np.sqrt(f*(1-((w2 - wa) / (wc - wa)))) * K([(1-f)*((w2 - wa) / (wc - wa)) / (f*(1-((w2 - wa) / (wc - wa))))]),
0])
开发者ID:marirb,项目名称:useful_stuff,代码行数:51,代码来源:fitting_functions.py
示例8: EpEvo
def EpEvo(t,A,eta,g,E0,Gamma0,n0,q):
#c = 2.99E10 #cm/s
c=1.
mp = 1.67E-26 # keV ??
z=1.
#q=1.E-3
#Gamma0 = 300.
#g = (3.-eta)/2.
#n0 = 1.E2
#xd = ((3.-eta)*E0 / ( 4.*pi*n0*Gamma0**2. * mp ) )**(1./3.)
xd = 2.6E16*((1.-eta/3.)*(E0/1.E54)/((n0/100.)*(Gamma0/300.)))**(1./3.)
#td = (1.+z)*xd / (Gamma0**2. * c)
td = 9.7*(1.+z)*((1.-eta/3.)*(E0/1.E54)/((n0/100.)*(Gamma0/300.)**8.))**(1./3.)
### Calculate X(t) ###
test = (td/(2. * g + 1.) * Gamma0**(2.+1./g) + 2.*g)
#frac = t/td
condition1 = t<td
condition2 = logical_and(td<=t, t<=test)
X = piecewise(t, [condition1, condition2],\
[lambda t: t/td, \
lambda t: ((2.*g+1.)*(t/td) - 2.*g)**(1./(2.*g+1.)) ])
### Calculate X(t) ###
### Calculate Gamma(X) ###
condition3 = X<1.
condition4 = logical_and(1.<=X, X<=Gamma0**(1./g))
Gamma = piecewise(X, [condition3, condition4],\
[lambda X: Gamma0, \
lambda X: Gamma0*X**(-g) ])
### Calculate Gamma(X) ###
eE0 = 3.E-8 * n0**(.5)*q*Gamma0**4. /(1.+z)
return A*eE0*(Gamma/Gamma0)**4. * (X/xd)**(-eta/2.)
开发者ID:JohannesBuchner,项目名称:spectralTools,代码行数:51,代码来源:functions.py
示例9: _evaluate
def _evaluate(self, t):
if self.direction == 1:
kernel = np.piecewise(
t, [t < 0, t >= 0], [
lambda t: 0,
lambda t: (1.0 / self._sigma_scaled.magnitude) * np.exp(
(-t / self._sigma_scaled).magnitude)]) / t.units
elif self.direction == -1:
kernel = np.piecewise(
t, [t < 0, t >= 0], [
lambda t: (1.0 / self._sigma_scaled.magnitude) * np.exp(
(t / self._sigma_scaled).magnitude),
lambda t: 0]) / t.units
return kernel
开发者ID:INM-6,项目名称:elephant-cs16,代码行数:14,代码来源:kernels.py
示例10: loadExampleData
def loadExampleData():
data = pd.DataFrame({'Seconds': np.arange(0,15,1/200)})
t = data.loc[:,'Seconds'].values
data.loc[:,'T ACP'] = \
np.piecewise(t, [t < 4, 4 <= t], [1,0]) * (1800/4*t) + \
np.piecewise(t, [t < 4,(4<=t)*(t<=12)], [0,1]) * (1800 + (1200-1800)/8*(t-4)) + \
np.piecewise(t, [12 < t, 20 < t], [1,0]) * (1500 + -400/8*(t-12))
data.loc[:,'time'] = t
self.data = data
self.initExampleData()
self.camera = 'rad'
self.times = [4,7,12]
开发者ID:stephanGit,项目名称:eml,代码行数:14,代码来源:cameraData.py
示例11: phi
def phi(xs, Z):
"""Evaluate phi(x) on a numpy list.
This uses invibro.phi.phi0_cache to interpolate values."""
Z0, x_bound = phi0_cache['Z0'], phi0_cache['xs'][0]
c1 = pi ** 2 /6; c2 = 7 * pi ** 4 / 60.0
neg = lambda x: log((Z - x) / (Z + x))
interp = lambda x: phi0_cache['interp'](x) + log((Z + x) / (Z0 + x))
large = lambda x: log(1 + Z / x) + c1 / x ** 2 + c2 / x ** 4
return (
piecewise(xs, [xs < 0], [neg, 0.0]) +
piecewise(abs(xs), [abs(xs) < x_bound], [interp, large]) +
complex(0, -0.5) * n(xs)
)
开发者ID:drostie,项目名称:invibro,代码行数:14,代码来源:make_phi.py
示例12: reposition
def reposition(coords, box_size):
com = compute_com_pbc(coords, box_size)
cob = box_size / 2.0
coords_recenter = coords - com + cob
coords_recenter_x = coords_recenter[:,0]
coords_recenter_y = coords_recenter[:,1]
coords_recenter_z = coords_recenter[:,2]
#print coords_recenter
coords_recenter_x = np.piecewise(coords_recenter_x, [coords_recenter_x < 0.0, (coords_recenter_x >= 0.0) * (coords_recenter_x <= box_size[0]), coords_recenter_x > box_size[0]], \
[lambda coords_recenter_x: coords_recenter_x + box_size[0], lambda coords_recenter_x: coords_recenter_x, lambda coords_recenter_x: coords_recenter_x - box_size[0]])
coords_recenter_y = np.piecewise(coords_recenter_y, [coords_recenter_y < 0.0, (coords_recenter_y >= 0.0) * (coords_recenter_y <= box_size[1]), coords_recenter_y > box_size[1]], \
[lambda coords_recenter_y: coords_recenter_y + box_size[1], lambda coords_recenter_y: coords_recenter_y, lambda coords_recenter_y: coords_recenter_y - box_size[1]])
coords_recenter_z = np.piecewise(coords_recenter_z, [coords_recenter_z < 0.0, (coords_recenter_z >= 0.0) * (coords_recenter_z <= box_size[2]), coords_recenter_z > box_size[2]], \
[lambda coords_recenter_z: coords_recenter_z + box_size[2], lambda coords_recenter_z: coords_recenter_z, lambda coords_recenter_z: coords_recenter_z - box_size[2]])
return np.array(zip(coords_recenter_x,coords_recenter_y,coords_recenter_z))
开发者ID:anyuzx,项目名称:toolbox,代码行数:15,代码来源:recenter_dump.py
示例13: I_axial
def I_axial(w, wa, wc):
if wc > wa:
return np.piecewise(w, [(w <= wa),
(wa < w) & (w < wc),
(wc <= w)],
[0,
lambda w: 1 / (2*np.sqrt((w - wa) / (wc - wa))),
0])
elif wa > wc:
return np.piecewise(w, [(w <= wc),
(wc < w) & (w < wa),
(wa <= w)],
[0,
lambda w: 1 / (2*np.sqrt((w - wa) / (wc - wa))),
0])
开发者ID:marirb,项目名称:useful_stuff,代码行数:15,代码来源:fitting_functions.py
示例14: f
def f(x, a1, b1, c1, d1, b2, c2, v0):
a2_calculated = a2(a1, b1, c1, d1, b2, c2, v0)
d2_calculated = d2(a1, b1, c1, d1, b2, c2, v0)
return np.piecewise(
x,
[x < v0, x >= v0],
[lambda x: p(x, a1, b1, c1, d1), lambda x: p(x, a2_calculated, b2, c2, d2_calculated)])
开发者ID:Pitt-RAS,项目名称:micromouse,代码行数:7,代码来源:fit.py
示例15: intgl_simp38
def intgl_simp38(f,a,b,steps=-1,h=1):
if steps>0:
xis = np.linspace(a,b,steps+1)
h = xis[1]-xis[0]
fxis = f(xis)
wis = np.zeros(steps+1)
pcs = []; fpcs = []
for i in xrange(0,steps-2,3):
wis[i:i+4] += [1,3,3,1]
pcs.append(xis[i:i+4])
fpcs.append(fxis[i:i+4])
wis *= 3*h/8
if steps%3==2:
wis[-3:] += [h/3,4*h/3,h/3]
pcs.append(xis[-3:])
fpcs.append(fxis[-3:])
elif steps%3==1:
wis[-2:] += [h/2,h/2]
pcs.append(xis[-2:])
fpcs.append(fxis[-2:])
fapprox = lambda x: np.piecewise(x,
[np.logical_and(p[0]<=x,x<=p[-1]) for p in pcs],
[lagrange(pcs[i],fpcs[i]) for i in xrange(len(pcs))])# np.interp(x,xis,fxis)
# fapprox = lambda x: np.interp(x,xis,fxis)
return (sum(fxis*wis),xis,fxis,wis,fapprox) # h/2 * sum(np.array([f(x) for x in xs]) * np.array([1]+[2]*(len(xs)-2)+[1]))
开发者ID:AjinkyaDahale,项目名称:AML702_Prog_Assgn,代码行数:25,代码来源:numintegrals.py
示例16: fermi_poly2
def fermi_poly2(x):
"""fermi_poly2(x), equal to -Li_2(-e^x)"""
def f0(x):
return np.exp(x)
def f1(x):
ex = np.exp(x)
return (1.+( -0.25+( 0.111111+( -0.0625+( 0.04+( -0.0277778+( 0.0204082+( -0.015625+( 0.0123457+( -0.01+( 0.00826446+( -0.00694444+( 0.00591716+( -0.00510204+( 0.00444444+( -0.00390625+( 0.00346021+( -0.00308642+( 0.00277008+ -0.0025*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex
def f2(x):
ex = x**2
return 0.822467+(0.6931471805599453+( 0.25+( 0.04166666666666666+( -0.0010416666666666534+( 0.00004960317460316857+( -2.927965167558005e-6+(1.9415383998507108e-7+( -1.3870999148454729e-8+(1.0440288911003276e-9+(-8.167040926799743e-11+6.5806618711692295e-12*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*x)*x)*x
def f3(x):
ex = np.exp(-x)
return 1.6449340668482262 + 0.5*x**2 - (1.+( -0.25+( 0.111111+( -0.0625+( 0.04+( -0.0277778+( 0.0204082+( -0.015625+( 0.0123457+( -0.01+( 0.00826446+( -0.00694444+( 0.00591716+( -0.00510204+( 0.00444444+( -0.00390625+( 0.00346021+( -0.00308642+( 0.00277008 -0.0025*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex
def f4(x):
return 1.6449340668482262 + 0.5*x**2
# fix for bug in piecewise, fixed in more recent numpy
if np.isscalar(x):
x = np.array([x], dtype=float)
# define piecewise function and evaluate
ans = np.piecewise(x, [x<=-20, np.logical_and(x>-20, x<=-1), \
np.logical_and(x>-1, x<=1), np.logical_and(x>1, x<=20)],\
[f0, f1, f2, f3, f4])
return ans
开发者ID:MaxParsons,项目名称:amo-physics,代码行数:27,代码来源:polylog.py
示例17: fermi_poly5half
def fermi_poly5half(x):
"""fermi_poly5half(x), equal to -Li_{5/2}(-e^x)
FAILS TESTS (COMPARING TO LERCH), DO NOT USE WITHOUT INVESTIGATING MORE
"""
def f0(x):
return np.exp(x)
def f1(x):
ex = np.exp(x)
return (1 + (-0.17677669529663687 + (0.06415002990995843 - (0.03125 + (0.01788854381999832 - (0.011340230290662863 + (0.007713560673657698 - (0.005524271728019902 + (0.00411522633744856 - 0.0031622776601683794*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex)*ex
def f2(x):
res = (7.999472242952045e-8 + (2.015789875039643e-8 + (-5.182488893752819e-9 + (-1.3550552937770878e-9 + (3.5944104666022113e-10 + (9.653703483078106e-11 + (-2.6209625544677692e-11 + (-7.185930974961928e-12 + (1.9812061650792594e-12 + 5.447084984800099e-13*x)*x)*x)*x)*x)*x)*x)*x)*x)*x
return 0.8671998890121841+(0.7651470246254081+(0.30244932171081546+(0.06335080210161399+(0.0049450362799933825+(-0.0007320093393446121+(-0.00013339945006254949 + (0.000027147085179903566+(5.930588304137955e-6+(-1.3626304577484817e-6 + (-3.252451788607287e-7 + res*x)*x)*x)*x)*x)*x)*x)*x)*x)*x)*x
def f3(x):
res = 5.992860912139351e-7 + (-6.083668666935579e-8 + (5.041252634789406e-9 + (-3.386896134140133e-10 + (1.8196669171414837e-11 + (-7.642990316874879e-13 + (2.4202106712129105e-14 + (-5.437364923509245e-16 + (7.72925401611516e-18 -5.228771407811986e-20*x)*x)*x)*x)*x)*x)*x)*x)*x
return 0.869416215427492 + (0.7603408345815055 + (0.30606614629176887 + (0.06361411550944529 + (0.002145410757189772 + (0.002020072416997651 + (-0.0017045762862650151 + (0.0006382881546811445 + (- 0.00016246851298525836 + (0.00003140383144730955 + (-4.819813947314412e-6+res*x)*x)*x)*x)*x)*x)*x)*x)*x)*x)*x
def f4(x):
x2 = x**2
invex = np.sqrt(x)
return (-2.0851412241155116/x/x - 0.5343060576801043)/x/invex + 1.8561093322772355*invex + 0.30090111122547003*x2*invex
def f5(x):
x2 = x**2
invex = np.sqrt(x)
return 1.8561093322772355*invex + 0.30090111122547003*x2*invex
# fix for bug in piecewise, fixed in more recent numpy
if np.isscalar(x):
x = np.array([x], dtype=float)
# define piecewise function and evaluate
ans = np.piecewise(x, [x<=-20, np.logical_and(x>-20, x<=-2), \
np.logical_and(x>-2, x<=2), np.logical_and(x>2, x<=12), \
np.logical_and(x>12, x<=20)], [f0, f1, f2, f3, f4, f5])
return ans
开发者ID:MaxParsons,项目名称:amo-physics,代码行数:33,代码来源:polylog.py
示例18: fermi_poly3
def fermi_poly3(x):
"""fermi_poly3(x), equal to -Li_3(-e^x)"""
def f0(x):
return np.exp(x)
def f1(x):
ex = np.exp(x)
return (1 + (-0.125 + (0.037037037037037035 + (-0.015625 + (0.008 - 0.004629629629629629*ex)*ex)*ex)*ex)*ex)*ex
def f2(x):
x2 = x**2
return 0.9015426773696955 + (0.8224670334241131 + (0.34657359027997264 + (0.08333333333333333 + (0.010416666666666666 +(-0.00017361111111111112 + (6.200396825396825e-6 +(-2.927965167548501e-7 + (1.6179486665597777e-8 + (-9.90785651003905e-10 + (6.525181428041877e-11 +(-4.5372283133067906e-12 + 3.290608283068484e-13*x2)*x2)*x2)*x2)*x2)*x2)*x2)*x2)*x)*x)*x)*x
def f3(x):
invex = np.exp(-x)
return (((((0.008*invex - 0.015625)*invex + 0.037037037037037035)*invex) - 0.125)*invex + 1)*invex + 1.6449340668482262*x + 0.16666666666666666*x**3
def f4(x):
return 1.6449340668482262*x + 0.16666666666666666*x**3
# fix for bug in piecewise, fixed in more recent numpy
if np.isscalar(x):
x = np.array([x], dtype=float)
# define piecewise function and evaluate
ans = np.piecewise(x, [x<=-20, np.logical_and(x>-20, x<=-2), \
np.logical_and(x>-2, x<=2), np.logical_and(x>2, x<=20)],\
[f0, f1, f2, f3, f4])
return ans
开发者ID:MaxParsons,项目名称:amo-physics,代码行数:25,代码来源:polylog.py
示例19: _ale
def _ale(self):
"""ale algorithm in SubSection 3.1 of the paper.
Basically just the implementation of the following formula:
In_prime = f(In, z)
Calculates In and z, then return In_prime
:return In_prime:
"""
# Calculate In
In = self.img_gray / 255.0 # 2d array, equation 2
# Calculate z
cdf = cv2.calcHist([self.img_gray], [0], None, [256], [0, 256]).cumsum()
L = np.searchsorted(cdf, 0.1 * self.img_gray.shape[0] * self.img_gray.shape[1], side='right')
L_as_array = np.array([L]) # L as array, for np.piecewise
z_as_array = np.piecewise(L_as_array,
[L_as_array <= 50,
50 < L_as_array <= 150,
L_as_array > 150
],
[0, (L-50) / 100.0, 1]
)
z = z_as_array[0] # take the value out of array
self.z = z
# Result In_prime = f(In, z)
In_prime = 0.5 * (In**(0.75*z+0.25) + (1-In)*0.4*(1-z) + In**(2-z))
return In_prime
开发者ID:shiruilu,项目名称:AINDANE,代码行数:31,代码来源:aindane.py
示例20: de_sitter_form_testing
def de_sitter_form_testing(x,s,A,C,N3,num_slices):
"""
The functional form for de Sitter Space. x is position, s, A, C
are all fit parameters. N3 is the total number of 3-simplices in
the spacetime. num_slices is the number of time slices in the spacetime.
"""
# A normalized cosine. used for clarity.
n_cos = lambda y: np.cos(y/(s * N3**(1/3.)))
# The full width/half-max of the spacetime
fwhm = np.arccos(np.sqrt((np.pi * A/2.)*(s * N3**(1/3.)/N3)))
# The conditional functions
# for -num_slices/2.0 <= (x - C) < -s * N3**(1/3.) * fwhm
# or
# s * N3**(1/3.) * fwhm < (x-C) <= num_slices/2.0
stem = lambda x: float(A)
# for -s * N3**(1/3.) * fwhm <= (x - C) <= s * N3**(1/3.) * fwhm
bulk = lambda x: (2/np.pi) * (N3/(s * N3**(1/3.))) * n_cos(x-C)**2
# List of conditions for the piecewise function
conds = [(-num_slices/2.0 <= (x-C))&((x-C) < -s * N3**(1/3.) * fwhm),
(-s * N3**(1/3.) * fwhm <= (x-C))&((x-C) <= s * N3**(1/3.) * fwhm),
(s * N3**(1/3.) * fwhm < (x-C))&((x-C) <= num_slices/2.0)]
# List of return functions for the piecewise function
returnfuncs = [stem,bulk,stem]
return np.piecewise(x,conds,returnfuncs)
开发者ID:raylee,项目名称:CDT,代码行数:29,代码来源:average_ensemble.py
注:本文中的numpy.piecewise函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论