加快Java中的数学计算 [英] Speeding up Math calculations in Java

查看:150
本文介绍了加快Java中的数学计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Java编写的神经网络,它使用如下定义的sigmoid传递函数:

  private static double sigmoid( double x)
{
return 1 /(1 + Math.exp(-x));
}

这在训练期间被称为很多次使用网络进行计算。有没有办法加速这个?这并不是说它很慢,只是它被大量使用,所以这里的小优化将是一个很大的整体收益。

解决方案

对于神经网络,您不需要sigmoid函数的确切值。因此,您可以预先计算100个值并重用最接近输入的值,或者甚至更好(如注释所述)从邻居值进行插值。



如何做到这一点在



如您所见,只有-10< x< 10有趣。并且,正如另一条评论所述,该功能是对称的。您只需要存储一半的值。






编辑:我是抱歉,我在这里显示错误的图表。我已经纠正了。


I have a neural network written in Java which uses a sigmoid transfer function defined as follows:

private static double sigmoid(double x)
{
    return 1 / (1 + Math.exp(-x));
}

and this is called many times during training and computation using the network. Is there any way of speeding this up? It's not that it's slow, it's just that it is used a lot, so a small optimisation here would be a big overall gain.

解决方案

For neural networks, you don't need the exact value of the sigmoid function. So you can precalculate 100 values and reuse the value that is closest to your input, or even better (as a comment stated) do an interpolation from the neighbour values.

How you can do this is described in this article (link stolen from the answer of s-lott).

This is the sigmoid function:

As you can see, only values of -10 < x < 10 are interesting at all. And, as another comment stated, the function is symmetric. You only have to store half of the values at all.


Edit: I'm sorry that I showed the wrong graph here. I've corrected it.

这篇关于加快Java中的数学计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆