當前位置: 首頁>>代碼示例>>Python>>正文


Python poisson.pmf方法代碼示例

本文整理匯總了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) 
開發者ID:XanaduAI,項目名稱:thewalrus,代碼行數:25,代碼來源:test_quantum.py

示例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) 
開發者ID:XanaduAI,項目名稱:thewalrus,代碼行數:19,代碼來源:test_quantum.py

示例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 
開發者ID:biocore-ntnu,項目名稱:epic,代碼行數:18,代碼來源:compute_window_score.py

示例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 
開發者ID:biocore-ntnu,項目名稱:epic,代碼行數:18,代碼來源:compute_values_needed_for_recurrence.py

示例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] 
開發者ID:ShangtongZhang,項目名稱:reinforcement-learning-an-introduction,代碼行數:8,代碼來源:car_rental.py

示例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) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:6,代碼來源:test_discrete.py

示例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) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:6,代碼來源:test_discrete.py

示例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) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:6,代碼來源:test_discrete.py

示例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) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:6,代碼來源:test_discrete.py

示例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) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:6,代碼來源:test_discrete.py

示例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) 
開發者ID:ying-wen,項目名稱:malib,代碼行數:5,代碼來源:level_k_policy.py

示例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) 
開發者ID:biocore-ntnu,項目名稱:epic,代碼行數:9,代碼來源:compute_values_needed_for_recurrence.py

示例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) 
開發者ID:ml3705454,項目名稱:mapr2,代碼行數:5,代碼來源:level_k_policy.py

示例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 
開發者ID:Azure,項目名稱:cortana-intelligence-inventory-optimization,代碼行數:48,代碼來源:newsvendor.py

示例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 
開發者ID:mirnylab,項目名稱:cooltools,代碼行數:59,代碼來源:dotfinder.py


注:本文中的scipy.stats.poisson.pmf方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。