张量流概率中条件屏蔽自回归流的逆变换
以下是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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)