from __future__ import division
from __future__ import print_function
+from tensorflow.contrib.bayesflow.python.ops import docstring_util
from tensorflow.contrib.bayesflow.python.ops import layers_util
from tensorflow.contrib.distributions.python.ops import independent as independent_lib
from tensorflow.python.framework import dtypes
from tensorflow.python.ops.distributions import normal as normal_lib
from tensorflow.python.ops.distributions import util as distribution_util
+doc_args = """ activation: Activation function. Set it to None to maintain a
+ linear activation.
+ activity_regularizer: Optional regularizer function for the output.
+ trainable: Boolean, if `True` also add variables to the graph collection
+ `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
+ kernel_posterior_fn: Python `callable` which creates
+ `tf.distributions.Distribution` instance representing the surrogate
+ posterior of the `kernel` parameter. Default value:
+ `default_mean_field_normal_fn()`.
+ kernel_posterior_tensor_fn: Python `callable` which takes a
+ `tf.distributions.Distribution` instance and returns a representative
+ value. Default value: `lambda d: d.sample()`.
+ kernel_prior_fn: Python `callable` which creates `tf.distributions`
+ instance. See `default_mean_field_normal_fn` docstring for required
+ parameter signature.
+ Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
+ kernel_divergence_fn: Python `callable` which takes the surrogate posterior
+ distribution, prior distribution and random variate sample(s) from the
+ surrogate posterior and computes or approximates the KL divergence. The
+ distributions are `tf.distributions.Distribution`-like instances and the
+ sample is a `Tensor`.
+ bias_posterior_fn: Python `callable` which creates
+ `tf.distributions.Distribution` instance representing the surrogate
+ posterior of the `bias` parameter. Default value:
+ `default_mean_field_normal_fn(is_singular=True)` (which creates an
+ instance of `tf.distributions.Deterministic`).
+ bias_posterior_tensor_fn: Python `callable` which takes a
+ `tf.distributions.Distribution` instance and returns a representative
+ value. Default value: `lambda d: d.sample()`.
+ bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
+ See `default_mean_field_normal_fn` docstring for required parameter
+ signature. Default value: `None` (no prior, no variational inference)
+ bias_divergence_fn: Python `callable` which takes the surrogate posterior
+ distribution, prior distribution and random variate sample(s) from the
+ surrogate posterior and computes or approximates the KL divergence. The
+ distributions are `tf.distributions.Distribution`-like instances and the
+ sample is a `Tensor`.
+ name: A string, the name of the layer."""
+
class _ConvVariational(layers_lib.Layer):
"""Abstract nD convolution layer (private, used as implementation base).
(`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
distributions.
- Arguments:
- rank: An integer, the rank of the convolution, e.g. "2" for 2D convolution.
- filters: Integer, the dimensionality of the output space (i.e. the number
- of filters in the convolution).
- kernel_size: An integer or tuple/list of n integers, specifying the
- length of the convolution window.
- strides: An integer or tuple/list of n integers,
- specifying the stride length of the convolution.
- Specifying any stride value != 1 is incompatible with specifying
- any `dilation_rate` value != 1.
- padding: One of `"valid"` or `"same"` (case-insensitive).
- data_format: A string, one of `channels_last` (default) or `channels_first`.
- The ordering of the dimensions in the inputs.
- `channels_last` corresponds to inputs with shape
- `(batch, ..., channels)` while `channels_first` corresponds to
- inputs with shape `(batch, channels, ...)`.
- dilation_rate: An integer or tuple/list of n integers, specifying
- the dilation rate to use for dilated convolution.
- Currently, specifying any `dilation_rate` value != 1 is
- incompatible with specifying any `strides` value != 1.
- activation: Activation function. Set it to None to maintain a
- linear activation.
- activity_regularizer: Optional regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- name: A string, the name of the layer.
-
Properties:
rank: Python integer, dimensionality of convolution.
filters: Python integer, dimensionality of the output space.
bias_divergence_fn: `callable` returning divergence.
"""
+ @docstring_util.expand_docstring(args=doc_args)
def __init__(
self,
rank,
bias_divergence_fn=lambda q, p, ignore: kl_lib.kl_divergence(q, p),
name=None,
**kwargs):
+ """Construct layer.
+
+ Args:
+ rank: An integer, the rank of the convolution, e.g. "2" for 2D
+ convolution.
+ filters: Integer, the dimensionality of the output space (i.e. the number
+ of filters in the convolution).
+ kernel_size: An integer or tuple/list of n integers, specifying the
+ length of the convolution window.
+ strides: An integer or tuple/list of n integers,
+ specifying the stride length of the convolution.
+ Specifying any stride value != 1 is incompatible with specifying
+ any `dilation_rate` value != 1.
+ padding: One of `"valid"` or `"same"` (case-insensitive).
+ data_format: A string, one of `channels_last` (default) or
+ `channels_first`. The ordering of the dimensions in the inputs.
+ `channels_last` corresponds to inputs with shape `(batch, ...,
+ channels)` while `channels_first` corresponds to inputs with shape
+ `(batch, channels, ...)`.
+ dilation_rate: An integer or tuple/list of n integers, specifying
+ the dilation rate to use for dilated convolution.
+ Currently, specifying any `dilation_rate` value != 1 is
+ incompatible with specifying any `strides` value != 1.
+ @{args}
+ """
super(_ConvVariational, self).__init__(
trainable=trainable,
name=name,
(`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
distributions.
- Arguments:
- rank: An integer, the rank of the convolution, e.g. "2" for 2D convolution.
- filters: Integer, the dimensionality of the output space (i.e. the number
- of filters in the convolution).
- kernel_size: An integer or tuple/list of n integers, specifying the
- length of the convolution window.
- strides: An integer or tuple/list of n integers,
- specifying the stride length of the convolution.
- Specifying any stride value != 1 is incompatible with specifying
- any `dilation_rate` value != 1.
- padding: One of `"valid"` or `"same"` (case-insensitive).
- data_format: A string, one of `channels_last` (default) or `channels_first`.
- The ordering of the dimensions in the inputs.
- `channels_last` corresponds to inputs with shape
- `(batch, ..., channels)` while `channels_first` corresponds to
- inputs with shape `(batch, channels, ...)`.
- dilation_rate: An integer or tuple/list of n integers, specifying
- the dilation rate to use for dilated convolution.
- Currently, specifying any `dilation_rate` value != 1 is
- incompatible with specifying any `strides` value != 1.
- activation: Activation function. Set it to None to maintain a
- linear activation.
- activity_regularizer: Optional regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- name: A string, the name of the layer.
-
Properties:
rank: Python integer, dimensionality of convolution.
filters: Python integer, dimensionality of the output space.
International Conference on Learning Representations, 2014.
"""
+ @docstring_util.expand_docstring(args=doc_args)
def __init__(
self,
rank,
bias_divergence_fn=lambda q, p, ignore: kl_lib.kl_divergence(q, p),
name=None,
**kwargs):
+ """Construct layer.
+
+ Args:
+ rank: An integer, the rank of the convolution, e.g. "2" for 2D
+ convolution.
+ filters: Integer, the dimensionality of the output space (i.e. the number
+ of filters in the convolution).
+ kernel_size: An integer or tuple/list of n integers, specifying the
+ length of the convolution window.
+ strides: An integer or tuple/list of n integers,
+ specifying the stride length of the convolution.
+ Specifying any stride value != 1 is incompatible with specifying
+ any `dilation_rate` value != 1.
+ padding: One of `"valid"` or `"same"` (case-insensitive).
+ data_format: A string, one of `channels_last` (default) or
+ `channels_first`. The ordering of the dimensions in the inputs.
+ `channels_last` corresponds to inputs with shape `(batch, ...,
+ channels)` while `channels_first` corresponds to inputs with shape
+ `(batch, channels, ...)`.
+ dilation_rate: An integer or tuple/list of n integers, specifying
+ the dilation rate to use for dilated convolution.
+ Currently, specifying any `dilation_rate` value != 1 is
+ incompatible with specifying any `strides` value != 1.
+ @{args}
+ """
super(_ConvReparameterization, self).__init__(
rank=rank,
filters=filters,
(`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
distributions.
- Arguments:
- filters: Integer, the dimensionality of the output space (i.e. the number
- of filters in the convolution).
- kernel_size: An integer or tuple/list of a single integer, specifying the
- length of the 1D convolution window.
- strides: An integer or tuple/list of a single integer,
- specifying the stride length of the convolution.
- Specifying any stride value != 1 is incompatible with specifying
- any `dilation_rate` value != 1.
- padding: One of `"valid"` or `"same"` (case-insensitive).
- data_format: A string, one of `channels_last` (default) or `channels_first`.
- The ordering of the dimensions in the inputs.
- `channels_last` corresponds to inputs with shape
- `(batch, length, channels)` while `channels_first` corresponds to
- inputs with shape `(batch, channels, length)`.
- dilation_rate: An integer or tuple/list of a single integer, specifying
- the dilation rate to use for dilated convolution.
- Currently, specifying any `dilation_rate` value != 1 is
- incompatible with specifying any `strides` value != 1.
- activation: Activation function. Set it to None to maintain a
- linear activation.
- activity_regularizer: Optional regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- name: A string, the name of the layer.
-
Properties:
filters: Python integer, dimensionality of the output space.
kernel_size: Size of the convolution window.
International Conference on Learning Representations, 2014.
"""
+ @docstring_util.expand_docstring(args=doc_args)
def __init__(
self,
filters,
bias_divergence_fn=lambda q, p, ignore: kl_lib.kl_divergence(q, p),
name=None,
**kwargs):
+ """Construct layer.
+
+ Args:
+ filters: Integer, the dimensionality of the output space (i.e. the number
+ of filters in the convolution).
+ kernel_size: An integer or tuple/list of a single integer, specifying the
+ length of the 1D convolution window.
+ strides: An integer or tuple/list of a single integer,
+ specifying the stride length of the convolution.
+ Specifying any stride value != 1 is incompatible with specifying
+ any `dilation_rate` value != 1.
+ padding: One of `"valid"` or `"same"` (case-insensitive).
+ data_format: A string, one of `channels_last` (default) or
+ `channels_first`. The ordering of the dimensions in the inputs.
+ `channels_last` corresponds to inputs with shape `(batch, length,
+ channels)` while `channels_first` corresponds to inputs with shape
+ `(batch, channels, length)`.
+ dilation_rate: An integer or tuple/list of a single integer, specifying
+ the dilation rate to use for dilated convolution.
+ Currently, specifying any `dilation_rate` value != 1 is
+ incompatible with specifying any `strides` value != 1.
+ @{args}
+ """
super(Conv1DReparameterization, self).__init__(
rank=1,
filters=filters,
name=name, **kwargs)
+@docstring_util.expand_docstring(args=doc_args)
def conv1d_reparameterization(
inputs,
filters,
(`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
distributions.
- Arguments:
+ Args:
inputs: Tensor input.
filters: Integer, the dimensionality of the output space (i.e. the number
of filters in the convolution).
the dilation rate to use for dilated convolution.
Currently, specifying any `dilation_rate` value != 1 is
incompatible with specifying any `strides` value != 1.
- activation: Activation function. Set it to None to maintain a
- linear activation.
- activity_regularizer: Optional regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- name: A string, the name of the layer.
+ @{args}
reuse: Boolean, whether to reuse the weights of a previous layer
by the same name.
(`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
distributions.
- Arguments:
- filters: Integer, the dimensionality of the output space (i.e. the number
- of filters in the convolution).
- kernel_size: An integer or tuple/list of 2 integers, specifying the
- height and width of the 2D convolution window.
- Can be a single integer to specify the same value for
- all spatial dimensions.
- strides: An integer or tuple/list of 2 integers,
- specifying the strides of the convolution along the height and width.
- Can be a single integer to specify the same value for
- all spatial dimensions.
- Specifying any stride value != 1 is incompatible with specifying
- any `dilation_rate` value != 1.
- padding: One of `"valid"` or `"same"` (case-insensitive).
- data_format: A string, one of `channels_last` (default) or `channels_first`.
- The ordering of the dimensions in the inputs.
- `channels_last` corresponds to inputs with shape
- `(batch, height, width, channels)` while `channels_first` corresponds to
- inputs with shape `(batch, channels, height, width)`.
-
- dilation_rate: An integer or tuple/list of 2 integers, specifying
- the dilation rate to use for dilated convolution.
- Can be a single integer to specify the same value for
- all spatial dimensions.
- Currently, specifying any `dilation_rate` value != 1 is
- incompatible with specifying any stride value != 1.
- activation: Activation function. Set it to None to maintain a
- linear activation.
- activity_regularizer: Optional regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- name: A string, the name of the layer.
-
Properties:
filters: Python integer, dimensionality of the output space.
kernel_size: Size of the convolution window.
International Conference on Learning Representations, 2014.
"""
+ @docstring_util.expand_docstring(args=doc_args)
def __init__(
self,
filters,
bias_divergence_fn=lambda q, p, ignore: kl_lib.kl_divergence(q, p),
name=None,
**kwargs):
+ """Construct layer.
+
+ Args:
+ filters: Integer, the dimensionality of the output space (i.e. the number
+ of filters in the convolution).
+ kernel_size: An integer or tuple/list of 2 integers, specifying the
+ height and width of the 2D convolution window.
+ Can be a single integer to specify the same value for
+ all spatial dimensions.
+ strides: An integer or tuple/list of 2 integers,
+ specifying the strides of the convolution along the height and width.
+ Can be a single integer to specify the same value for
+ all spatial dimensions.
+ Specifying any stride value != 1 is incompatible with specifying
+ any `dilation_rate` value != 1.
+ padding: One of `"valid"` or `"same"` (case-insensitive).
+ data_format: A string, one of `channels_last` (default) or
+ `channels_first`. The ordering of the dimensions in the inputs.
+ `channels_last` corresponds to inputs with shape `(batch, height,
+ width, channels)` while `channels_first` corresponds to inputs with
+ shape `(batch, channels, height, width)`.
+ dilation_rate: An integer or tuple/list of 2 integers, specifying
+ the dilation rate to use for dilated convolution.
+ Can be a single integer to specify the same value for
+ all spatial dimensions.
+ Currently, specifying any `dilation_rate` value != 1 is
+ incompatible with specifying any stride value != 1.
+ @{args}
+ """
super(Conv2DReparameterization, self).__init__(
rank=2,
filters=filters,
name=name, **kwargs)
+@docstring_util.expand_docstring(args=doc_args)
def conv2d_reparameterization(
inputs,
filters,
(`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
distributions.
- Arguments:
+ Args:
inputs: Tensor input.
filters: Integer, the dimensionality of the output space (i.e. the number
of filters in the convolution).
`channels_last` corresponds to inputs with shape
`(batch, height, width, channels)` while `channels_first` corresponds to
inputs with shape `(batch, channels, height, width)`.
-
dilation_rate: An integer or tuple/list of 2 integers, specifying
the dilation rate to use for dilated convolution.
Can be a single integer to specify the same value for
all spatial dimensions.
Currently, specifying any `dilation_rate` value != 1 is
incompatible with specifying any stride value != 1.
- activation: Activation function. Set it to None to maintain a
- linear activation.
- activity_regularizer: Optional regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- name: A string, the name of the layer.
+ @{args}
reuse: Boolean, whether to reuse the weights of a previous layer
by the same name.
(`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
distributions.
- Arguments:
- filters: Integer, the dimensionality of the output space (i.e. the number
- of filters in the convolution).
- kernel_size: An integer or tuple/list of 3 integers, specifying the
- depth, height and width of the 3D convolution window.
- Can be a single integer to specify the same value for
- all spatial dimensions.
- strides: An integer or tuple/list of 3 integers,
- specifying the strides of the convolution along the depth,
- height and width.
- Can be a single integer to specify the same value for
- all spatial dimensions.
- Specifying any stride value != 1 is incompatible with specifying
- any `dilation_rate` value != 1.
- padding: One of `"valid"` or `"same"` (case-insensitive).
- data_format: A string, one of `channels_last` (default) or `channels_first`.
- The ordering of the dimensions in the inputs.
- `channels_last` corresponds to inputs with shape
- `(batch, depth, height, width, channels)` while `channels_first`
- corresponds to inputs with shape
- `(batch, channels, depth, height, width)`.
- dilation_rate: An integer or tuple/list of 3 integers, specifying
- the dilation rate to use for dilated convolution.
- Can be a single integer to specify the same value for
- all spatial dimensions.
- Currently, specifying any `dilation_rate` value != 1 is
- incompatible with specifying any stride value != 1.
- activation: Activation function. Set it to None to maintain a
- linear activation.
- activity_regularizer: Optional regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- name: A string, the name of the layer.
-
Properties:
filters: Python integer, dimensionality of the output space.
kernel_size: Size of the convolution window.
International Conference on Learning Representations, 2014.
"""
+ @docstring_util.expand_docstring(args=doc_args)
def __init__(
self,
filters,
bias_divergence_fn=lambda q, p, ignore: kl_lib.kl_divergence(q, p),
name=None,
**kwargs):
+ """Construct layer.
+
+ Args:
+ filters: Integer, the dimensionality of the output space (i.e. the number
+ of filters in the convolution).
+ kernel_size: An integer or tuple/list of 3 integers, specifying the
+ depth, height and width of the 3D convolution window.
+ Can be a single integer to specify the same value for
+ all spatial dimensions.
+ strides: An integer or tuple/list of 3 integers,
+ specifying the strides of the convolution along the depth,
+ height and width.
+ Can be a single integer to specify the same value for
+ all spatial dimensions.
+ Specifying any stride value != 1 is incompatible with specifying
+ any `dilation_rate` value != 1.
+ padding: One of `"valid"` or `"same"` (case-insensitive).
+ data_format: A string, one of `channels_last` (default) or
+ `channels_first`. The ordering of the dimensions in the inputs.
+ `channels_last` corresponds to inputs with shape `(batch, depth,
+ height, width, channels)` while `channels_first` corresponds to inputs
+ with shape `(batch, channels, depth, height, width)`.
+ dilation_rate: An integer or tuple/list of 3 integers, specifying
+ the dilation rate to use for dilated convolution.
+ Can be a single integer to specify the same value for
+ all spatial dimensions.
+ Currently, specifying any `dilation_rate` value != 1 is
+ incompatible with specifying any stride value != 1.
+ @{args}
+ """
super(Conv3DReparameterization, self).__init__(
rank=3,
filters=filters,
name=name, **kwargs)
+@docstring_util.expand_docstring(args=doc_args)
def conv3d_reparameterization(
inputs,
filters,
(`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
distributions.
- Arguments:
+ Args:
inputs: Tensor input.
filters: Integer, the dimensionality of the output space (i.e. the number
of filters in the convolution).
all spatial dimensions.
Currently, specifying any `dilation_rate` value != 1 is
incompatible with specifying any stride value != 1.
- activation: Activation function. Set it to None to maintain a
- linear activation.
- activity_regularizer: Optional regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- name: A string, the name of the layer.
+ @{args}
reuse: Boolean, whether to reuse the weights of a previous layer
by the same name.
(`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
distributions.
- Arguments:
- rank: An integer, the rank of the convolution, e.g. "2" for 2D convolution.
- filters: Integer, the dimensionality of the output space (i.e. the number
- of filters in the convolution).
- kernel_size: An integer or tuple/list of n integers, specifying the
- length of the convolution window.
- strides: An integer or tuple/list of n integers,
- specifying the stride length of the convolution.
- Specifying any stride value != 1 is incompatible with specifying
- any `dilation_rate` value != 1.
- padding: One of `"valid"` or `"same"` (case-insensitive).
- data_format: A string, one of `channels_last` (default) or `channels_first`.
- The ordering of the dimensions in the inputs.
- `channels_last` corresponds to inputs with shape
- `(batch, ..., channels)` while `channels_first` corresponds to
- inputs with shape `(batch, channels, ...)`.
- dilation_rate: An integer or tuple/list of n integers, specifying
- the dilation rate to use for dilated convolution.
- Currently, specifying any `dilation_rate` value != 1 is
- incompatible with specifying any `strides` value != 1.
- activation: Activation function. Set it to None to maintain a
- linear activation.
- activity_regularizer: Optional regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- seed: Python scalar `int` which initializes the random number
- generator. Default value: `None` (i.e., use global seed).
- name: A string, the name of the layer.
-
Properties:
rank: Python integer, dimensionality of convolution.
filters: Python integer, dimensionality of the output space.
[1]: "Flipout: Efficient Pseudo-Independent Weight Perturbations on
Mini-Batches."
- Anonymous. OpenReview, 2017.
- https://openreview.net/forum?id=rJnpifWAb
+ Yeming Wen, Paul Vicol, Jimmy Ba, Dustin Tran, Roger Grosse.
+ International Conference on Learning Representations, 2018.
"""
+ @docstring_util.expand_docstring(args=doc_args)
def __init__(
self,
rank,
seed=None,
name=None,
**kwargs):
+ """Construct layer.
+
+ Args:
+ rank: An integer, the rank of the convolution, e.g. "2" for 2D
+ convolution.
+ filters: Integer, the dimensionality of the output space (i.e. the number
+ of filters in the convolution).
+ kernel_size: An integer or tuple/list of n integers, specifying the
+ length of the convolution window.
+ strides: An integer or tuple/list of n integers,
+ specifying the stride length of the convolution.
+ Specifying any stride value != 1 is incompatible with specifying
+ any `dilation_rate` value != 1.
+ padding: One of `"valid"` or `"same"` (case-insensitive).
+ data_format: A string, one of `channels_last` (default) or
+ `channels_first`. The ordering of the dimensions in the inputs.
+ `channels_last` corresponds to inputs with shape `(batch, ...,
+ channels)` while `channels_first` corresponds to inputs with shape
+ `(batch, channels, ...)`.
+ dilation_rate: An integer or tuple/list of n integers, specifying
+ the dilation rate to use for dilated convolution.
+ Currently, specifying any `dilation_rate` value != 1 is
+ incompatible with specifying any `strides` value != 1.
+ @{args}
+ """
super(_ConvFlipout, self).__init__(
rank=rank,
filters=filters,
(`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
distributions.
- Arguments:
- filters: Integer, the dimensionality of the output space (i.e. the number
- of filters in the convolution).
- kernel_size: An integer or tuple/list of a single integer, specifying the
- length of the 1D convolution window.
- strides: An integer or tuple/list of a single integer,
- specifying the stride length of the convolution.
- Specifying any stride value != 1 is incompatible with specifying
- any `dilation_rate` value != 1.
- padding: One of `"valid"` or `"same"` (case-insensitive).
- data_format: A string, one of `channels_last` (default) or `channels_first`.
- The ordering of the dimensions in the inputs.
- `channels_last` corresponds to inputs with shape
- `(batch, length, channels)` while `channels_first` corresponds to
- inputs with shape `(batch, channels, length)`.
- dilation_rate: An integer or tuple/list of a single integer, specifying
- the dilation rate to use for dilated convolution.
- Currently, specifying any `dilation_rate` value != 1 is
- incompatible with specifying any `strides` value != 1.
- activation: Activation function. Set it to None to maintain a
- linear activation.
- activity_regularizer: Optional regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- seed: Python scalar `int` which initializes the random number
- generator. Default value: `None` (i.e., use global seed).
- name: A string, the name of the layer.
-
Properties:
filters: Python integer, dimensionality of the output space.
kernel_size: Size of the convolution window.
[1]: "Flipout: Efficient Pseudo-Independent Weight Perturbations on
Mini-Batches."
- Anonymous. OpenReview, 2017.
- https://openreview.net/forum?id=rJnpifWAb
+ Yeming Wen, Paul Vicol, Jimmy Ba, Dustin Tran, Roger Grosse.
+ International Conference on Learning Representations, 2018.
"""
+ @docstring_util.expand_docstring(args=doc_args)
def __init__(
self,
filters,
seed=None,
name=None,
**kwargs):
+ """Construct layer.
+
+ Args:
+ filters: Integer, the dimensionality of the output space (i.e. the number
+ of filters in the convolution).
+ kernel_size: An integer or tuple/list of a single integer, specifying the
+ length of the 1D convolution window.
+ strides: An integer or tuple/list of a single integer,
+ specifying the stride length of the convolution.
+ Specifying any stride value != 1 is incompatible with specifying
+ any `dilation_rate` value != 1.
+ padding: One of `"valid"` or `"same"` (case-insensitive).
+ data_format: A string, one of `channels_last` (default) or
+ `channels_first`. The ordering of the dimensions in the inputs.
+ `channels_last` corresponds to inputs with shape `(batch, length,
+ channels)` while `channels_first` corresponds to inputs with shape
+ `(batch, channels, length)`.
+ dilation_rate: An integer or tuple/list of a single integer, specifying
+ the dilation rate to use for dilated convolution.
+ Currently, specifying any `dilation_rate` value != 1 is
+ incompatible with specifying any `strides` value != 1.
+ @{args}
+ """
super(Conv1DFlipout, self).__init__(
rank=1,
filters=filters,
name=name, **kwargs)
+@docstring_util.expand_docstring(args=doc_args)
def conv1d_flipout(
inputs,
filters,
(`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
distributions.
- Arguments:
+ Args:
inputs: Tensor input.
filters: Integer, the dimensionality of the output space (i.e. the number
of filters in the convolution).
the dilation rate to use for dilated convolution.
Currently, specifying any `dilation_rate` value != 1 is
incompatible with specifying any `strides` value != 1.
- activation: Activation function. Set it to None to maintain a
- linear activation.
- activity_regularizer: Optional regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- seed: Python scalar `int` which initializes the random number
- generator. Default value: `None` (i.e., use global seed).
- name: A string, the name of the layer.
+ @{args}
reuse: Boolean, whether to reuse the weights of a previous layer
by the same name.
[1]: "Flipout: Efficient Pseudo-Independent Weight Perturbations on
Mini-Batches."
- Anonymous. OpenReview, 2017.
- https://openreview.net/forum?id=rJnpifWAb
+ Yeming Wen, Paul Vicol, Jimmy Ba, Dustin Tran, Roger Grosse.
+ International Conference on Learning Representations, 2018.
"""
layer = Conv1DFlipout(
filters=filters,
(`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
distributions.
- Arguments:
- filters: Integer, the dimensionality of the output space (i.e. the number
- of filters in the convolution).
- kernel_size: An integer or tuple/list of 2 integers, specifying the
- height and width of the 2D convolution window.
- Can be a single integer to specify the same value for
- all spatial dimensions.
- strides: An integer or tuple/list of 2 integers,
- specifying the strides of the convolution along the height and width.
- Can be a single integer to specify the same value for
- all spatial dimensions.
- Specifying any stride value != 1 is incompatible with specifying
- any `dilation_rate` value != 1.
- padding: One of `"valid"` or `"same"` (case-insensitive).
- data_format: A string, one of `channels_last` (default) or `channels_first`.
- The ordering of the dimensions in the inputs.
- `channels_last` corresponds to inputs with shape
- `(batch, height, width, channels)` while `channels_first` corresponds to
- inputs with shape `(batch, channels, height, width)`.
-
- dilation_rate: An integer or tuple/list of 2 integers, specifying
- the dilation rate to use for dilated convolution.
- Can be a single integer to specify the same value for
- all spatial dimensions.
- Currently, specifying any `dilation_rate` value != 1 is
- incompatible with specifying any stride value != 1.
- activation: Activation function. Set it to None to maintain a
- linear activation.
- activity_regularizer: Optional regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- seed: Python scalar `int` which initializes the random number
- generator. Default value: `None` (i.e., use global seed).
- name: A string, the name of the layer.
-
Properties:
filters: Python integer, dimensionality of the output space.
kernel_size: Size of the convolution window.
[1]: "Flipout: Efficient Pseudo-Independent Weight Perturbations on
Mini-Batches."
- Anonymous. OpenReview, 2017.
- https://openreview.net/forum?id=rJnpifWAb
+ Yeming Wen, Paul Vicol, Jimmy Ba, Dustin Tran, Roger Grosse.
+ International Conference on Learning Representations, 2018.
"""
+ @docstring_util.expand_docstring(args=doc_args)
def __init__(
self,
filters,
seed=None,
name=None,
**kwargs):
+ """Construct layer.
+
+ Args:
+ filters: Integer, the dimensionality of the output space (i.e. the number
+ of filters in the convolution).
+ kernel_size: An integer or tuple/list of 2 integers, specifying the
+ height and width of the 2D convolution window.
+ Can be a single integer to specify the same value for
+ all spatial dimensions.
+ strides: An integer or tuple/list of 2 integers,
+ specifying the strides of the convolution along the height and width.
+ Can be a single integer to specify the same value for
+ all spatial dimensions.
+ Specifying any stride value != 1 is incompatible with specifying
+ any `dilation_rate` value != 1.
+ padding: One of `"valid"` or `"same"` (case-insensitive).
+ data_format: A string, one of `channels_last` (default) or
+ `channels_first`. The ordering of the dimensions in the inputs.
+ `channels_last` corresponds to inputs with shape `(batch, height,
+ width, channels)` while `channels_first` corresponds to inputs with
+ shape `(batch, channels, height, width)`.
+ dilation_rate: An integer or tuple/list of 2 integers, specifying
+ the dilation rate to use for dilated convolution.
+ Can be a single integer to specify the same value for
+ all spatial dimensions.
+ Currently, specifying any `dilation_rate` value != 1 is
+ incompatible with specifying any stride value != 1.
+ @{args}
+ """
super(Conv2DFlipout, self).__init__(
rank=2,
filters=filters,
name=name, **kwargs)
+@docstring_util.expand_docstring(args=doc_args)
def conv2d_flipout(
inputs,
filters,
(`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
distributions.
- Arguments:
+ Args:
inputs: Tensor input.
filters: Integer, the dimensionality of the output space (i.e. the number
of filters in the convolution).
`channels_last` corresponds to inputs with shape
`(batch, height, width, channels)` while `channels_first` corresponds to
inputs with shape `(batch, channels, height, width)`.
-
dilation_rate: An integer or tuple/list of 2 integers, specifying
the dilation rate to use for dilated convolution.
Can be a single integer to specify the same value for
all spatial dimensions.
Currently, specifying any `dilation_rate` value != 1 is
incompatible with specifying any stride value != 1.
- activation: Activation function. Set it to None to maintain a
- linear activation.
- activity_regularizer: Optional regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- seed: Python scalar `int` which initializes the random number
- generator. Default value: `None` (i.e., use global seed).
- name: A string, the name of the layer.
+ @{args}
reuse: Boolean, whether to reuse the weights of a previous layer
by the same name.
[1]: "Flipout: Efficient Pseudo-Independent Weight Perturbations on
Mini-Batches."
- Anonymous. OpenReview, 2017.
- https://openreview.net/forum?id=rJnpifWAb
+ Yeming Wen, Paul Vicol, Jimmy Ba, Dustin Tran, Roger Grosse.
+ International Conference on Learning Representations, 2018.
"""
layer = Conv2DFlipout(
filters=filters,
(`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
distributions.
- Arguments:
- filters: Integer, the dimensionality of the output space (i.e. the number
- of filters in the convolution).
- kernel_size: An integer or tuple/list of 3 integers, specifying the
- depth, height and width of the 3D convolution window.
- Can be a single integer to specify the same value for
- all spatial dimensions.
- strides: An integer or tuple/list of 3 integers,
- specifying the strides of the convolution along the depth,
- height and width.
- Can be a single integer to specify the same value for
- all spatial dimensions.
- Specifying any stride value != 1 is incompatible with specifying
- any `dilation_rate` value != 1.
- padding: One of `"valid"` or `"same"` (case-insensitive).
- data_format: A string, one of `channels_last` (default) or `channels_first`.
- The ordering of the dimensions in the inputs.
- `channels_last` corresponds to inputs with shape
- `(batch, depth, height, width, channels)` while `channels_first`
- corresponds to inputs with shape
- `(batch, channels, depth, height, width)`.
- dilation_rate: An integer or tuple/list of 3 integers, specifying
- the dilation rate to use for dilated convolution.
- Can be a single integer to specify the same value for
- all spatial dimensions.
- Currently, specifying any `dilation_rate` value != 1 is
- incompatible with specifying any stride value != 1.
- activation: Activation function. Set it to None to maintain a
- linear activation.
- activity_regularizer: Optional regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- seed: Python scalar `int` which initializes the random number
- generator. Default value: `None` (i.e., use global seed).
- name: A string, the name of the layer.
-
Properties:
filters: Python integer, dimensionality of the output space.
kernel_size: Size of the convolution window.
[1]: "Flipout: Efficient Pseudo-Independent Weight Perturbations on
Mini-Batches."
- Anonymous. OpenReview, 2017.
- https://openreview.net/forum?id=rJnpifWAb
+ Yeming Wen, Paul Vicol, Jimmy Ba, Dustin Tran, Roger Grosse.
+ International Conference on Learning Representations, 2018.
"""
+ @docstring_util.expand_docstring(args=doc_args)
def __init__(
self,
filters,
seed=None,
name=None,
**kwargs):
+ """Construct layer.
+
+ Args:
+ filters: Integer, the dimensionality of the output space (i.e. the number
+ of filters in the convolution).
+ kernel_size: An integer or tuple/list of 3 integers, specifying the
+ depth, height and width of the 3D convolution window.
+ Can be a single integer to specify the same value for
+ all spatial dimensions.
+ strides: An integer or tuple/list of 3 integers,
+ specifying the strides of the convolution along the depth,
+ height and width.
+ Can be a single integer to specify the same value for
+ all spatial dimensions.
+ Specifying any stride value != 1 is incompatible with specifying
+ any `dilation_rate` value != 1.
+ padding: One of `"valid"` or `"same"` (case-insensitive).
+ data_format: A string, one of `channels_last` (default) or
+ `channels_first`. The ordering of the dimensions in the inputs.
+ `channels_last` corresponds to inputs with shape `(batch, depth,
+ height, width, channels)` while `channels_first` corresponds to inputs
+ with shape `(batch, channels, depth, height, width)`.
+ dilation_rate: An integer or tuple/list of 3 integers, specifying
+ the dilation rate to use for dilated convolution.
+ Can be a single integer to specify the same value for
+ all spatial dimensions.
+ Currently, specifying any `dilation_rate` value != 1 is
+ incompatible with specifying any stride value != 1.
+ @{args}
+ """
super(Conv3DFlipout, self).__init__(
rank=3,
filters=filters,
name=name, **kwargs)
+@docstring_util.expand_docstring(args=doc_args)
def conv3d_flipout(
inputs,
filters,
(`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
distributions.
- Arguments:
+ Args:
inputs: Tensor input.
filters: Integer, the dimensionality of the output space (i.e. the number
of filters in the convolution).
all spatial dimensions.
Currently, specifying any `dilation_rate` value != 1 is
incompatible with specifying any stride value != 1.
- activation: Activation function. Set it to None to maintain a
- linear activation.
- activity_regularizer: Optional regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- seed: Python scalar `int` which initializes the random number
- generator. Default value: `None` (i.e., use global seed).
- name: A string, the name of the layer.
+ @{args}
reuse: Boolean, whether to reuse the weights of a previous layer
by the same name.
[1]: "Flipout: Efficient Pseudo-Independent Weight Perturbations on
Mini-Batches."
- Anonymous. OpenReview, 2017.
- https://openreview.net/forum?id=rJnpifWAb
+ Yeming Wen, Paul Vicol, Jimmy Ba, Dustin Tran, Roger Grosse.
+ International Conference on Learning Representations, 2018.
"""
layer = Conv3DFlipout(
filters=filters,
from __future__ import division
from __future__ import print_function
+from tensorflow.contrib.bayesflow.python.ops import docstring_util
from tensorflow.contrib.bayesflow.python.ops import layers_util
from tensorflow.contrib.distributions.python.ops import independent as independent_lib
from tensorflow.python.framework import dtypes
from tensorflow.python.ops.distributions import util as distribution_util
+doc_args = """ units: Integer or Long, dimensionality of the output space.
+ activation: Activation function (`callable`). Set it to None to maintain a
+ linear activation.
+ activity_regularizer: Regularizer function for the output.
+ trainable: Boolean, if `True` also add variables to the graph collection
+ `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
+ kernel_posterior_fn: Python `callable` which creates
+ `tf.distributions.Distribution` instance representing the surrogate
+ posterior of the `kernel` parameter. Default value:
+ `default_mean_field_normal_fn()`.
+ kernel_posterior_tensor_fn: Python `callable` which takes a
+ `tf.distributions.Distribution` instance and returns a representative
+ value. Default value: `lambda d: d.sample()`.
+ kernel_prior_fn: Python `callable` which creates `tf.distributions`
+ instance. See `default_mean_field_normal_fn` docstring for required
+ parameter signature.
+ Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
+ kernel_divergence_fn: Python `callable` which takes the surrogate posterior
+ distribution, prior distribution and random variate sample(s) from the
+ surrogate posterior and computes or approximates the KL divergence. The
+ distributions are `tf.distributions.Distribution`-like instances and the
+ sample is a `Tensor`.
+ bias_posterior_fn: Python `callable` which creates
+ `tf.distributions.Distribution` instance representing the surrogate
+ posterior of the `bias` parameter. Default value:
+ `default_mean_field_normal_fn(is_singular=True)` (which creates an
+ instance of `tf.distributions.Deterministic`).
+ bias_posterior_tensor_fn: Python `callable` which takes a
+ `tf.distributions.Distribution` instance and returns a representative
+ value. Default value: `lambda d: d.sample()`.
+ bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
+ See `default_mean_field_normal_fn` docstring for required parameter
+ signature. Default value: `None` (no prior, no variational inference)
+ bias_divergence_fn: Python `callable` which takes the surrogate posterior
+ distribution, prior distribution and random variate sample(s) from the
+ surrogate posterior and computes or approximates the KL divergence. The
+ distributions are `tf.distributions.Distribution`-like instances and the
+ sample is a `Tensor`.
+ seed: Python scalar `int` which initializes the random number
+ generator. Default value: `None` (i.e., use global seed).
+ name: Python `str`, the name of the layer. Layers with the same name will
+ share `tf.Variable`s, but to avoid mistakes we require `reuse=True` in
+ such cases.
+ reuse: Python `bool`, whether to reuse the `tf.Variable`s of a previous
+ layer by the same name."""
+
+
class _DenseVariational(layers_lib.Layer):
"""Abstract densely-connected class (private, used as implementation base).
(`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
distributions.
- Args:
- units: Integer or Long, dimensionality of the output space.
- activation: Activation function (`callable`). Set it to None to maintain a
- linear activation.
- activity_regularizer: Regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- name: Python `str`, the name of the layer. Layers with the same name will
- share `tf.Variable`s, but to avoid mistakes we require `reuse=True` in
- such cases.
- reuse: Python `bool`, whether to reuse the `tf.Variable`s of a previous
- layer by the same name.
-
Properties:
units: Python integer, dimensionality of the output space.
activation: Activation function (`callable`).
bias_divergence_fn: `callable` returning divergence.
"""
+ @docstring_util.expand_docstring(args=doc_args)
def __init__(
self,
units,
bias_divergence_fn=lambda q, p, ignore: kl_lib.kl_divergence(q, p),
name=None,
**kwargs):
+ """Construct layer.
+
+ Args:
+ @{args}
+ """
super(_DenseVariational, self).__init__(
trainable=trainable,
name=name,
(`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
distributions.
- Args:
- units: Integer or Long, dimensionality of the output space.
- activation: Activation function (`callable`). Set it to None to maintain a
- linear activation.
- activity_regularizer: Regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- name: Python `str`, the name of the layer. Layers with the same name will
- share `tf.Variable`s, but to avoid mistakes we require `reuse=True` in
- such cases.
- reuse: Python `bool`, whether to reuse the `tf.Variable`s of a previous
- layer by the same name.
-
Properties:
units: Python integer, dimensionality of the output space.
activation: Activation function (`callable`).
International Conference on Learning Representations, 2014.
"""
+ @docstring_util.expand_docstring(args=doc_args)
def __init__(
self,
units,
bias_divergence_fn=lambda q, p, ignore: kl_lib.kl_divergence(q, p),
name=None,
**kwargs):
+ """Construct layer.
+
+ Args:
+ @{args}
+ """
super(DenseReparameterization, self).__init__(
units=units,
activation=activation,
return self._matmul(inputs, self.kernel_posterior_tensor)
+@docstring_util.expand_docstring(args=doc_args)
def dense_reparameterization(
inputs,
units,
Args:
inputs: Tensor input.
- units: Integer or Long, dimensionality of the output space.
- activation: Activation function (`callable`). Set it to None to maintain a
- linear activation.
- activity_regularizer: Regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- name: Python `str`, the name of the layer. Layers with the same name will
- share `tf.Variable`s, but to avoid mistakes we require `reuse=True` in
- such cases.
- reuse: Python `bool`, whether to reuse the `tf.Variable`s of a previous
- layer by the same name.
+ @{args}
Returns:
output: `Tensor` representing a the affine transformed input under a random
(`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
distributions.
- Args:
- units: Integer or Long, dimensionality of the output space.
- activation: Activation function (`callable`). Set it to None to maintain a
- linear activation.
- activity_regularizer: Regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- name: Python `str`, the name of the layer. Layers with the same name will
- share `tf.Variable`s, but to avoid mistakes we require `reuse=True` in
- such cases.
- reuse: Python `bool`, whether to reuse the `tf.Variable`s of a previous
- layer by the same name.
-
Properties:
units: Python integer, dimensionality of the output space.
activation: Activation function (`callable`).
Neural Information Processing Systems, 2015.
"""
+ @docstring_util.expand_docstring(args=doc_args)
def __init__(
self,
units,
bias_divergence_fn=lambda q, p, ignore: kl_lib.kl_divergence(q, p),
name=None,
**kwargs):
+ """Construct layer.
+
+ Args:
+ @{args}
+ """
super(DenseLocalReparameterization, self).__init__(
units=units,
activation=activation,
return self.kernel_posterior_affine_tensor
+@docstring_util.expand_docstring(args=doc_args)
def dense_local_reparameterization(
inputs,
units,
Args:
inputs: Tensor input.
- units: Integer or Long, dimensionality of the output space.
- activation: Activation function (`callable`). Set it to None to maintain a
- linear activation.
- activity_regularizer: Regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- name: Python `str`, the name of the layer. Layers with the same name will
- share `tf.Variable`s, but to avoid mistakes we require `reuse=True` in
- such cases.
- reuse: Python `bool`, whether to reuse the `tf.Variable`s of a previous
- layer by the same name.
+ @{args}
Returns:
output: `Tensor` representing a the affine transformed input under a random
(`q(W|x)`), prior (`p(W)`), and divergence for both the `kernel` and `bias`
distributions.
- Args:
- units: Integer or Long, dimensionality of the output space.
- activation: Activation function (`callable`). Set it to None to maintain a
- linear activation.
- activity_regularizer: Regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- seed: Python scalar `int` which initializes the random number
- generator. Default value: `None` (i.e., use global seed).
- name: Python `str`, the name of the layer. Layers with the same name will
- share `tf.Variable`s, but to avoid mistakes we require `reuse=True` in
- such cases.
- reuse: Python `bool`, whether to reuse the `tf.Variable`s of a previous
- layer by the same name.
-
Properties:
units: Python integer, dimensionality of the output space.
activation: Activation function (`callable`).
https://openreview.net/forum?id=rJnpifWAb
"""
+ @docstring_util.expand_docstring(args=doc_args)
def __init__(
self,
units,
seed=None,
name=None,
**kwargs):
+ """Construct layer.
+
+ Args:
+ @{args}
+ """
super(DenseFlipout, self).__init__(
units=units,
activation=activation,
return outputs
+@docstring_util.expand_docstring(args=doc_args)
def dense_flipout(
inputs,
units,
Args:
inputs: Tensor input.
- units: Integer or Long, dimensionality of the output space.
- activation: Activation function (`callable`). Set it to None to maintain a
- linear activation.
- activity_regularizer: Regularizer function for the output.
- trainable: Boolean, if `True` also add variables to the graph collection
- `GraphKeys.TRAINABLE_VARIABLES` (see `tf.Variable`).
- kernel_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `kernel` parameter. Default value:
- `default_mean_field_normal_fn()`.
- kernel_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- kernel_prior_fn: Python `callable` which creates `tf.distributions`
- instance. See `default_mean_field_normal_fn` docstring for required
- parameter signature.
- Default value: `tf.distributions.Normal(loc=0., scale=1.)`.
- kernel_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- bias_posterior_fn: Python `callable` which creates
- `tf.distributions.Distribution` instance representing the surrogate
- posterior of the `bias` parameter. Default value:
- `default_mean_field_normal_fn(is_singular=True)` (which creates an
- instance of `tf.distributions.Deterministic`).
- bias_posterior_tensor_fn: Python `callable` which takes a
- `tf.distributions.Distribution` instance and returns a representative
- value. Default value: `lambda d: d.sample()`.
- bias_prior_fn: Python `callable` which creates `tf.distributions` instance.
- See `default_mean_field_normal_fn` docstring for required parameter
- signature. Default value: `None` (no prior, no variational inference)
- bias_divergence_fn: Python `callable` which takes the surrogate posterior
- distribution, prior distribution and random variate sample(s) from the
- surrogate posterior and computes or approximates the KL divergence. The
- distributions are `tf.distributions.Distribution`-like instances and the
- sample is a `Tensor`.
- seed: Python scalar `int` which initializes the random number
- generator. Default value: `None` (i.e., use global seed).
- name: Python `str`, the name of the layer. Layers with the same name will
- share `tf.Variable`s, but to avoid mistakes we require `reuse=True` in
- such cases.
- reuse: Python `bool`, whether to reuse the `tf.Variable`s of a previous
- layer by the same name.
+ @{args}
Returns:
output: `Tensor` representing a the affine transformed input under a random