1

tensorflow 内部函数支持 Bessel 函数 BesselI tensorflow besseli0

但是,它没有 BesselJ 函数(尤其是 BesselJ[2,x])。

如果我要逼近这个函数,我将不得不If在 tensorflow 中使用,这不是有效的。

tensorflow 是否有任何替代或任何其他可以推荐的方法?

4

1 回答 1

2

经过多次搜索,我找到了一个令人满意的解决方案:

def BesselJ0(x):
    PI=3.1415926
    temp = tf.cast(tf.less(x,tf.ones_like(x)*4.7),dtype=tf.float32)
    temp1 = tf.abs(temp-1)
    left_part = tf.multiply(1-x**2/4+x**4/64-x**6/2304+x**8/147456-x**10/14745600,temp)
    right_part = tf.multiply(tf.sqrt(2/PI/x)*tf.cos(x-PI/4),temp1)
    return left_part+right_part
def BesselJ1(x):
    PI=3.1415926
    temp = tf.cast(tf.less(x,tf.ones_like(x)*3.8),dtype=tf.float32)
    temp1 = tf.abs(temp-1)
    left_part = tf.multiply(x/2-x**3/16+x**5/384-x**7/18432+x**9/1474560-x**11/176947200+x**13/29727129600,temp)
    right_part = tf.multiply(tf.sqrt(2/PI/x)*tf.cos(x-PI/2-PI/4),temp1)
    return left_part+right_part

不过,这不是很快。

于 2018-10-03T00:53:48.157 回答