张量流概率中条件屏蔽自回归流的逆变换

发布于 2025-01-19 12:31:19 字数 1440 浏览 0 评论 0原文

以下是x _给定c _的日志条件密度的标准化流模型。

import tensorflow as tf
import tensorflow_probability as tfp
tfk = tf.keras
tfkl = tf.keras.layers
tfpl = tfp.layers
tfd = tfp.distributions
tfb = tfp.bijectors
n = 100
dims = 10
regNet1 = tfb.AutoregressiveNetwork(
    params=2,
    hidden_units=[64],
    event_shape=(dims,),
    conditional=True,
    conditional_event_shape=(10,),
    activation="relu",
    dtype=np.float32,
)
maf1 = tfb.MaskedAutoregressiveFlow(shift_and_log_scale_fn=regNet1, name="maf1")
maf_mod = tfd.TransformedDistribution(
    distribution=tfd.MultivariateNormalDiag(
        loc=np.zeros(dims).astype(dtype=np.float32),
        scale_diag=np.ones(dims).astype(dtype=np.float32),
    ),
    bijector=maf1,
)
# Construct and fit model
x_ = tfkl.Input(shape=dims, dtype=tf.float32)
c_ = tfkl.Input(shape=dims, dtype=tf.float32)
log_prob_ = maf_mod.log_prob(
    x_,
    bijector_kwargs={'conditional_input': c_}
)
model_log_prob = tfk.Model([x_, c_], log_prob_)

什么是x _给定c _的代码/语法。即,我希望通过绘制绘制(在本示例中的基线分布 - 多变量正常),这些绘制通过二元组(regnet1)映射到x _给定c_

我的目的是构建表单模型:

model_inverse = tfk.Model([x_, c_], inv_x_)

其中Inv_x _是与x _c _相对应的绘制。

我想像Inv_x_ = regnet1.inverse(x_,c _)之类的东西应该起作用,但我无法弄清楚正确的语法并使用。

The following is a normalizing flow model of the log conditional density of x_ given c_.

import tensorflow as tf
import tensorflow_probability as tfp
tfk = tf.keras
tfkl = tf.keras.layers
tfpl = tfp.layers
tfd = tfp.distributions
tfb = tfp.bijectors
n = 100
dims = 10
regNet1 = tfb.AutoregressiveNetwork(
    params=2,
    hidden_units=[64],
    event_shape=(dims,),
    conditional=True,
    conditional_event_shape=(10,),
    activation="relu",
    dtype=np.float32,
)
maf1 = tfb.MaskedAutoregressiveFlow(shift_and_log_scale_fn=regNet1, name="maf1")
maf_mod = tfd.TransformedDistribution(
    distribution=tfd.MultivariateNormalDiag(
        loc=np.zeros(dims).astype(dtype=np.float32),
        scale_diag=np.ones(dims).astype(dtype=np.float32),
    ),
    bijector=maf1,
)
# Construct and fit model
x_ = tfkl.Input(shape=dims, dtype=tf.float32)
c_ = tfkl.Input(shape=dims, dtype=tf.float32)
log_prob_ = maf_mod.log_prob(
    x_,
    bijector_kwargs={'conditional_input': c_}
)
model_log_prob = tfk.Model([x_, c_], log_prob_)

What is the code/syntax to get the inverse of x_ given c_. I.e., I want the draws (from the baseline distribution, in this example -- the multivariate Normal) that map through the bijector (regNet1) to x_ given c_.

My aim is to build a model of the form:

model_inverse = tfk.Model([x_, c_], inv_x_)

where inv_x_ are the draws that correspond to x_ and c_.

I would imagine that something like inv_x_ = regNet1.inverse(x_, c_) should work but I am unable to figure out the correct syntax and use.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北音执念 2025-01-26 12:31:20
def maf1inverse(x_):
    params = regNet1(x_, conditional_input = c_)
    return (x_ - params[:,:,0]) / tf.exp(params[:,:,1])
inv_x_ = maf1inverse(x_)
model_inverse = tfk.Model([x_, c_], inv_x_)
def maf1inverse(x_):
    params = regNet1(x_, conditional_input = c_)
    return (x_ - params[:,:,0]) / tf.exp(params[:,:,1])
inv_x_ = maf1inverse(x_)
model_inverse = tfk.Model([x_, c_], inv_x_)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文