PyMC3:每个tim提供不同的结果

2024-06-09 20:15:49 发布

您现在位置:Python中文网/ 问答频道 /正文

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

发生了什么事

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'==θ

enter image description here

$\alpha$


Tags: 函数importaswith对数mccorestensor