예제 #1
0
 def test_besseli_boundary(self):
   self.assertAllClose(1., special_math_ops.bessel_i0(0.))
   self.assertAllClose(1., special_math_ops.bessel_i0e(0.))
   self.assertAllClose(0., special_math_ops.bessel_i1(0.))
   self.assertAllClose(0., special_math_ops.bessel_i1e(0.))
   self.assertTrue(np.isnan(self.evaluate(special_math_ops.bessel_i0(np.nan))))
   self.assertTrue(
       np.isnan(self.evaluate(special_math_ops.bessel_i0e(np.nan))))
   self.assertTrue(np.isnan(self.evaluate(special_math_ops.bessel_i1(np.nan))))
   self.assertTrue(
       np.isnan(self.evaluate(special_math_ops.bessel_i1e(np.nan))))
예제 #2
0
  def test_i0j0_even(self, dtype):
    x = np.random.uniform(-100., 100., size=int(1e4)).astype(dtype)
    self.assertAllClose(
        self.evaluate(special_math_ops.bessel_i0(x)),
        self.evaluate(special_math_ops.bessel_i0(-x)))

    self.assertAllClose(
        self.evaluate(special_math_ops.bessel_i0e(x)),
        self.evaluate(special_math_ops.bessel_i0e(-x)))

    self.assertAllClose(
        self.evaluate(special_math_ops.bessel_j0(x)),
        self.evaluate(special_math_ops.bessel_j0(-x)))
예제 #3
0
 def test_besseli_larger(self, dtype):
   x = np.random.uniform(1., 20., size=int(1e4)).astype(dtype)
   try:
     from scipy import special  # pylint: disable=g-import-not-at-top
     self.assertAllClose(
         special.i0e(x), self.evaluate(special_math_ops.bessel_i0e(x)))
     self.assertAllClose(
         special.i1e(x), self.evaluate(special_math_ops.bessel_i1e(x)))
   except ImportError as e:
     tf_logging.warn('Cannot test special functions: %s' % str(e))
예제 #4
0
def kaiser_window(window_length, beta=12., dtype=dtypes.float32, name=None):
    """Generate a [Kaiser window][kaiser].

  Args:
    window_length: A scalar `Tensor` indicating the window length to generate.
    beta: Beta parameter for Kaiser window, see reference below.
    dtype: The data type to produce. Must be a floating point type.
    name: An optional name for the operation.

  Returns:
    A `Tensor` of shape `[window_length]` of type `dtype`.

  [kaiser]:
    https://docs.scipy.org/doc/numpy/reference/generated/numpy.kaiser.html
  """
    with ops.name_scope(name, 'kaiser_window'):
        window_length = _check_params(window_length, dtype)
        window_length_const = tensor_util.constant_value(window_length)
        if window_length_const == 1:
            return array_ops.ones([1], dtype=dtype)
        # tf.range does not support float16 so we work with float32 initially.
        halflen_float = (math_ops.cast(window_length, dtype=dtypes.float32) -
                         1.0) / 2.0
        arg = math_ops.range(-halflen_float,
                             halflen_float + 0.1,
                             dtype=dtypes.float32)
        # Convert everything into given dtype which can be float16.
        arg = math_ops.cast(arg, dtype=dtype)
        beta = math_ops.cast(beta, dtype=dtype)
        one = math_ops.cast(1.0, dtype=dtype)
        two = math_ops.cast(2.0, dtype=dtype)
        halflen_float = math_ops.cast(halflen_float, dtype=dtype)
        num = beta * math_ops.sqrt(one - math_ops.pow(arg, two) /
                                   math_ops.pow(halflen_float, two))
        window = math_ops.exp(num - beta) * (special_math_ops.bessel_i0e(num) /
                                             special_math_ops.bessel_i0e(beta))
    return window