codecamp

TensorFlow Monte Carlo期望值计算

tf.contrib.bayesflow.monte_carlo.expectation

expectation( 
    f , 
    p , 
    z = none, 
    n = none, 
    seed = none, 
    name = 'expectation' 
)

定义在tensorflow/contrib/bayesflow/python/ops/monte_carlo_impl.py.

参见指南:贝叶斯蒙特卡罗(contrib)>行动

蒙特卡罗估计的期望:E_p[f(Z)] 与样本具有均值.

该操作返回:

n ^ { - 1 } sum_ {i= 1 } ^ n f( z_i ),where z_i 〜 p
\approx E_p[f(Z)]

ARGS:

  • f:从 p 到张量的可调用映射样本.
  • p:tf.contrib.distributions.Distribution.
  • z:p 样品的张量,由 p.sample 为一些 n 生成.
  • n:整数张量.如果未提供z生成的样本数.
  • seed:Python整数来寻找随机数程序.
  • name:为该操作提供一个名字.

返回:

与一个 Tensor 具有相同 dtype 的 p,举例:

N_samples =  10000
distribute = 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


TensorFlow 计算Renyi分歧
TensorFlow Monte Carlo重要性抽样估计
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

TensorFlow 函数介绍

TensorFlow 函数模块:tf

TensorFlow的image模块

TensorFlow使用之tf.io

TensorFlow使用之tf.keras

TensorFlow函数教程:tf.keras.applications

TensorFlow函数教程:tf.keras.backend

TensorFlow使用之tf.metrics

TensorFlow使用之tf.nn

TensorFlow使用之tf.python_io

TensorFlow 功能函数

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }