當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python tensorflow.math.betainc()用法及代碼示例

TensorFlow是Google設計的開源python庫,用於開發機器學習模型和深度學習神經網絡。 betainc()是tensorflow數學模塊中的方法,用於計算正則化的不完全beta積分Ix(a,b)。

Regularized incomplete beta integral Ix(a,b)  is defines as:

 Ix(a,b) = B(x;a,b)/B(a,b)

where,

B(x;a,b) is incomplete beta function and is defined as:



B(x;a,b) = ?xo ta-1(1-t)b-1 dt

and B(a,b) is complete beta function.

用法:tensorflow.math.betainc(  a, b, x, name)
 

參數:

  • a:是張量允許的類型為float32和float64。
  • b:它是與類型相同的張量。
  • x:它也是與a相同類型的張量。
  • name:這是一個可選參數,用於定義操作的名稱。

返回:返回與a類型相同的張量。

範例1:

Python3

# importing the library 
import tensorflow as tf 
  
# initializing the constant tensors 
a = tf.constant([1,2,3,4,5], dtype = tf.float64) 
b = tf.constant([1.5,2.7,3.4,4.9,5.6], dtype = tf.float64) 
x = tf.constant( [1,1,1,1,1], dtype = tf.float64) 
  
# printing the input tensors 
print('Input a:',a) 
print('Input b:',b) 
print('Input x:',x) 
  
# calculating the regularized incomplete beta integral  
ribi = tf.math.betainc(a,b,x) 
  
# printing the result 
print('regularized incomplete beta integral:',ribi)

輸出:

Input a: tf.Tensor([1. 2. 3. 4. 5.], shape=(5,), dtype=float64)
Input b: tf.Tensor([1.5 2.7 3.4 4.9 5.6], shape=(5,), dtype=float64)
Input x: tf.Tensor([1. 1. 1. 1. 1.], shape=(5,), dtype=float64)
regularized incomplete beta integral: tf.Tensor([1. 1. 1. 1. 1.], shape=(5,), dtype=float64)


範例2:此示例嘗試使用不允許的dtype張量評估正則化的不完全beta積分。這將引發NotFoundError。

Python3

# importing the library 
import tensorflow as tf 
  
# initializing the constant tensors 
a = tf.constant([1,2,3,4,5], dtype = tf.complex128) 
b = tf.constant([1.5,2.7,3.4,4.9,5.6], dtype = tf.complex128) 
x = tf.constant( [1,1,1,1,1], dtype = tf.complex128) 
  
# printing the input tensors 
print('Input a:',a) 
print('Input b:',b) 
print('Input x:',x) 
  
# calculating the regularized incomplete beta integral  
ribi = tf.math.betainc(a,b,x)

輸出:

Input a: tf.Tensor([1.+0.j 2.+0.j 3.+0.j 4.+0.j 5.+0.j], shape=(5,), dtype=complex128)
Input b: tf.Tensor([1.5+0.j 2.7+0.j 3.4+0.j 4.9+0.j 5.6+0.j], shape=(5,), dtype=complex128)
Input x: tf.Tensor([1.+0.j 1.+0.j 1.+0.j 1.+0.j 1.+0.j], shape=(5,), dtype=complex128)

NotFoundError                             Traceback (most recent call last)

<ipython-input-16-904ce11d62af> in <module>()
      1 # calculating the regularized incomplete beta integral
----> 2 ribi = tf.math.betainc(a,b,x)

2 frames

/usr/local/lib/python3.6/dist-packages/six.py in raise_from(value, from_value)

NotFoundError:Could not find valid device for node.
Node:{{node Betainc}}
All kernels registered for op Betainc:
  device='XLA_CPU_JIT'; T in [DT_FLOAT, DT_DOUBLE]
  device='XLA_GPU_JIT'; T in [DT_FLOAT, DT_DOUBLE]
  device='XLA_CPU'; T in [DT_FLOAT, DT_DOUBLE]
  device='XLA_GPU'; T in [DT_FLOAT, DT_DOUBLE]
  device='GPU'; T in [DT_DOUBLE]
  device='GPU'; T in [DT_FLOAT]
  device='CPU'; T in [DT_DOUBLE]
  device='CPU'; T in [DT_FLOAT]





相關用法


注:本文由純淨天空篩選整理自aman neekhara大神的英文原創作品 Python – tensorflow.math.betainc() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。