exp()函数 快速算法实现
来源:互联网 发布:jisucopy什么软件 编辑:程序博客网 时间:2024/05/09 07:23
Using Faster Exponential Approximation
In some scenarios/applicatons, where the precision may not be so critically important but the speed (performance) is, you may be willing to sacrifice some extent of accuracy for the speed.
In neutral networks, where the math function where n is usually small (less than 2, for instance), you can avoid the expensive exp() provided by math.h (for other programming languages, similar inbuilt system functions are provided)
The (exponential function) can be considered as the following:
In practice, n cannot approach to the infinity but we can achieve a relatively good accuracy by using a large n.
For example, if we put , then we can multiply by itself 8 times due to the fact
With this in mind, we can come up with the following approximation:
inlinedouble exp1(double x) { x = 1.0 + x / 256.0; x *= x; x *= x; x *= x; x *= x; x *= x; x *= x; x *= x; x *= x; return x;}
We can also multiply a few more times, to increase the accuracy.
inlinedouble exp2(double x) { x = 1.0 + x / 1024; x *= x; x *= x; x *= x; x *= x; x *= x; x *= x; x *= x; x *= x; x *= x; x *= x; return x;}
Now, you have the pattern, but for now, we need to test how accurate these approximations are:
The above plots 3 curves, which are the exp provided by math.h, the exp 256 and the exp 1024. They show very good agreement for input smaller than 5.
We plot the difference to make it easier to see.
Wow, it really can be a faster alternative if the required input range smaller than 5. For negative inputs, the difference won’t be so noticeable because the value itself is so tiny that can’t be observed visually in graph.
The exp 256 is 360 times faster than the traditional exp and the exp 1024 is 330 times faster than the traditional exp.
- exp()函数 快速算法实现
- 快速浮点数exp算法
- 快速排序算法 函数实现
- java和C中exp 指数和对数函数的快速实现
- 素数的算法 普通算法 函数实现 和 快速算法
- exp () 函数
- Exp 函数
- 用函数指针实现的快速排序算法
- 快速排序算法函数
- matlab2c使用c++实现matlab函数系列教程-exp函数
- 快速排序算法实现
- 快速排序算法实现
- 快速排序算法实现
- 快速排序算法实现
- 快速幂取模算法实现
- 实现快速排序算法
- 快速排序算法实现
- 快速排序算法实现
- Android绘制简单图形
- iPhone/iPad利用系统MFMailComposeViewController调用系统邮件
- 【机器学习基础】从感知机模型说起
- tightvnc 2.7.10 vs2008 编译
- hdu 1257 最少拦截系统
- exp()函数 快速算法实现
- 【软件工程】面向对象的设计
- View的显示和隐藏动画
- 【机器学习基础】理解为什么机器可以学习1——PAC学习模型
- Html之超链接
- 关于在MyEclipse2014中导入jquery-easyui-1.4.1,MyEclipse中js文件报错的解释
- SIGTERM、SIGKILL、SIGINT和SIGQUIT的区别
- 如何在ubuntu中修改init的值
- 最简单的兼容firefox和ie的锚点方法(转载)