将张量流概率约束为正系数
我有一个张量流 sts 模型,我希望将线性回归系数限制为大于零。我知道这可以通过将 HalfNormal 分布作为先验来实现:
network_effects = tfp.sts.LinearRegression(
design_matrix=tf.stack((df-df.mean()).values.astype(np.float32)),
name='network_effects',
weights_prior=tfd.HalfNormal(scale=2.0))
autoregressive = sts.Autoregressive(
order=8,
observed_time_series=observed_time_series,
name='autoregressive')
但是,它抱怨我的 dtypes 与错误不同:
ValueError: SampleHalfNormal, type=<dtype: 'float32'>, must be of the same type (<dtype: 'float64'>) as design_matrix_linop.
我约束线性回归系数的方法是否正确,如果是,我如何指定HalfNormal 分布是 float64 类型?
I have a tensorflow sts model I wish to constrain the Linear Regression coefficients to greater than zero. I understand this can be achieved by passing a HalfNormal distribution as a prior:
network_effects = tfp.sts.LinearRegression(
design_matrix=tf.stack((df-df.mean()).values.astype(np.float32)),
name='network_effects',
weights_prior=tfd.HalfNormal(scale=2.0))
autoregressive = sts.Autoregressive(
order=8,
observed_time_series=observed_time_series,
name='autoregressive')
However, it complains that my dtypes are not the same with the error:
ValueError: SampleHalfNormal, type=<dtype: 'float32'>, must be of the same type (<dtype: 'float64'>) as design_matrix_linop.
Is my method of constraining the Linear Regressor coefficients correct and if so, how do I specify that the HalfNormal distribution is of type float64?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
完全不明显这是如何完成的,但我对 Tensorflow 不太熟悉。然而,答案是将scale参数设置为float64,如下所示:
答案来自这篇文章:
如何在 TensorFlow 中创建分布数组概率?
Not at all obvious how this is done, but I'm not overly familiar with Tensorflow. However the answer is to set the scale argument to float64 as follows:
The answer came from this post here:
How can I create an array of distributions in TensorFlow Probability?