How to Create Exponent and Logarithm Operations in TensorFlow
Machine learning applications frequently need exponents and logarithms to compute errors and probability. To meet this need, TensorFlow provides many of the same functions available in NumPy. The following table lists 11 of them and provides a description of each.
Exponential and Logarithmic Operations
||Returns the square of the argument|
||Subtracts the first argument from the second and returns the square|
||Returns the square root of the argument|
||Returns the reciprocal of the square root|
||Returns elements of the first tensor raised to the power of the elements of the second vector|
||Returns the exponential function of the argument|
||Returns the exponential function of the argument minus one, exp(x) – 1|
||Returns the natural logarithm of the argument|
||Returns the natural logarithm of the argument plus 1, log(x + 1)|
||Returns the error function of the argument|
||Returns the complementary error function of the argument|
These functions are straightforward to use and understand. Each executes in an element-wise manner, and the following code demonstrates how you can call
t = tf.constant([4.]) t1 = tf.square(t) # 16 t2 = tf.sqrt(t) # 2 t3 = tf.rsqrt(t) # 0.5
exp function computes the exponential functions of a tensor’s elements, and expm1 subtracts 1 from each exponential. If x is a value in the input tensor, the result of
exp(x) – 1.
Similarly, the log function computes the natural logarithm of a tensor’s elements.
logp1 adds 1 to the value before the logarithm is computed, so if x is a value in the input tensor, the result of
log(x + 1).