Path: blob/master/site/en-snapshot/probability/examples/Learnable_Distributions_Zoo.ipynb
25118 views
Kernel: Python 3
Copyright 2019 The TensorFlow Probability Authors.
Licensed under the Apache License, Version 2.0 (the "License");
In [ ]:
Learnable Distributions Zoo
In this colab we show various examples of building learnable ("trainable") distributions. (We make no effort to explain the distributions, only to show how to build them.)
In [ ]:
In [ ]:
Learnable Multivariate Normal with Scaled Identity for chol(Cov)
In [ ]:
tfp.distributions.Independent("learnable_mvn_scaled_identity", batch_shape=[], event_shape=[4], dtype=float32)
(<tf.Variable 'loc:0' shape=(4,) dtype=float32, numpy=array([0., 0., 0., 0.], dtype=float32)>, <tf.Variable 'scale:0' shape=(1,) dtype=float32, numpy=array([0.], dtype=float32)>)
Learnable Multivariate Normal with Diagonal for chol(Cov)
In [ ]:
tfp.distributions.Independent("learnable_mvn_diag", batch_shape=[], event_shape=[4], dtype=float32)
(<tf.Variable 'loc:0' shape=(4,) dtype=float32, numpy=array([0., 0., 0., 0.], dtype=float32)>, <tf.Variable 'scale:0' shape=(4,) dtype=float32, numpy=array([0.54132485, 0.54132485, 0.54132485, 0.54132485], dtype=float32)>)
Mixture of Multivarite Normal (spherical)
In [ ]:
tfp.distributions.MixtureSameFamily("learnable_mix_mvn_scaled_identity", batch_shape=[], event_shape=[4], dtype=float32)
(<tf.Variable 'logits:0' shape=(3,) dtype=float32, numpy=array([-0., -0., -0.], dtype=float32)>, <tf.Variable 'loc:0' shape=(3, 4) dtype=float32, numpy=
array([[ 0.21316044, 0.18825649, 1.3055958 , -1.4072137 ],
[-1.6604203 , -0.9415946 , -1.1349488 , -0.4928658 ],
[-0.9672405 , 0.45094398, -2.615817 , 3.7891428 ]],
dtype=float32)>, <tf.Variable 'scale:0' shape=(3, 1) dtype=float32, numpy=
array([[9.999954],
[9.999954],
[9.999954]], dtype=float32)>)
Mixture of Multivariate Normal (spherical) with first mix weight unlearnable
In [ ]:
tfp.distributions.MixtureSameFamily("learnable_mix_mvndiag_first_fixed", batch_shape=[], event_shape=[4], dtype=float32)
(<tf.Variable 'Variable:0' shape=(2,) dtype=float32, numpy=array([-0.4054651, -0.8109302], dtype=float32)>, <tf.Variable 'loc:0' shape=(3, 4) dtype=float32, numpy=
array([[ 1., 1., -1., -1.],
[ 1., -1., 1., 1.],
[-1., 1., -1., -1.]], dtype=float32)>, <tf.Variable 'scale:0' shape=(3, 1) dtype=float32, numpy=
array([[9.999954],
[9.999954],
[9.999954]], dtype=float32)>)
Mixture of Multivariate Normal (full Cov
)
In [ ]:
tfp.distributions.MixtureSameFamily("learnable_mix_mvntril", batch_shape=[], event_shape=[4], dtype=float32)
(<tf.Variable 'loc:0' shape=(3, 4) dtype=float32, numpy=
array([[0., 0., 0., 0.],
[0., 0., 0., 0.],
[0., 0., 0., 0.]], dtype=float32)>, <tf.Variable 'scale_tril:0' shape=(3, 10) dtype=float32, numpy=
array([[9.999945, 0. , 0. , 0. , 9.999945, 9.999945,
0. , 0. , 0. , 9.999945],
[9.999945, 0. , 0. , 0. , 9.999945, 9.999945,
0. , 0. , 0. , 9.999945],
[9.999945, 0. , 0. , 0. , 9.999945, 9.999945,
0. , 0. , 0. , 9.999945]], dtype=float32)>, <tf.Variable 'logits:0' shape=(3,) dtype=float32, numpy=array([-0., -0., -0.], dtype=float32)>)
Mixture of Multivariate Normal (full Cov
) with unlearnable first mix & first component
In [ ]:
tfp.distributions.MixtureSameFamily("learnable_mix_mvntril_fixed_first", batch_shape=[], event_shape=[4], dtype=float32)
(<tf.Variable 'loc:0' shape=(2, 4) dtype=float32, numpy=
array([[0., 0., 0., 0.],
[0., 0., 0., 0.]], dtype=float32)>, <tf.Variable 'scale_tril:0' shape=(2, 10) dtype=float32, numpy=
array([[9.999945, 0. , 0. , 0. , 9.999945, 9.999945,
0. , 0. , 0. , 9.999945],
[9.999945, 0. , 0. , 0. , 9.999945, 9.999945,
0. , 0. , 0. , 9.999945]], dtype=float32)>, <tf.Variable 'logits:0' shape=(2,) dtype=float32, numpy=array([-0., -0.], dtype=float32)>)