- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在用 javascript 做一些数字信号处理计算,我发现计算双曲正切 (tanh) 有点太昂贵了。这就是我目前近似 tanh 的方式:
function tanh (arg) {
// sinh(number)/cosh(number)
return (Math.exp(arg) - Math.exp(-arg)) / (Math.exp(arg) + Math.exp(-arg));
}
有人知道更快的计算方法吗?
最佳答案
来自 here .
function rational_tanh(x)
{
if( x < -3 )
return -1;
else if( x > 3 )
return 1;
else
return x * ( 27 + x * x ) / ( 27 + 9 * x * x );
}
This is a rational function to approximate a tanh-like soft clipper. It is based on the pade-approximation of the tanh function with tweaked coefficients.
The function is in the range x=-3..3 and outputs the range y=-1..1. Beyond this range the output must be clamped to -1..1.
The first to derivatives of the function vanish at -3 and 3, so the transition to the hard clipped region is C2-continuous.
Padé 近似比泰勒展开好几个数量级。夹紧也可能是一个问题(取决于您的范围)。
关于javascript - Javascript 中的快速双曲正切近似,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6118028/
所以我必须用以下方法来近似 Pi:4*(1-1/3+1/5-1/7+1/9-...)。它也应该基于迭代次数。所以函数应该是这样的: >>> piApprox(1) 4.0 >>> piApprox(1
输入:图 G 输出:多个独立集,使得一个节点对所有独立集的成员资格是唯一的。因此,节点与它自己的集合中的任何节点都没有连接。这是一个示例路径。 由于这里需要澄清,因此再次改写: 将给定的图划分为多个集
我已经使用查找表和低阶多项式近似实现了定点 log2 函数,但对整个 32 位定点范围 [-1,+1) 的准确度不太满意。输入格式为 s0.31,输出格式为 s15.16。 我在这里发布这个问题,以便
大多数拥有CS学位的人当然会知道Big O stands for是什么。 它可以帮助我们评估算法的可扩展性。 但是我很好奇,您如何计算或估算算法的复杂性? 最佳答案 我会尽力在这里简单地解释它,但要注
我的目标是近似二项式变量总和的分布。我使用以下纸张The Distribution of a Sum of Binomial Random Variables作者:肯·巴特勒和迈克尔·斯蒂芬斯。 我想
我知道有方法 approximate cubic Bezier curves ( this page 也是一个很好的引用),但是有没有更快的方法来逼近 N 次贝塞尔曲线?还是只能使用下面的概括? 来自
大多数拥有CS学位的人当然会知道Big O stands for是什么。 它有助于我们评估算法的可扩展性。 但是我很好奇,您如何计算或估算算法的复杂性? 最佳答案 我会尽力在这里简单地解释它,但要注意
我是 C++ 和编码本身的初学者,所以请原谅任何词汇错误。我找不到这个具体问题,但在互联网上找到了类似的问题,但我仍然很难获得我需要的结果。 所以我使用莱布尼茨公式来近似 pi,即: pi = 4 ·
有多种方法可以通过显示名称查找联系人。例如这个答案Android - Find a contact by display name 但是我需要找到模糊匹配的联系人。例如如果找不到“Kim”,我需要返回
我一直在尝试使用以下代码使用级数表示来近似 e 以获得尽可能多的精度数字,但无论我计算多少项,精度数字的数量似乎都保持不变。即: 2.718281984329223632812500000000000
大多数拥有CS学位的人当然会知道Big O stands for是什么。 它可以帮助我们评估算法的可扩展性。 但是我很好奇,您如何计算或估算算法的复杂性? 最佳答案 我会尽力在这里简单地解释它,但要注
大多数拥有CS学位的人当然会知道Big O stands for是什么。 它可以帮助我们评估算法的可扩展性。 但是我很好奇,您如何计算或估算算法的复杂性? 最佳答案 我会尽力在这里简单地解释它,但要注
大多数拥有计算机科学学位的人肯定知道什么是Big O stands for。 它有助于我们衡量一个算法的实际效率,如果您知道在what category the problem you are try
大多数拥有计算机科学学位的人肯定知道什么是Big O stands for。 它有助于我们衡量一个算法的实际效率,如果您知道在what category the problem you are try
我做了很多随机的数学程序来帮助我完成作业(合成除法是最有趣的),现在我想反转一个激进的表达式。 例如,在我方便的 TI 计算器中我得到 .2360679775 好吧,我想将该数字转换为等效的无理数表达
我可以通过 CPU 分析器看到,compute_variances() 是我项目的瓶颈。 % cumulative self self total
大多数拥有 CS 学位的人肯定知道什么 Big O stands for . 它帮助我们衡量算法的可扩展性。 但我很好奇,你如何计算或近似算法的复杂性? 最佳答案 我会尽我所能用简单的术语在这里解释它
这是迄今为止我的代码, from math import * def main(): sides = eval(input("Enter the number of sides:"))
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
大多数拥有 CS 学位的人肯定知道什么 Big O stands for . 它帮助我们衡量算法的扩展性。 但我很好奇,你如何计算或近似算法的复杂性? 最佳答案 我会尽我所能用简单的术语在这里解释它,
我是一名优秀的程序员,十分优秀!