【问题标题】:PyMC3: Giving a Different Result Every timePyMC3:每次都给出不同的结果
【发布时间】:2019-11-20 00:16:56
【问题描述】:

我已经定义了一个对数似然函数,并且我有一个变量在均匀分布上进行采样。我确保对数似然函数为相同的输入返回相同的结果。但是当我采样时,每次分布都有些不同(在相同的范围内)。

发生了什么事?

import pymc3 as mc
import theano.tensor as tt

SAMPLES = 1000
TUNING_SAMPLES = 100
N_CORES = 10
N_CHAINS = 2

#(logl_ThetaFromChoices is defined above with the input)

# use PyMC3 to sampler from log-likelihood
with mc.Model() as modelFindTheta:
    theta = mc.Uniform('theta', lower=-200.0, upper=200.0)

    # convert m and c to a tensor vector
    theta = tt.as_tensor_variable(theta)

    def callOp(v):
        return logl_ThetaFromChoices(v)
    mc.DensityDist('logl_ThetaFromChoices', callOp, observed={'v': theta})

    step1 = mc.Metropolis()
    trace_theta = mc.sample(SAMPLES,
                            tune=TUNING_SAMPLES,
                            discard_tuned_samples=True,
                            chains=N_CHAINS,
                            cores=N_CORES,
                            step=step1)

'alpha' == 这里的 Theta

【问题讨论】:

    标签: python pymc3 markov-chains mcmc


    【解决方案1】:

    由于它涉及随机数生成,因此需要设置种子以获得可重复的结果。对于 PyMC3,这是通过 the pymc3.sampling.sample() method 中的 random_seed 参数完成的。

    【讨论】:

    • 我在哪里可以找到他们使用的算法的清晰描述?我不知道结果会如何变化。分布嵌入在数据本身中,而不是方法中......?
    • @user1581390 抱歉,我不确定我是否遵循让您感到困惑的问题。根据定义,您正在调用一种从概率模型生成随机样本的方法(theta 是一个随机变量)。 MCMC 通常使用后验似然评估来创建随机序列,而 Metropolis-Hastings 是您使用的特定算法实现。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-12
    • 2012-08-21
    • 2021-07-12
    • 2018-05-02
    • 1970-01-01
    相关资源
    最近更新 更多