本文整理汇总了Python中scipy.stats.poisson.pmf方法的典型用法代码示例。如果您正苦于以下问题:Python poisson.pmf方法的具体用法?Python poisson.pmf怎么用?Python poisson.pmf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.stats.poisson
的用法示例。
在下文中一共展示了poisson.pmf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_with_noise_coherent
# 需要导入模块: from scipy.stats import poisson [as 别名]
# 或者: from scipy.stats.poisson import pmf [as 别名]
def test_update_with_noise_coherent(num_modes, parallel, monkeypatch):
""" Test that adding noise on coherent states gives the same probabilities at some other coherent states"""
if parallel: # set single-thread use in OpenMP
monkeypatch.setenv("OMP_NUM_THREADS", "1")
cutoff = 15
nbar_vals = np.random.rand(num_modes)
noise_dists = np.array([poisson.pmf(np.arange(cutoff), nbar) for nbar in nbar_vals])
hbar = 2
beta = np.random.rand(num_modes) + 1j * np.random.rand(num_modes)
means = Means(np.concatenate((beta, beta.conj())), hbar=hbar)
cov = hbar * np.identity(2 * num_modes) / 2
cutoff = 10
probs = probabilities(means, cov, cutoff, parallel=parallel, hbar=2)
updated_probs = update_probabilities_with_noise(noise_dists, probs)
beta_expected = np.sqrt(nbar_vals + np.abs(beta) ** 2)
means_expected = Means(
np.concatenate((beta_expected, beta_expected.conj())), hbar=hbar
)
expected = probabilities(means_expected, cov, cutoff, parallel=parallel, hbar=2)
assert np.allclose(updated_probs, expected)
示例2: test_update_with_noise_coherent_value_error
# 需要导入模块: from scipy.stats import poisson [as 别名]
# 或者: from scipy.stats.poisson import pmf [as 别名]
def test_update_with_noise_coherent_value_error():
"""Tests the correct error is raised"""
cutoff = 15
num_modes = 3
nbar_vals = np.random.rand(num_modes - 1)
noise_dists = np.array([poisson.pmf(np.arange(cutoff), nbar) for nbar in nbar_vals])
hbar = 2
beta = np.random.rand(num_modes) + 1j * np.random.rand(num_modes)
means = Means(np.concatenate((beta, beta.conj())), hbar=hbar)
cov = hbar * np.identity(2 * num_modes) / 2
cutoff = 10
probs = probabilities(means, cov, cutoff, hbar=2)
with pytest.raises(
ValueError,
match="The list of probability distributions probs_noise and the tensor of probabilities probs have incompatible dimensions.",
):
update_probabilities_with_noise(noise_dists, probs)
示例3: compute_window_score
# 需要导入模块: from scipy.stats import poisson [as 别名]
# 或者: from scipy.stats.poisson import pmf [as 别名]
def compute_window_score(i, poisson_parameter):
# type: (int, float) -> float
# No enrichment; poisson param also average
if i < poisson_parameter:
return 0
p_value = poisson.pmf(i, poisson_parameter)
if p_value > 0:
window_score = -log(p_value)
else:
# log of zero not defined
window_score = 1000
return window_score
示例4: compute_enriched_threshold
# 需要导入模块: from scipy.stats import poisson [as 别名]
# 或者: from scipy.stats.poisson import pmf [as 别名]
def compute_enriched_threshold(average_window_readcount):
# type: (float) -> int
"""
Computes the minimum number of tags required in window for an island to be enriched.
"""
current_threshold, survival_function = 0, 1
for current_threshold in count(start=0, step=1):
survival_function -= poisson.pmf(current_threshold,
average_window_readcount)
if survival_function <= WINDOW_P_VALUE:
break
island_enriched_threshold = current_threshold + 1
return island_enriched_threshold
示例5: poisson_probability
# 需要导入模块: from scipy.stats import poisson [as 别名]
# 或者: from scipy.stats.poisson import pmf [as 别名]
def poisson_probability(n, lam):
global poisson_cache
key = n * 10 + lam
if key not in poisson_cache:
poisson_cache[key] = poisson.pmf(n, lam)
return poisson_cache[key]
示例6: test_pmf_p1
# 需要导入模块: from scipy.stats import poisson [as 别名]
# 或者: from scipy.stats.poisson import pmf [as 别名]
def test_pmf_p1(self):
poisson_pmf = poisson.pmf(1, 1)
genpoisson_pmf = sm.distributions.genpoisson_p.pmf(1, 1, 0, 1)
assert_allclose(poisson_pmf, genpoisson_pmf, rtol=1e-15)
示例7: test_pmf_p2
# 需要导入模块: from scipy.stats import poisson [as 别名]
# 或者: from scipy.stats.poisson import pmf [as 别名]
def test_pmf_p2(self):
poisson_pmf = poisson.pmf(2, 2)
genpoisson_pmf = sm.distributions.genpoisson_p.pmf(2, 2, 0, 2)
assert_allclose(poisson_pmf, genpoisson_pmf, rtol=1e-15)
示例8: test_pmf_p5
# 需要导入模块: from scipy.stats import poisson [as 别名]
# 或者: from scipy.stats.poisson import pmf [as 别名]
def test_pmf_p5(self):
poisson_pmf = poisson.pmf(10, 2)
genpoisson_pmf_5 = sm.distributions.genpoisson_p.pmf(10, 2, 1e-25, 5)
assert_allclose(poisson_pmf, genpoisson_pmf_5, rtol=1e-12)
示例9: test_pmf_zero
# 需要导入模块: from scipy.stats import poisson [as 别名]
# 或者: from scipy.stats.poisson import pmf [as 别名]
def test_pmf_zero(self):
poisson_pmf = poisson.pmf(3, 2)
zipoisson_pmf = sm.distributions.zipoisson.pmf(3, 2, 0)
assert_allclose(poisson_pmf, zipoisson_pmf, rtol=1e-12)
示例10: test_pmf
# 需要导入模块: from scipy.stats import poisson [as 别名]
# 或者: from scipy.stats.poisson import pmf [as 别名]
def test_pmf(self):
poisson_pmf = poisson.pmf(2, 2)
zipoisson_pmf = sm.distributions.zipoisson.pmf(2, 2, 0.1)
assert_allclose(poisson_pmf, zipoisson_pmf, rtol=5e-2, atol=5e-2)
示例11: level_distribution
# 需要导入模块: from scipy.stats import poisson [as 别名]
# 或者: from scipy.stats.poisson import pmf [as 别名]
def level_distribution(self, k, mu):
_dists = np.array([poisson.pmf(kk, mu) for kk in range(1, k + 1)])
return _dists / np.sum(_dists)
示例12: single_gap_factor
# 需要导入模块: from scipy.stats import poisson [as 别名]
# 或者: from scipy.stats.poisson import pmf [as 别名]
def single_gap_factor(island_enriched_threshold,
poisson_distribution_parameter):
# type: (int, float) -> float
poisson_scores = [poisson.pmf(i, poisson_distribution_parameter)
for i in range(island_enriched_threshold)]
return sum(poisson_scores)
示例13: level_distribution
# 需要导入模块: from scipy.stats import poisson [as 别名]
# 或者: from scipy.stats.poisson import pmf [as 别名]
def level_distribution(self, k, mu):
_dists = np.array([poisson.pmf(kk, mu) for kk in range(1, k+1)])
return _dists / np.sum(_dists)
示例14: defineOptimization
# 需要导入模块: from scipy.stats import poisson [as 别名]
# 或者: from scipy.stats.poisson import pmf [as 别名]
def defineOptimization():
model = AbstractModel()
# Set of orders
model.S = Set()
# Budget
model.V = Param(within=NonNegativeReals)
# Purchase cost
model.c = Param(model.S, within=NonNegativeReals)
# Holding/refurbishing cost
model.h = Param(model.S, within=NonNegativeReals)
# Expected demand
model.demand = Param(model.S, within=NonNegativeReals)
# Cost of the lost sale due to the shortage of supply (economic cost)
model.b = Param(model.S, within=NonNegativeReals)
# Number of items of each product ordered
model.s = Var(model.S, within=NonNegativeIntegers, initialize=0)
# Minimize ordering cost
def cost_rule(model):
return sum(model.h[i] * (model.s[i] - model.demand[i]) +
(model.h[i] + model.b[i]) * sum((x - model.s[i]) * poisson.pmf(x,model.demand[i]) * (1/(1+exp(-10*(log(x+1)-log(model.s[i]+1)))))
for x in sequence(0, int(model.V / model.c[i])))
# we have to sum from 0 and not from s[i] since the indices of sum are determined
# at compilation time
# 1/(1+exp(...)) term is an approximation of the step function
# f(x,s[i]) = 1 if x>s[i], f(x,s[i])=0 if x<=s[i]
for i in model.S)
model.cost = Objective(rule=cost_rule)
# Budget constraint
def budget_rule(model):
return summation(model.c, model.s) <= model.V
model.budget_constraint = Constraint(rule=budget_rule)
return model
示例15: determine_thresholds
# 需要导入模块: from scipy.stats import poisson [as 别名]
# 或者: from scipy.stats.poisson import pmf [as 别名]
def determine_thresholds(kernels, ledges, gw_hist, fdr):
"""
given a 'gw_hist' histogram of observed counts
for each lambda-chunk for each kernel-type, and
also given a FDR, calculate q-values for each observed
count value in each lambda-chunk for each kernel-type.
Returns
-------
threshold_df : dict
each threshold_df[k] is a Series indexed by la_exp intervals
(IntervalIndex) and it is all we need to extract "good" pixels from
each chunk ...
qvalues : dict
A dictionary with keys being kernel names and values pandas.DataFrames
storing q-values: each column corresponds to a lambda-chunk,
while rows correspond to observed pixels values.
"""
rcs_hist = {}
rcs_Poisson = {}
qvalues = {}
threshold_df = {}
for k in kernels:
# Reverse cumulative histogram for this kernel.
# First row contains total # of pixels in each lambda-chunk.
rcs_hist[k] = gw_hist[k].iloc[::-1].cumsum(axis=0).iloc[::-1]
# Assign a unit Poisson distribution to each lambda-chunk.
# The expected value is the upper boundary of the lambda-chunk.
# poisson.sf = 1 - poisson.cdf, but more precise
# poisson.sf(-1,mu) == 1.0, i.e. is equivalent to the
# poisson.pmf(gw_hist[k].index, mu)[::-1].cumsum()[::-1]
rcs_Poisson[k] = pd.DataFrame()
for mu, column in zip(ledges[1:-1], gw_hist[k].columns):
renorm_factors = rcs_hist[k].loc[0, column]
rcs_Poisson[k][column] = renorm_factors * poisson.sf(
gw_hist[k].index - 1, mu
)
# Determine the threshold by checking the value at which 'fdr_diff'
# first turns positive. Fill NaNs with an "unreachably" high value.
fdr_diff = fdr * rcs_hist[k] - rcs_Poisson[k]
very_high_value = len(rcs_hist[k])
threshold_df[k] = (
fdr_diff.where(fdr_diff > 0)
.apply(lambda col: col.first_valid_index())
.fillna(very_high_value)
.astype(np.integer)
)
# q-values
# bear in mind some issues with lots of NaNs and Infs after
# such a brave operation ...
qvalues[k] = rcs_Poisson[k] / rcs_hist[k]
return threshold_df, qvalues