当前位置: 首页>>代码示例>>Python>>正文


Python MCMC.write_csv方法代码示例

本文整理汇总了Python中pymc.MCMC.write_csv方法的典型用法代码示例。如果您正苦于以下问题:Python MCMC.write_csv方法的具体用法?Python MCMC.write_csv怎么用?Python MCMC.write_csv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymc.MCMC的用法示例。


在下文中一共展示了MCMC.write_csv方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: estimate_failures

# 需要导入模块: from pymc import MCMC [as 别名]
# 或者: from pymc.MCMC import write_csv [as 别名]
def estimate_failures(samples, #samples from noisy labelers
                      n_samples=10000, #number of samples to run MCMC for
                      burn=None, #burn-in. Defaults to n_samples/2
                      thin=10, #thinning rate. Sample every k samples from markov chain 
                      alpha_p=1, beta_p=1, #beta parameters for true positive rate
                      alpha_e=1, beta_e=10 #beta parameters for noise rates
                      ):

  if burn is None:
    burn = n_samples / 2

  S,N = samples.shape
  p = Beta('p', alpha=alpha_p, beta=beta_p) #prior on true label
  l = Bernoulli('l', p=p, size=S)
  e_pos = Beta('e_pos', alpha_e, beta_e, size=N) # error rate if label = 1
  e_neg = Beta('e_neg', alpha_e, beta_e, size=N) # error rate if label = 0

  @deterministic(plot=False)
  def noise_rate(l=l, e_pos=e_pos, e_neg=e_neg):
    #probability that a noisy labeler puts a label 1
    return np.outer(l, 1-e_pos) + np.outer(1-l, e_neg)

  noisy_label = Bernoulli('noisy_label', p=noise_rate, size=samples.shape, value=samples, observed=True)
  variables = [l, e_pos, e_neg, p, noisy_label, noise_rate]
  model = MCMC(variables, verbose=3)
  model.sample(iter=n_samples, burn=burn, thin=thin)
  model.write_csv('out.csv', ['p', 'e_pos', 'e_neg'])
  p = np.median(model.trace('p')[:])
  e_pos = np.median(model.trace('e_pos')[:],0)
  e_neg = np.median(model.trace('e_neg')[:],0)
  return p, e_pos, e_neg
开发者ID:clinicalml,项目名称:noise-estimation,代码行数:33,代码来源:model.py

示例2: estimate_failures_from_counts

# 需要导入模块: from pymc import MCMC [as 别名]
# 或者: from pymc.MCMC import write_csv [as 别名]
def estimate_failures_from_counts(counts, #samples from noisy labelers
                      n_samples=10000, #number of samples to run MCMC for
                      burn=None, #burn-in. Defaults to n_samples/2
                      thin=10, #thinning rate. Sample every k samples from markov chain 
                      alpha_p=1, beta_p=1, #beta parameters for true positive rate
                      alpha_e=1, beta_e=10 #beta parameters for noise rates
                      ):

  if burn is None:
    burn = n_samples / 2

  S = counts.sum()
  N = len(counts.shape)

  p_label = Beta('p_label', alpha=alpha_p, beta=beta_p) #prior on true label
  e_pos = Beta('e_pos', alpha_e, beta_e, size=N) # error rate if label = 1
  e_neg = Beta('e_neg', alpha_e, beta_e, size=N) # error rate if label = 0

  print counts
  @deterministic(plot=False)
  def patterns(p_label=p_label, e_pos=e_pos, e_neg=e_neg):
    #probability that the noisy labelers output pattern p
    P = np.zeros((2,)*N)
    for pat in itertools.product([0,1], repeat=N):
      P[pat] = p_label*np.product([1-e_pos[i] if pat[i]==1 else e_pos[i] for i in xrange(N)])
      P[pat] += (1-p_label)*np.product([e_neg[i] if pat[i]==1 else 1-e_neg[i] for i in xrange(N)])
    assert np.abs(P.sum() - 1) < 1e-6
    return P.ravel()
    
  pattern_counts = Multinomial('pattern_counts',n=S, p=patterns, value=counts.ravel(), observed=True)
  variables = [p_label, e_pos, e_neg, patterns]
  model = MCMC(variables, verbose=3)
  model.sample(iter=n_samples, burn=burn, thin=thin)
  model.write_csv('out.csv', ['p_label', 'e_pos', 'e_neg'])
  p = np.median(model.trace('p_label')[:])
  e_pos = np.median(model.trace('e_pos')[:],0)
  e_neg = np.median(model.trace('e_neg')[:],0)
  return p, e_pos, e_neg
开发者ID:clinicalml,项目名称:noise-estimation,代码行数:40,代码来源:model.py

示例3: Dorazio

# 需要导入模块: from pymc import MCMC [as 别名]
# 或者: from pymc.MCMC import write_csv [as 别名]
# PyMC implementation of Panel 6.4 from Royle & Dorazio (2008) pp. 217
# MA MacNeil - 04.03.14

import Mbht
import sys
import os
import pdb
from pymc import MCMC, BinaryMetropolis, Metropolis, AdaptiveMetropolis
from pymc import Matplot as mp
import pdb


M = MCMC(Mbht)
#M = MCMC(models,db='sqlite',dbname='xx_dbase')
xex = 6
M.isample(10**xex, 10**xex-10**(xex-1), thin=10**(xex-4), verbose=2)
#M.isample(100000, 80000, thin=10, verbose=2)

try:
    os.mkdir('Outputs')
except OSError:
    pass
os.chdir('Outputs')
M.write_csv("zz_results.csv")
mp.plot(M)
开发者ID:mamacneil,项目名称:Royle_microtus,代码行数:27,代码来源:runmodel.py

示例4: MCMC

# 需要导入模块: from pymc import MCMC [as 别名]
# 或者: from pymc.MCMC import write_csv [as 别名]
# Run model
#
# PyMC implementation of Smith et al. (2012) Ecology: http://www.esajournals.org/doi/abs/10.1890/12-0460.1
# 
#  Created by M. Aaron MacNeil on 20/07/12.
#

import snapper
from pymc import MCMC, BinaryMetropolis, Metropolis, AdaptiveMetropolis
from pymc import Matplot as mp


M = MCMC(snapper)
xex = 5
M.isample(10**xex, 10**xex-10**(xex-1), thin=100, verbose=2)


M.write_csv("results.csv")
mp.plot(M)
开发者ID:mamacneil,项目名称:snapper,代码行数:21,代码来源:runmodel.py


注:本文中的pymc.MCMC.write_csv方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。