cuốn sách gpt4 ai đã làm

Xác định hàm python Pymc3

In lại Tác giả: Vũ trụ không gian Thời gian cập nhật: 2023-11-03 15:47:53 26 4
mua khóa gpt4 Nike

hiện hữuthis notebook来自 Bayesian Methods for Hackers,他们从 python 函数创建一个确定性变量:

# from code line 9 in the notebook
@pm.deterministic
def lambda_(tau=tau, lambda_1=lambda_1, lambda_2=lambda_2):
out = np.zeros(n_count_data)
out[:tau] = lambda_1 # lambda before tau is lambda1
out[tau:] = lambda_2 # lambda after (and including) tau is lambda2
return out

我试图几乎完全重现这个实验,但显然 @pm.deterministic 不是 pymc3 中的东西。知道如何在 pymc3 中执行此操作吗?

câu trả lời hay nhất

此模型在“Probabilistic Programming and Bayesian Methods for Hackers”的 PyMC3 端口中被翻译为

with pm.Model() as model:
alpha = 1.0/count_data.mean() # Recall count_data is the
# variable that holds our txt counts
lambda_1 = pm.Exponential("lambda_1", alpha)
lambda_2 = pm.Exponential("lambda_2", alpha)

tau = pm.DiscreteUniform("tau", lower=0, upper=n_count_data - 1)

# These two lines do what the deterministic function did above
idx = np.arange(n_count_data) # Index
lambda_ = pm.math.switch(tau > idx, lambda_1, lambda_2)

observation = pm.Poisson("obs", lambda_, observed=count_data)
trace = pm.sample()

请注意,我们只是使用 pm.math.switch(with 是 theano.tensor.switch 的别名)来计算 lambda_ .还有pm.Deterministic,不过这里不需要。

关于python - Pymc3 python函数确定性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48869788/

26 4 0
không gian vũ trụ
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress