PyMC3:每次给出不同的结果

问题描述 投票:0回答:1

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

发生了什么事?

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在这里

enter image description here

$\alpha$

python pymc3 markov-chains mcmc
1个回答
2
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.