contrib.bayesflow.monte_carlo.expectation
tf.contrib.bayesflow.monte_carlo.expectation
tf.contrib.bayesflow.monte_carlo.expectation
expectation( f, p, z=None, n=None, seed=None, name='expectation' )
Defined in tensorflow/contrib/bayesflow/python/ops/monte_carlo_impl.py
.
See the guide: BayesFlow Monte Carlo (contrib) > Ops
Monte Carlo estimate of an expectation: E_p[f(Z)]
with sample mean.
This Op
returns
n^{-1} sum_{i=1}^n f(z_i), where z_i ~ p \approx E_p[f(Z)]
User supplies either Tensor
of samples z
, or number of samples to draw n
Args:
-
f
: Callable mapping samples fromp
toTensors
. -
p
:tf.contrib.distributions.Distribution
. -
z
:Tensor
of samples fromp
, produced byp.sample
for somen
. -
n
: IntegerTensor
. Number of samples to generate ifz
is not provided. -
seed
: Python integer to seed the random number generator. -
name
: A name to give thisOp
.
Returns:
A Tensor
with the same dtype
as p
.
Example:
N_samples = 10000 distributions = tf.contrib.distributions dist = distributions.Uniform([0.0, 0.0], [1.0, 2.0]) elementwise_mean = lambda x: x mean_sum = lambda x: tf.reduce_sum(x, 1) estimate_elementwise_mean_tf = monte_carlo.expectation(elementwise_mean, dist, n=N_samples) estimate_mean_sum_tf = monte_carlo.expectation(mean_sum, dist, n=N_samples) with tf.Session() as sess: estimate_elementwise_mean, estimate_mean_sum = ( sess.run([estimate_elementwise_mean_tf, estimate_mean_sum_tf])) print estimate_elementwise_mean >>> np.array([ 0.50018013 1.00097895], dtype=np.float32) print estimate_mean_sum >>> 1.49571
© 2017 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/api_docs/python/tf/contrib/bayesflow/monte_carlo/expectation