Mediant approximation trick

2024-01-08 04:36
文章标签 trick approximation mediant

本文主要是介绍Mediant approximation trick,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

近似值的一个取值技巧

如果知道一个数值变量的上限和下限,那么有一种快速的方法,快速获取该变量更准确的近似值。

比如,已知变量e的大小范围是19/7 < e < 87/32,就可以快速得到它的近似值。

Suppose you are trying to approximate some number x and you’ve got it sandwiched between two rational numbers:

a/b < x < c/d.

Now you’d like a better approximation. What would you do?

The obvious approach would be to take the average of a/b and c/d. That’s fine, except it could be a fair amount of work if you’re doing this in your head.

I recently stumbled across an article [1] that suggested taking the mediant of the two fractions rather than the mean. The mediant of two fractions simply adds the numerators and denominators, the very thing you might have gotten your hand slapped for doing in elementary school. It’s not a valid way to add two fractions, but it is a valid way to get a new fraction between two fractions. That is,

a/b < (a + c)/(b + d) < c/d.

So the mediant of a lower bound and an upper bound is going to be a better approximation than either bound.

There are two advantages to using the mediant rather than the mean:

  1. It’s easier to compute mentally.
  2. It generally results in smaller numerators and denominators.

For example, suppose you know that 19/7 and 87/32 are both approximations to e, with

19/7 < e < 87/32.

Then (19 + 87)/(7 + 32) = 106/39 should be better than either of the previous approximations.

Here’s a little Python calculation to illustrate that this is the case.

    >>> from math import exp>>> e = exp(1)>>> 19/7 - e-0.003996114173330678>>> 87/32 - e0.0004681715409549092>>> 106/39 - e-0.0003331105103270282

So 106/39 is an order of magnitude more accurate an approximation to e than 19/7 is. The approximation 106/39 is also more accurate than 87/32, though it’s not as much an improvement over 87/32 as it was over 19/7.

You might notice that while 87/32 overestimates e, 106/39 underestimates e, and by roughly the same amount. This suggests repeating our process would give an even better approximation. Let’s check it out.

The mediant of 87/32 and 106/39 is 193/71.

    >>> 193/71 - e2.8030695884417867e-05

This shows that 193/71 is an order of magnitude better than 106/39 as an approximation to e.

Here’s a plot of the last three approximations.

好图

Related posts

  • Mentally computing mathematical functions
  • Mentally calculating day of the week in 2023

[1] Tom M. Apostol and Mamikon A. Mnatsakanian. Good Rational Approximations to Logarithms. The College Mathematics Journal, May, 2001, Vol. 32, No. 3. pp. 172–179.

这篇关于Mediant approximation trick的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/582332

相关文章

What is Approximation Ratio?

Approximation Ratio 近似比率是用来衡量一个算法找到的近似解与最优解之间的差距的一个量化指标. 假设有一个优化问题,其最优解的值是OPT,用时间T,而我们的算法得到的解的值是ALG,用时间t。如果算法有一个2的近似比率,那么我们可以保证ALG ≤ 2 * OPT and t ≤ 2 * T。这意味着算法找到的解的“成本(时间)”和“答案”不会超过最优解的两倍。

MATH36022 Numerical Analysis 2 Approximation of Functions – Week 3 Exercises

Show that the Chebyshev polynomials are orthogonal on ( − 1 , 1 ) (−1, 1) (−1,1) with respect to the weight function ( 1 − x 2 ) − 1 / 2 (1 − x^2)^{−1/2} (1−x2)−1/2. Ans: T n ( x ) = cos ⁡ ( n arcc

MATH36022 Numerical Analysis 2 Approximation of Functions – Week 2 Exercises

Attempt these exercises in advance of the tutorial in Week 3 Find the best L ∞ L_\infin L∞​ approximation to f ( x ) = x n + 1 + ∑ k = 0 n a k x k f (x) = x^{n+1} + \sum_{k=0}^na_kx^k f(x)=xn+1+∑k=

MemSQL Start[c]UP 2.0 - Round 1 C. Magic Trick

Codeforces MemSQL Start[c]UP 2.0 - Round 1 C. Magic Trick 首先,我们先假设有抽出的牌样式为A 则,抽到同样的牌(不是同样类型)的概率为 1 / N 则,抽到不同的牌的概率为 N-1 / N 此时抽到A类型的概率为,在原来的N*M张中去掉我们最先抽出的一张A,再从中抽出剩下的 M-1张A类牌 综上所述,答案为 1 / N + (

小trick之tools

以前写布局时为了观看布局效果,会写些静态的测试数据,以便在androidstudio中观察布局的效果.等到写完布局的时候在进行擦除.当布局很多的时候,这确实也是很费劲的事.其实官方早就为我们考虑到这点了. 我们在实际开发中可以使用tools. tools可以覆盖我们的属性,但是运行时这些属性是被忽略的 如: <?xml version="1.0" encoding="utf-8"?><L

HuggingFace烧钱做了一大批实验,揭示多模态大模型哪些trick真正有效

构建多模态大模型时有很多有效的trick,如采用交叉注意力机制融合图像信息到语言模型中,或直接将图像隐藏状态序列与文本嵌入序列结合输入至语言模型。 但是这些trick为什么有效,其计算效率如何,往往解释得很粗略或者或者缺乏充分的实验验证。 Hugging Face团队最近进行了广泛的实验以验证在构建多模态大模型时哪些trick是真正有效的,得出了一系列极具参考价值的结论,甚至推翻了以往文献中普

小学生都能懂的 UMAP(Uniform Manifold Approximation and Projection)说明

小学生都能懂的 UMAP(Uniform Manifold Approximation and Projection)说明 1. 什么是UMAP?2. UMAP有什么用?3. 示例解释3-1. 故事:给颜色分类 4. 简单代码示例4-1. 解释 1. 什么是UMAP? UMAP(Uniform Manifold Approximation and Projection)是一种数

Reparameterization Trick

之前在学蒸馏的时候接触了gumbel-softmax,顺势了解了一下重参数技巧,还是很有意思的一个东西 引入 重参数技巧主要是尝试对这样形式的一个东西求梯度 L θ = E z ∼ p θ ( z ) [ f θ ( z ) ] ( 1 ) \large L_{\theta} = E_{z\sim p_{\theta}(z)}[f_{\theta}(z)] \quad \quad(1) Lθ

一些很有用很 trick 的命令

Git 篇 在commit之前撤销 git add 操作 (undo git add before commit),此处. 意为当前目录下。 git rm -r --cached .

trick:CSS 3+checkbox实现JQuery的6个基本动画效果

在JQuery中,有六个基本动画函数:show()/hide()、fadeIn()/fadeOut()、slideUp()/slideDown()。这篇文章,就利用CSS3+checkbox实现这六个基本动画。 show()/hide()的实现 show()/hide()的实现主要控制元素的display属性。 html: <div id="box"><input type="checkb