Python - метод tensorflow.math.betainc ()

Опубликовано: 29 Марта, 2022

TensorFlow - это библиотека Python с открытым исходным кодом, разработанная Google для разработки моделей машинного обучения и нейронных сетей глубокого обучения. betainc () - это метод в математическом модуле тензорного потока, используемый для вычисления регуляризованного неполного бета-интеграла I x (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.

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

Parameters:

  • a: It’s a Tensor. Allowed types are float32 and float64.
  • b: It’s a Tensor of type same as a.
  • x: It’s also a Tensor of type same as a.
  • name: It’s an optional parameter that defines the name for the operation.
     

Return: Returns a tensor of type same as a.
 

Example 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)

Выход:

 Введите a: tf.Tensor ([1. 2. 3. 4. 5.], shape = (5,), dtype = float64)
Вход b: tf.Tensor ([1.5 2.7 3.4 4.9 5.6], shape = (5,), dtype = float64)
Введите x: tf.Tensor ([1. 1. 1. 1. 1.], shape = (5,), dtype = float64)
регуляризованный неполный бета-интеграл: tf.Tensor ([1. 1. 1. 1. 1.], shape = (5,), dtype = float64)


Example 2: This example tries to evaluate regularized incomplete beta integral  with unallowed dtype tensor. This will raise 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)

Выход:

 Введите a: tf.Tensor ([1. + 0.j 2. + 0.j 3. + 0.j 4. + 0.j 5. + 0.j], shape = (5,), dtype = complex128 )
Ввод 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)
Введите x: tf.Tensor ([1. + 0.j 1. + 0.j 1. + 0.j 1. + 0.j 1. + 0.j], shape = (5,), dtype = complex128 )

NotFoundError Traceback (последний вызов последним)

<ipython-input-16-904ce11d62af> в <модуль> ()
      1 # вычисление регуляризованного неполного бета-интеграла
----> 2 риби = tf.math.betainc (a, b, x)

2 кадра

/usr/local/lib/python3.6/dist-packages/six.py в raise_from (значение, from_value)

NotFoundError: не удалось найти допустимое устройство для узла.
Узел: {{node Betainc}}
Все ядра зарегистрированы для op Betainc:
  устройство = 'XLA_CPU_JIT'; Т в [DT_FLOAT, DT_DOUBLE]
  устройство = 'XLA_GPU_JIT'; Т в [DT_FLOAT, DT_DOUBLE]
  устройство = 'XLA_CPU'; Т в [DT_FLOAT, DT_DOUBLE]
  устройство = 'XLA_GPU'; Т в [DT_FLOAT, DT_DOUBLE]
  device = 'GPU'; Т в [DT_DOUBLE]
  device = 'GPU'; Т в [DT_FLOAT]
  device = 'CPU'; Т в [DT_DOUBLE]
  device = 'CPU'; Т в [DT_FLOAT]


Внимание компьютерщик! Укрепите свои основы с помощью базового курса программирования Python и изучите основы.

Для начала подготовьтесь к собеседованию. Расширьте свои концепции структур данных с помощью курса Python DS. А чтобы начать свое путешествие по машинному обучению, присоединяйтесь к курсу Машинное обучение - базовый уровень.