高斯金字塔 拉普拉斯金字塔_金字塔制造者

2023-10-28 16:20

本文主要是介绍高斯金字塔 拉普拉斯金字塔_金字塔制造者,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

高斯金字塔 拉普拉斯金字塔

Recursion is beautiful, and when applied in combination it is truly a form of art. In this story, we are going to implement an interesting algorithm to create pyramids with recursion.

递归是美丽的,结合使用它确实是一种艺术形式。 在这个故事中,我们将实现一个有趣的算法来创建具有递归的金字塔。

Ancient civilizations around the world have built giant pyramids for worship and other holy purposes. The most famous, perhaps, are the pyramids built by the Egyptians. These huge structures are built with white, limestone surfaces so that they appear to be shining when seen from a distance. They are so magnificent, in fact, that many people today still believe that they were built by the aliens. So, today we are going to build them in code with recursion. It is very fitting.

世界各地的古代文明都建造了巨型金字塔,以供崇拜和其他神圣用途。 也许最著名的是埃及人建造的金字塔。 这些巨大的建筑物是用白色石灰石表面建造的,因此从远处看时它们看起来像是在发光。 实际上,它们是如此的宏伟,以至于当今许多人仍然相信它们是由外星人建造的。 因此,今天我们将使用递归代码构建它们。 非常合适。

问题: (Problem:)

Suppose I am given a base like this:

假设给我这样的基础:

[a, b, c ]

[a,b,c]

and that the following triangles are allowed:

并且允许以下三角形:

[aab, bdc, bad]

[AAB,BDC,坏]

what kind of pyramids can I create?

我可以创建哪种金字塔?

Image for post
Base = abc, Allows = [abb, bdc, bad]
基本= abc,允许= [abb,bdc,坏]

Shown above is a valid pyramid that can be built with the specifications given. The base is [a, b, c], and there are 3 triangles in this pyramid:

上面显示的是可以使用给定规格构建的有效金字塔。 底数为[a,b,c],此金字塔中有3个三角形:

from bottom to top: [abb, bdc, bad]

从下到上:[abb,bdc,坏]

They are all in the allowed triangles.

它们都在允许的三角形中。

What if I add one more allowed triangle: acb?

如果我再添加一个允许的三角形:acb怎么办?

Well, if you did that you could get into this situation:

好吧,如果您这样做,可能会遇到这种情况:

Image for post
Unfinished Pyramid
未完成的金字塔

But there’s no way for you to complete the pyramid, because there is no allowed triangle that satisfies: c*d.

但是您无法完成金字塔,因为没有允许的三角形满足:c * d。

But if you add yet one more allowed triangle: cad

但是,如果再添​​加一个允许的三角形:cad

Image for post
Base = abc, Allows = [abb, bdc, bad, acb, cad]
基本= abc,允许= [abb,bdc,坏,acb,cad]

Then you can complete a new pyramid!

然后,您可以完成一个新的金字塔!

解决: (Solve:)

行制造商: (Row Maker:)

How do we go about creating all of the possible pyramids from a base, [a, b, c], and a set of allowed triangles, [abb, bdc, bad, acb, cad]?

我们如何从一个底数[a,b,c]和一组允许的三角形[abb,bdc,bad,acb,cad]创建所有可能的金字塔?

I think it’s clear that you’ll have to loop through each pair of base nodes, [ab, bc], and create the next rows of the pyramids (that would be [b, d] and [c, d]). So let’s do that.

我认为很明显,您必须遍历每对基本节点[ab,bc],并创建金字塔的下一行(即[b,d]和[c,d])。 因此,让我们这样做。

Starting with ab, we check what are the allowed triangles with base ab. That would be: [abb, acb], at this point it’s clear that there are at least two possible combinations of next row, so how do you proceed to find all of them? Well, what we could do is recursively find the next row for the remaining base: [b, c], and then append the solutions to that to each of the possible first triangle. In this case the solutions to [b, c] is simple, there is only one: [bdc], so we append this solution to the two possible solutions to the first triangle ([abb, acb]), and contruct the two possible next row: ([b, d], [c, d])

从ab开始,我们检查以ab为基础的三角形是什么。 那应该是:[abb,acb],这时很显然下一行至少有两种可能的组合,那么如何继续查找所有这些呢? 好吧,我们可以做的是递归地找到剩余基数的下一行:[b,c],然后将解决方案附加到每个可能的第一个三角形上。 在这种情况下,[b,c]的解很简单,只有一个:[bdc],因此我们将此解附加到第一个三角形的两个可能解中([abb,acb]),并构造两个可能的解下一行:([b,d],[c,d])

def row_maker(bottom, allows):

if len(bottom) <= 1:
return [bottom]

def get_allowed(pair):

allowed = []
for allow in allows:
if allow[0] == pair[0] and allow[-1] == pair[-1]:
allowed.append(allow[1])

return allowed

allowed = get_allowed(bottom[:2])
if len(bottom) == 2:
return allowed

substrings = row_maker(bottom[1:], allows)
res = []
for allow in allowed:
for substring in substrings:
res.append(allow + substring)

return resbase = 'abc'
allows = ['abb', 'bdc', 'bad', 'acb', 'cad']

row_maker(base, allows)
# ['bd', 'cd']

Now that we have the next row maker function, we still need to construct the pyramid.

现在我们有了下一个行生成器功能,我们仍然需要构造金字塔。

金字塔制作器: (Pyramid Maker:)

In order to do that, again we start with the base [a, b, c], find the next rows: [b,d], [c, d], then for each of the next rows we again recursively find their respective next rows: [a], [a], and combine them into the final solutions:

为此,我们再次从基础[a,b,c]开始,找到下一行:[b,d],[c,d],然后对于接下来的每一行,我们再次递归地找到它们各自的接下来的行:[a],[a],并将它们合并为最终解决方案:

Image for post
Solutions for Base = abc, Allows = [abb, bdc, bad, acb, cad]
Base = abc,Allows = [abb,bdc,bad,acb,cad]的解决方案
def pyramid_maker(bottom, allows):

if len(bottom) <= 1:
return [[bottom]]

rows = row_maker(bottom, allows)

res = []
for row in rows:
res = res + pyramid_maker(row, allows)

res = [[bottom] + s for s in res]

return resbase = 'abc'
allows = ['abb', 'bdc', 'bad', 'acb', 'cad']

res = pyramid_maker(base, allows)
# [['abc', 'bd', 'a'], ['abc', 'cd', 'a']]

Isn’t it wonderful?

这不是很好吗?

复杂: (Complexity:)

Before we go for dinner, what is the complexity of this algorithm?

在我们共进晚餐之前,该算法的复杂性是什么?

Let’s start with row_maker, in order to make the next row you are looping through every character of the current row, so that’s O(n) where n is the length of base.

让我们从row_maker开始,为了制作下一行,您正在遍历当前行的每个字符,因此为O(n),其中n是基数的长度。

Moving onto the pyramid_maker. In it, you first call row_maker to get all of the possible rows, if allows is size m, the maximum number of possible rows returned are m^(n-1) and for each of those rows you call pyramid_maker again, until the returned rows are length 1. so the total number of operations are m^(n-1) * m^(n-2) * … * m¹ = m^(n(n-1)/2)

移动到pyramid_maker。 在其中,您首先调用row_maker以获取所有可能的行,如果允许的大小为m,则返回的最大可能行数为m ^(n-1),对于这些行中的每一行,您再次调用pyramid_maker,直到返回行的长度为1。因此操作总数为m ^(n-1)* m ^(n-2)*…*m¹= m ^(n(n-1)/ 2)

The maximum complexity is actually:

实际上,最大复杂度是:

O(m^(n²))

O(m ^(n²))

That’s a pretty large number… but it’s really only for special cases where all the characters in the pyramid and allows are identical, so don’t worry too much about it!

这是一个相当大的数字……但实际上仅适用于特殊情况下,金字塔和允许的所有字符都相同,因此不必为此担心太多!

艺术时间! (Art Time!)

Image for post
Base = faye, Allows = [fya, afy, fay, ayf, yfa, yaf, yae, yea, eay, eya, aye, aey]
基数= faye,允许= [fya,afy,fay,ayf,yfa,yaf,yae,是,eay,eya,aye,aey]

翻译自: https://medium.com/swlh/pyramid-maker-1d5b13ab9b67

高斯金字塔 拉普拉斯金字塔


http://www.taodudu.cc/news/show-8078884.html

相关文章:

  • 多元高斯分布是非参_广义高斯分布(GGD)和非对称广义高斯分布(AGGD)
  • 小高斯与老师的故事高级版
  • 阿里云服务器一年多少钱,学会利用阿里云价格计算器估算成本
  • 阿里云服务器ECS购买一年要多少钱?附赠阿里云代金券
  • 网站托管一年多少钱
  • php手游服务器怎么样,手游服务器一年的费用大概是多少呢?
  • 最优惠租云服务器_阿里云服务器最新优惠活动,云服务器租用一年收费价格表,最低只要96元...
  • 腾讯云服务器多少钱一年?
  • 服务器租用多少钱一年?
  • 2023年一台服务器一年多少钱?2023年一台腾讯云服务器多少钱1年?
  • 2023年租一台服务器一年多少钱?2023年腾讯云服务器多少钱一台?
  • 租一台服务器一年多少钱?2023年一台腾讯云服务器多少钱1年?
  • 从零开发一个Java Web项目要点
  • 为什么强烈推荐 Java 程序员使用 Google Guava 编程
  • 我司为什么禁止使用阿里巴巴Java规范,而使用Google Guava编程?
  • 面试:Maven 的这 7 个问题你思考过没有?
  • 数据库实验---视图
  • mysql改写子查询_对MySQL子查询的简单改写优化
  • 系统分析与设计 作业5
  • 数组Array的应用
  • 小程序this.setData不起作用
  • 深入浅出Nginx
  • openGauss暑期2021结项公布!
  • 实验五 SQL语言 更新操作命令
  • 基础算法---模板总结
  • java oop阶段小测试2 机试题答案_机试题TSQL阶段小测试机试试卷.doc
  • 金职院自主招生计算机应用,2017金职院自主招生
  • 北京理工大学计算机面试题,北京理工大学自主招生笔试面试真题
  • 山东 自主招生计算机专业,山东大学计算机方向自主招生
  • 高职计算机自主招生面试题,常州高职单招面试题目
  • 这篇关于高斯金字塔 拉普拉斯金字塔_金字塔制造者的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

    相关文章

    【机器学习】高斯过程的基本概念和应用领域以及在python中的实例

    引言 高斯过程(Gaussian Process,简称GP)是一种概率模型,用于描述一组随机变量的联合概率分布,其中任何一个有限维度的子集都具有高斯分布 文章目录 引言一、高斯过程1.1 基本定义1.1.1 随机过程1.1.2 高斯分布 1.2 高斯过程的特性1.2.1 联合高斯性1.2.2 均值函数1.2.3 协方差函数(或核函数) 1.3 核函数1.4 高斯过程回归(Gauss

    【机器学习】高斯网络的基本概念和应用领域

    引言 高斯网络(Gaussian Network)通常指的是一个概率图模型,其中所有的随机变量(或节点)都遵循高斯分布 文章目录 引言一、高斯网络(Gaussian Network)1.1 高斯过程(Gaussian Process)1.2 高斯混合模型(Gaussian Mixture Model)1.3 应用1.4 总结 二、高斯网络的应用2.1 机器学习2.2 统计学2.3

    高斯平面直角坐标讲解,以及地理坐标转换高斯平面直角坐标

    高斯平面直角坐标系(Gauss-Krüger 坐标系)是基于 高斯-克吕格投影 的一种常见的平面坐标系统,主要用于地理信息系统 (GIS)、测绘和工程等领域。该坐标系将地球表面的经纬度(地理坐标)通过一种投影方式转换为平面直角坐标,以便在二维平面中进行距离、面积和角度的计算。 一 投影原理 高斯平面直角坐标系使用的是 高斯-克吕格投影(Gauss-Krüger Projection),这是 横

    高斯混合模型(GMM)的EM算法实现

    在 聚类算法K-Means, K-Medoids, GMM, Spectral clustering,Ncut一文中我们给出了GMM算法的基本模型与似然函数,在EM算法原理中对EM算法的实现与收敛性证明进行了详细说明。本文主要针对如何用EM算法在混合高斯模型下进行聚类进行代码上的分析说明。 GMM模型: 每个 GMM 由 K 个 Gaussian 分布组成,每个 Gaussian 称为一个“C

    【matlab】仿真4PSK调制信号在高斯信道下的性能,并与理论分析结果比较——仿真篇

    三、4PSK调制信号在高斯信道下的性能仿真[--详细解析--] 1. MATLAB进行仿真程序如下: %{----------------------------------------------------------------------------- File: 说明文件

    【matlab】仿真4PSK调制信号在高斯信道下的性能,并与理论分析结果比较——理论篇

    1.     试编写程序,仿真4PSK调制信号在高斯信道下的性能,并与理论分析结果比较。   一、4PSK调制信号在高斯信道下的性能仿真 仿真4PSK的调制以及解调的仿真图,包括已调信号的波形,解调后的信号波形,眼图和误码率。 在仿真的基础上分析比较了各种调制方法的性能,并比较仿真模型与理论性能,证明了仿真模型是否有效。 目前,改进的数字调制方式主要有偏置正交相移键控,π/4正交差分相移

    以人口金字塔图为例,在线绘制左右双侧堆叠条形图

    导读: 人口金字塔(population pyramids)用于展示一个特定人口的年龄和性别分布。本质上是一种水平条形图。左侧是男性的数据,右侧是女性的数据。 Proc Natl Acad Sci U S A.文章《Demographic change and assimilation in the early 21st-century United States》fig 1的人口金字

    机器学习项目——基于机器学习(RNN LSTM 高斯拟合 MLP)的锂离子电池剩余寿命预测方法研究(代码/论文)

    完整的论文代码见文章末尾 以下为核心内容和部分结果 摘要 机器学习方法在电池寿命预测中的应用主要包括监督学习、无监督学习和强化学习等。监督学习方法通过构建回归模型或分类模型,直接预测电池的剩余寿命或健康状态。无监督学习方法则通过聚类分析和降维技术,识别电池数据中的潜在模式和特征。强化学习方法通过构建动态决策模型,在电池运行过程中不断优化预测策略和调整参数。上述方法不仅可以提高预测精度,还可以在

    平均场变分推断:以混合高斯模型为例

    文章目录 一、贝叶斯推断的工作流二、一个业务例子三、变分推断四、平均场理论五、业务CASE的平均场变分推断求解六、代码实现 一、贝叶斯推断的工作流 在贝叶斯推断方法中,工作流可以总结为: 根据观察者的知识,做出合理假设,假设数据是如何被生成的将数据的生成模型转化为数学模型根据数据通过数学方法,求解模型参数对新的数据做出预测 在整个pipeline中,第1点数据的生成过程

    高斯模糊实现小结

    转自:http://blog.csdn.net/zddblog/article/details/7450033 高斯模糊是一种图像滤波器,它使用正态分布(高斯函数)计算模糊模板,并使用该模板与原图像做卷积运算,达到模糊图像的目的。 N维空间正态分布方程为: 其中,σ是正态分布的标准差,σ值越大,图像越模糊(平滑)。r为模糊半径,模糊半径是指模板元素到模板中心的距离。如二维模板