0

默认先验Convolution3DReparametrization()tfp.layers.default_multivariate_normal_fn均值 0 和标准差 1 的各向同性高斯。后面是tfp_layers_util.default_mean_field_normal_fn()。例如,是否可以为先验和后验指定分层模型,prior~N(0,sigma)并且sigma~Gamma(a1,b1)?我怎样才能在 Tensorflow 概率中实现这一点,可能是tfd.JointDistributionSequential?的源代码tfp_layers_util.default_mean_field_normal_fn()如下:

def default_mean_field_normal_fn(
    is_singular=False,
    loc_initializer=tf1.initializers.random_normal(stddev=0.1),
    untransformed_scale_initializer=tf1.initializers.random_normal(
        mean=-3., stddev=0.1),
    loc_regularizer=None,
    untransformed_scale_regularizer=None,
    loc_constraint=None,
    untransformed_scale_constraint=None):

  loc_scale_fn = default_loc_scale_fn(
      is_singular=is_singular,
      loc_initializer=loc_initializer,
      untransformed_scale_initializer=untransformed_scale_initializer,
      loc_regularizer=loc_regularizer,
      untransformed_scale_regularizer=untransformed_scale_regularizer,
      loc_constraint=loc_constraint,
      untransformed_scale_constraint=untransformed_scale_constraint)

  def _fn(dtype, shape, name, trainable, add_variable_fn):
    
    loc, scale = loc_scale_fn(dtype, shape, name, trainable, add_variable_fn)
    if scale is None:
      dist = deterministic_lib.Deterministic(loc=loc)
    else:
      dist = normal_lib.Normal(loc=loc, scale=scale)
    batch_ndims = tf.size(dist.batch_shape_tensor())
    return independent_lib.Independent(
        dist, reinterpreted_batch_ndims=batch_ndims)
  return _fn
4

0 回答 0