本文整理汇总了Python中scipy.misc.comb方法的典型用法代码示例。如果您正苦于以下问题:Python misc.comb方法的具体用法?Python misc.comb怎么用?Python misc.comb使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.misc
的用法示例。
在下文中一共展示了misc.comb方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mc2mnc
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import comb [as 别名]
def mc2mnc(mc):
'''convert central to non-central moments, uses recursive formula
optionally adjusts first moment to return mean
'''
n = len(mc)
mean = mc[0]
mc = [1] + list(mc) # add zero moment = 1
mc[1] = 0 # define central mean as zero for formula
mnc = [1, mean] # zero and first raw moments
for nn,m in enumerate(mc[2:]):
n=nn+2
mnc.append(0)
for k in range(n+1):
mnc[n] += comb(n,k,exact=1) * mc[k] * mean**(n-k)
return mnc[1:]
示例2: mnc2mc
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import comb [as 别名]
def mnc2mc(mnc, wmean = True):
'''convert non-central to central moments, uses recursive formula
optionally adjusts first moment to return mean
'''
n = len(mnc)
mean = mnc[0]
mnc = [1] + list(mnc) # add zero moment = 1
mu = [] #np.zeros(n+1)
for n,m in enumerate(mnc):
mu.append(0)
#[comb(n-1,k,exact=1) for k in range(n)]
for k in range(n+1):
mu[n] += (-1)**(n-k) * comb(n,k,exact=1) * mnc[k] * mean**(n-k)
if wmean:
mu[1] = mean
return mu[1:]
示例3: cum2mc
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import comb [as 别名]
def cum2mc(kappa):
'''convert non-central moments to cumulants
recursive formula produces as many cumulants as moments
References
----------
Kenneth Lange: Numerical Analysis for Statisticians, page 40
(http://books.google.ca/books?id=gm7kwttyRT0C&pg=PA40&lpg=PA40&dq=convert+cumulants+to+moments&source=web&ots=qyIaY6oaWH&sig=cShTDWl-YrWAzV7NlcMTRQV6y0A&hl=en&sa=X&oi=book_result&resnum=1&ct=result)
'''
mc = [1,0.0] #_kappa[0]] #insert 0-moment and mean
kappa0 = kappa[0]
kappa = [1] + list(kappa)
for nn,m in enumerate(kappa[2:]):
n = nn+2
mc.append(0)
for k in range(n-1):
mc[n] += comb(n-1,k,exact=1) * kappa[n-k]*mc[k]
mc[1] = kappa0 # insert mean as first moments by convention
return mc[1:]
示例4: cal_pvalue
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import comb [as 别名]
def cal_pvalue(c00, c11, c01, c10):
"""
c00: int, argeed number on positive
c01, c10: int, disagreed number
c11: int, agreed number on negative
return: p value
"""
b = min(c01, c10)
n = c01 + c10
p = 0
for i in range(b, n+1):
cur_p = 1
for j in range(i):
cur_p *= ((n - j) / (2.0 * (i - j)))
if not np.isinf(cur_p):# and n-i < 1000:
# print(n-i, cur_p)
for i in range(n-i):
cur_p /= 2.0
p += cur_p
# print(cur_p, p)
# p = p + comb(c01+c10, j) / denominator
# p /= (2 ** (c01 + c10 - 1))
return 2 * p
示例5: spearmans_rho
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import comb [as 别名]
def spearmans_rho(X):
"""
Calculates a generalized Spearman's rho for a data set given by X, as
described by "Multivariate Extensions of Spearman's Rho and Related Statistics"
Inputs:
X - the input data, should be a numpy array of shape = M x N, where
M is the number of samples, and N is the dimensionality of the data
"""
M = X.shape[0]
N = X.shape[1]
if N<2:
raise ValueError('To calculate Spearman\'s Rho, need data of dimensionality >= 2')
srho = 0.0
for dim1 in range(0,N-1):
for dim2 in range(dim1+1,N):
(r,p) = spearmanr(X[:,dim1],X[:,dim2])
srho = srho + r
# normalize
srho = srho / comb(N,2)
return srho
示例6: kendalls_tau
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import comb [as 别名]
def kendalls_tau(X):
"""
Calculates a generalized Kendall's tau for a data set given by X, as
described by "Multivariate Extensions of Spearman's Rho and Related Statistics"
Inputs:
X - the input data, should be a numpy array of shape = M x N, where
M is the number of samples, and N is the dimensionality of the data
"""
M = X.shape[0]
N = X.shape[1]
if N<2:
raise ValueError('To calculate Kendall\'s Tau, need data of dimensionality >= 2')
ktau = 0.0
for dim1 in range(0,N-1):
for dim2 in range(dim1+1,N):
(t,p) = kendalltau(X[:,dim1],X[:,dim2])
ktau = ktau + t
# normalize
ktau = ktau / comb(N,2)
return ktau
示例7: index
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import comb [as 别名]
def index(self, text, terms=None, **kwargs):
"""
Index all term pair distances.
Args:
text (Text): The source text.
terms (list): Terms to index.
"""
self.clear()
# By default, use all terms.
terms = terms or text.terms.keys()
pairs = combinations(terms, 2)
count = comb(len(terms), 2)
for t1, t2 in bar(pairs, expected_size=count, every=1000):
# Set the Bray-Curtis distance.
score = text.score_braycurtis(t1, t2, **kwargs)
self.set_pair(t1, t2, score)
示例8: generate_hamming_distance_payoff_distribution
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import comb [as 别名]
def generate_hamming_distance_payoff_distribution(max_sent_len, vocab_size, tau=1.):
"""compute the q distribution for Hamming Distance (substitution only) as in the RAML paper"""
probs = dict()
Z_qs = dict()
for sent_len in range(1, max_sent_len + 1):
counts = [1.] # e = 0, count = 1
for e in range(1, sent_len + 1):
# apply the rescaling trick as in https://gist.github.com/norouzi/8c4d244922fa052fa8ec18d8af52d366
count = comb(sent_len, e) * math.exp(-e / tau) * ((vocab_size - 1) ** (e - e / tau))
counts.append(count)
Z_qs[sent_len] = Z_q = sum(counts)
prob = [count / Z_q for count in counts]
probs[sent_len] = prob
# print('sent_len=%d, %s' % (sent_len, prob))
return probs, Z_qs
示例9: ab_filter_exp_cascade
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import comb [as 别名]
def ab_filter_exp_cascade(self,tau, n, step = 0.001):
""" create an ExpCascade filter and return arrays for the coefficients """
from scipy.misc import comb
tau = float(tau)
n = int(n)
if tau < 0:
raise Exception("Negative time constants are not implemented")
if n < 0:
raise Exception("Negative cascade number is not allowed")
if tau == 0:
a = np.array([1.0])
b = np.array([])
return [a,b]
tauC = tau/float(n) if n > 0 else tau
c = np.exp(-step/tauC)
N = n + 1
a = np.array([(-c)**(i)*comb(N,i) for i in range(N+1)])
b = np.array([(1.0-c)**N])
return [a,b]
示例10: mnc2cum
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import comb [as 别名]
def mnc2cum(mnc):
'''convert non-central moments to cumulants
recursive formula produces as many cumulants as moments
http://en.wikipedia.org/wiki/Cumulant#Cumulants_and_moments
'''
mnc = [1] + list(mnc)
kappa = [1]
for nn,m in enumerate(mnc[1:]):
n = nn+1
kappa.append(m)
for k in range(1,n):
kappa[n] -= comb(n-1,k-1,exact=1) * kappa[k]*mnc[n-k]
return kappa[1:]
示例11: __init__
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import comb [as 别名]
def __init__(self, n0, n1):
self.n0 = n0
self.n1 = n1
self.n = n = n0 + n1
self.comball = comb(n, n1)
示例12: runs_prob_odd
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import comb [as 别名]
def runs_prob_odd(self, r):
n0, n1 = self.n0, self.n1
k = (r+1)//2
tmp0 = comb(n0-1, k-1)
tmp1 = comb(n1-1, k-2)
tmp3 = comb(n0-1, k-2)
tmp4 = comb(n1-1, k-1)
return (tmp0 * tmp1 + tmp3 * tmp4) / self.comball
示例13: pdf
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import comb [as 别名]
def pdf(self, x, k, n, p):
'''distribution of success runs of length k or more
Parameters
----------
x : float
count of runs of length n
k : int
length of runs
n : int
total number of observations or trials
p : float
probability of success in each Bernoulli trial
Returns
-------
pdf : float
probability that x runs of length of k are observed
Notes
-----
not yet vectorized
References
----------
Muselli 1996, theorem 3
'''
q = 1-p
m = np.arange(x, (n+1)//(k+1)+1)[:,None]
terms = (-1)**(m-x) * comb(m, x) * p**(m*k) * q**(m-1) \
* (comb(n - m*k, m - 1) + q * comb(n - m*k, m))
return terms.sum(0)
示例14: _munp
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import comb [as 别名]
def _munp(self, n, c):
k = np.arange(0,n+1)
val = (1.0/c)**n * np.sum(comb(n,k)*(-1)**k / (1.0+c*k),axis=0)
return where(c*n > -1, val, inf)
示例15: lp2bp
# 需要导入模块: from scipy import misc [as 别名]
# 或者: from scipy.misc import comb [as 别名]
def lp2bp(b, a, wo=1.0, bw=1.0):
"""
Transform a lowpass filter prototype to a bandpass filter.
Return an analog band-pass filter with center frequency `wo` and
bandwidth `bw` from an analog low-pass filter prototype with unity
cutoff frequency, in transfer function ('ba') representation.
"""
a, b = map(atleast_1d, (a, b))
D = len(a) - 1
N = len(b) - 1
artype = mintypecode((a, b))
ma = max([N, D])
Np = N + ma
Dp = D + ma
bprime = numpy.zeros(Np + 1, artype)
aprime = numpy.zeros(Dp + 1, artype)
wosq = wo * wo
for j in range(Np + 1):
val = 0.0
for i in range(0, N + 1):
for k in range(0, i + 1):
if ma - i + 2 * k == j:
val += comb(i, k) * b[N - i] * (wosq) ** (i - k) / bw ** i
bprime[Np - j] = val
for j in range(Dp + 1):
val = 0.0
for i in range(0, D + 1):
for k in range(0, i + 1):
if ma - i + 2 * k == j:
val += comb(i, k) * a[D - i] * (wosq) ** (i - k) / bw ** i
aprime[Dp - j] = val
return normalize(bprime, aprime)