Spec-Zone.ru › TensorFlow 1.15

tf.contrib.distributions.matrix_diag_transform

Преобразовать диагональ [партш-]матрицы, оставив остальную часть матрицы без изменений.

tf.contrib.distributions.matrix_diag_transform(
    matrix, transform=None, name=None
)

Создать обучаемую ковариацию, определяемую фактором Холецкого:

# Transform network layer into 2 x 2 array.
matrix_values = tf.contrib.layers.fully_connected(activations, 4)
matrix = tf.reshape(matrix_values, (batch_size, 2, 2))

# Make the diagonal positive. If the upper triangle was zero, this would be a
# valid Cholesky factor.
chol = matrix_diag_transform(matrix, transform=tf.nn.softplus)

# LinearOperatorLowerTriangular ignores the upper triangle.
operator = LinearOperatorLowerTriangular(chol)

Пример гетероскедастической 2-мерной линейной регрессии.

tfd = tfp.distributions

# Get a trainable Cholesky factor.
matrix_values = tf.contrib.layers.fully_connected(activations, 4)
matrix = tf.reshape(matrix_values, (batch_size, 2, 2))
chol = matrix_diag_transform(matrix, transform=tf.nn.softplus)

# Get a trainable mean.
mu = tf.contrib.layers.fully_connected(activations, 2)

# This is a fully trainable multivariate normal!
dist = tfd.MultivariateNormalTriL(mu, chol)

# Standard log loss. Minimizing this will "train" mu and chol, and then dist
# will be a distribution predicting labels as multivariate Gaussians.
loss = -1 * tf.reduce_mean(dist.log_prob(labels))
Аргументы
matrix Ранг R Tensor, R >= 2, где последние две размерности равны.
transform Элементная функция, отображающая Tensors в Tensors. Для применения к диагонали matrix. Если None, то matrix возвращается без изменений. По умолчанию None.
name Имя, которое нужно дать созданным операциям. По умолчанию "matrix_diag_transform".
Возвращаемое значение
A Tensor с той же формой и dtype что и matrix.

© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/distributions/matrix_diag_transform

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API