启发式算法和算法有什么区别?

发布于 2024-08-23 03:03:03 字数 21 浏览 12 评论 0原文

启发式算法和算法有什么区别?

What is the difference between a heuristic and an algorithm?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

顾铮苏瑾 2024-08-30 03:03:03

算法是对问题的自动解决方案的描述。该算法的作用是精确定义的。该解决方案可能是也可能不是最好的解决方案,但您从一开始就知道会得到什么样的结果。您使用某种编程语言来实现算法以获得程序(的一部分)。

现在,有些问题很困难,您可能无法在可接受的时间内得到可接受的解决方案。在这种情况下,通过应用一些任意选择(有根据的猜测),您通常可以更快地获得不太糟糕的解决方案:这是一种启发式

启发式算法仍然是一种算法,但不会探索问题的所有可能状态,或者会从探索最可能的状态开始。

典型的例子来自游戏。在编写国际象棋游戏程序时,您可以想象在某个深度级别尝试每一个可能的动作,并对棋盘应用一些评估函数。启发式方法会排除以明显错误的举动开始的完整分支。

在某些情况下,您并不是在寻找最佳解决方案,而是在寻找符合某些约束的任何解决方案。一个好的启发式方法将有助于在短时间内找到解决方案,但如果唯一的解决方案位于它选择不尝试的状态,也可能找不到任何解决方案。

An algorithm is the description of an automated solution to a problem. What the algorithm does is precisely defined. The solution could or could not be the best possible one but you know from the start what kind of result you will get. You implement the algorithm using some programming language to get (a part of) a program.

Now, some problems are hard and you may not be able to get an acceptable solution in an acceptable time. In such cases you often can get a not too bad solution much faster, by applying some arbitrary choices (educated guesses): that's a heuristic.

A heuristic is still a kind of an algorithm, but one that will not explore all possible states of the problem, or will begin by exploring the most likely ones.

Typical examples are from games. When writing a chess game program you could imagine trying every possible move at some depth level and applying some evaluation function to the board. A heuristic would exclude full branches that begin with obviously bad moves.

In some cases you're not searching for the best solution, but for any solution fitting some constraint. A good heuristic would help to find a solution in a short time, but may also fail to find any if the only solutions are in the states it chose not to try.

反话 2024-08-30 03:03:03
  • 算法通常是确定性的,并被证明可以产生最佳结果。
  • 启发式算法没有正确性证明,通常涉及随机元素,并且可能不会产生最佳结果。

许多问题没有已知的有效算法来找到最佳解决方案,而启发式方法可以非常快速地产生接近最佳的结果。

有一些重叠:“遗传算法”是一个公认的术语,但严格来说,这些是启发法,而不是算法。

  • An algorithm is typically deterministic and proven to yield an optimal result
  • A heuristic has no proof of correctness, often involves random elements, and may not yield optimal results.

Many problems for which no efficient algorithm to find an optimal solution is known have heuristic approaches that yield near-optimal results very quickly.

There are some overlaps: "genetic algorithms" is an accepted term, but strictly speaking, those are heuristics, not algorithms.

青春如此纠结 2024-08-30 03:03:03

启发式,简而言之就是“有根据的猜测”。维基百科解释得很好。最后,将“普遍接受”方法作为特定问题的最优解决方案。

启发式是一个形容词
基于经验的技术可以帮助
在解决问题、学习和
发现。使用启发式方法
快速得出一个解决方案
希望接近最好的可能
答案,或“最佳解决方案”。
启发法是“经验法则”,
有根据的猜测,直觉判断
或者只是常识。启发式是
解决问题的一般方法。
启发式作为名词是另一个名字
用于启发式方法。

更准确地说,启发式
代表容易使用的策略
尽管松散适用,但可访问,
控制问题解决的信息
在人类和机器中。

而算法是包含用于解决问题的有限指令集的方法。该方法已被数学或科学证明可以解决该问题。有正式的方法和证明。

启发式算法是一种能够产生
可接受的问题解决方案
很多实际场景,在
一般启发式的时尚,但是
没有正式的证明
它的正确性。

Heuristic, in a nutshell is an "Educated guess". Wikipedia explains it nicely. At the end, a "general acceptance" method is taken as an optimal solution to the specified problem.

Heuristic is an adjective for
experience-based techniques that help
in problem solving, learning and
discovery. A heuristic method is used
to rapidly come to a solution that is
hoped to be close to the best possible
answer, or 'optimal solution'.
Heuristics are "rules of thumb",
educated guesses, intuitive judgments
or simply common sense. A heuristic is
a general way of solving a problem.
Heuristics as a noun is another name
for heuristic methods.

In more precise terms, heuristics
stand for strategies using readily
accessible, though loosely applicable,
information to control problem solving
in human beings and machines.

While an algorithm is a method containing finite set of instructions used to solving a problem. The method has been proven mathematically or scientifically to work for the problem. There are formal methods and proofs.

Heuristic algorithm is an algorithm that is able to produce an
acceptable solution to a problem in
many practical scenarios, in the
fashion of a general heuristic, but
for which there is no formal proof of
its correctness.

清音悠歌 2024-08-30 03:03:03

算法是要执行的一组独立的分步操作 4,通常解释为(计算机或人类)指令的有限序列,以确定问题的解决方案,例如:是否存在从 A 到 B 的路径,或者 A 和 B 之间的最小路径是什么。对于后一种情况,您也可能会对“相当接近”的替代解决方案感到满意。

算法有某些类别,启发式算法就是其中之一。根据本例中算法的(经过验证的)属性,它属于以下三个类别之一(注释 1):

请注意,近似算法也是一种启发式算法,但具有更强的属性,即存在已证明的边界它输出的解决方案(值)。

对于某些问题,没有人找到一种“有效”的算法来计算最优解(注 2)。这些问题之一是著名的旅行商问题。例如,Christophides 的旅行商问题算法过去被称为启发式,因为没有证明它与最优解的误差在 50% 之内。然而,由于已经被证明,Christophides 的算法更准确地称为近似算法。

由于计算机功能的限制,并不总是能够有效找到最佳解决方案。如果问题中有足够的结构,则可能有一种有效的方法来遍历解空间,即使解空间很大(即在最短路径问题中)。

启发式方法通常用于通过添加“专家信息”或“有根据的猜测”来指导搜索方向,从而提高算法的运行时间。在实践中,启发式也可能是最佳算法的子例程,以确定首先查看哪里。

(注 1):此外,算法的特征在于它们是否包含随机元素或非确定性元素。始终以相同方式执行并产生相同答案的算法称为确定性算法。

(注 2):这称为 P vs NP 问题,被分类为 NP 完全和 NP 困难的问题不太可能有“高效”算法。笔记;正如 @Kriss 在评论中提到的,甚至还有“更糟糕”类型的问题,可能需要指数时间或空间来计算。

有几个答案可以回答部分问题。我认为它们不够完整且不够准确,因此决定不编辑 @Kriss 接受的答案

An algorithm is a self-contained step-by-step set of operations to be performed 4, typically interpreted as a finite sequence of (computer or human) instructions to determine a solution to a problem such as: is there a path from A to B, or what is the smallest path between A and B. In the latter case, you could also be satisfied with a 'reasonably close' alternative solution.

There are certain categories of algorithms, of which the heuristic algorithm is one. Depending on the (proven) properties of the algorithm in this case, it falls into one of these three categories (note 1):

  • Exact: the solution is proven to be an optimal (or exact solution) to the input problem
  • Approximation: the deviation of the solution value is proven to be never further away from the optimal value than some pre-defined bound (for example, never more than 50% larger than the optimal value)
  • Heuristic: the algorithm has not been proven to be optimal, nor within a pre-defined bound of the optimal solution

Notice that an approximation algorithm is also a heuristic, but with the stronger property that there is a proven bound to the solution (value) it outputs.

For some problems, noone has ever found an 'efficient' algorithm to compute the optimal solutions (note 2). One of those problems is the well-known Traveling Salesman Problem. Christophides' algorithm for the Traveling Salesman Problem, for example, used to be called a heuristic, as it was not proven that it was within 50% of the optimal solution. Since it has been proven, however, Christophides' algorithm is more accurately referred to as an approximation algorithm.

Due to restrictions on what computers can do, it is not always possible to efficiently find the best solution possible. If there is enough structure in a problem, there may be an efficient way to traverse the solution space, even though the solution space is huge (i.e. in the shortest path problem).

Heuristics are typically applied to improve the running time of algorithms, by adding 'expert information' or 'educated guesses' to guide the search direction. In practice, a heuristic may also be a sub-routine for an optimal algorithm, to determine where to look first.

(note 1): Additionally, algorithms are characterised by whether they include random or non-deterministic elements. An algorithm that always executes the same way and produces the same answer, is called deterministic.

(note 2): This is called the P vs NP problem, and problems that are classified as NP-complete and NP-hard are unlikely to have an 'efficient' algorithm. Note; as @Kriss mentioned in the comments, there are even 'worse' types of problems, which may need exponential time or space to compute.

There are several answers that answer part of the question. I deemed them less complete and not accurate enough, and decided not to edit the accepted answer made by @Kriss

倒数 2024-08-30 03:03:03

事实上我不认为他们之间有很多共同点。一些算法在其逻辑中使用启发式(通常是为了减少计算或获得更快的结果)。通常,启发式算法用于所谓的贪婪算法。

启发式是我们认为可以很好地使用的一些“知识”,以便在我们的算法中获得最佳选择(当应该采取选择时)。例如......国际象棋中的启发式可能是(如果可以的话,总是选择对手的皇后,因为你知道这是更强的人物)。启发法并不能保证你会得到正确的答案,但是(如果假设正确)通常会在更短的时间内得到接近最佳的答案。

Actually I don't think that there is a lot in common between them. Some algorithm use heuristics in their logic (often to make fewer calculations or get faster results). Usually heuristics are used in the so called greedy algorithms.

Heuristics is some "knowledge" that we assume is good to use in order to get the best choice in our algorithm (when a choice should be taken). For example ... a heuristics in chess could be (always take the opponents' queen if you can, since you know this is the stronger figure). Heuristics do not guarantee you that will lead you to the correct answer, but (if the assumptions is correct) often get answer which are close to the best in much shorter time.

过去的过去 2024-08-30 03:03:03

算法是一组明确定义的解决问题的指令,启发式涉及利用学习和发现的方法来达成解决方案。

因此,如果您知道如何解决问题,请使用算法。如果您需要开发一个解决方案,那么它就是启发法。

An Algorithm is a clearly defined set of instructions to solve a problem, Heuristics involve utilising an approach of learning and discovery to reach a solution.

So, if you know how to solve a problem then use an algorithm. If you need to develop a solution then it's heuristics.

背叛残局 2024-08-30 03:03:03

启发式算法是算法,因此从这个意义上来说,没有算法,但是,启发式算法采用“猜测”方法来解决问题,产生“足够好”的答案,而不是找到“最佳可能”的解决方案。

一个很好的例子是,您有一个非常困难(读为 NP 完全)的问题,您想要一个解决方案,但没有时间找到它,因此必须使用基于启发式算法的足够好的解决方案,例如使用遗传算法寻找旅行商问题的解决方案。

Heuristics are algorithms, so in that sense there is none, however, heuristics take a 'guess' approach to problem solving, yielding a 'good enough' answer, rather than finding a 'best possible' solution.

A good example is where you have a very hard (read NP-complete) problem you want a solution for but don't have the time to arrive to it, so have to use a good enough solution based on a heuristic algorithm, such as finding a solution to a travelling salesman problem using a genetic algorithm.

农村范ル 2024-08-30 03:03:03

算法是一些操作的序列,给定输入计算某些内容(函数)并输出结果。

算法可以产生精确或近似值。

它还可以计算一个很有可能接近精确值的随机值。

启发式算法使用对输入值的一些洞察并计算不精确的值(但可能接近最佳值)。
在一些特殊情况下,启发式可以找到精确的解决方案。

Algorithm is a sequence of some operations that given an input computes something (a function) and outputs a result.

Algorithm may yield an exact or approximate values.

It also may compute a random value that is with high probability close to the exact value.

A heuristic algorithm uses some insight on input values and computes not exact value (but may be close to optimal).
In some special cases, heuristic can find exact solution.

九歌凝 2024-08-30 03:03:03

启发式通常是一种优化或策略,通常可以提供足够好的答案,但并不总是且很少是最佳答案。例如,如果你要用蛮力解决旅行商问题,那么一旦其成本超过当前最佳解决方案的成本,就放弃部分解决方案是一种启发式的做法:有时它有帮助,有时没有帮助,而且绝对没有帮助。 t 提高算法的理论(big-oh 表示法)运行时间

A heuristic is usually an optimization or a strategy that usually provides a good enough answer, but not always and rarely the best answer. For example, if you were to solve the traveling salesman problem with brute force, discarding a partial solution once its cost exceeds that of the current best solution is a heuristic: sometimes it helps, other times it doesn't, and it definitely doesn't improve the theoretical (big-oh notation) run time of the algorithm

黯淡〆 2024-08-30 03:03:03

我认为启发式更多的是人工智能中基于学习的模型中使用的约束,因为未来的解决方案状态很难预测。

但读完上面的答案后我的疑问是
“如何使用随机优化技术成功应用启发式?或者当与随机优化一起使用时它们可以作为成熟的算法发挥作用吗?”

http://en.wikipedia.org/wiki/Stochastic_optimization

I think Heuristic is more of a constraint used in Learning Based Model in Artificial Intelligent since the future solution states are difficult to predict.

But then my doubt after reading above answers is
"How would Heuristic can be successfully applied using Stochastic Optimization Techniques? or can they function as full fledged algorithms when used with Stochastic Optimization?"

http://en.wikipedia.org/wiki/Stochastic_optimization

优雅的叶子 2024-08-30 03:03:03

我读过的最好的解释之一来自伟大的书 Code Complete,我现在引用:

启发式是一种帮助您寻找答案的技术。它是
结果受偶然性影响,因为启发式仅告诉您如何
去寻找,而不是寻找什么。它没有告诉你如何直接获取
从A点到B点;它甚至可能不知道 A 点在哪里
B点是。实际上,启发式算法是一种穿着小丑服的算法。
它不太可预测,但更有趣,而且没有 30 天的期限,
退款保证。

这是开车去某人家的算法:走 167 号高速公路
向南至普伊阿勒普。从 South Hill Mall 出口驶出,行驶 4.5 英里
上山。在杂货店旁边的红绿灯处右转,然后
在第一个路口左转。转入大棕褐色房子的车道
左边,位于 714 North Cedar。

这是前往某人家的启发式方法:找到最后一个
我们寄给您的信。开车前往回程地址所在的城镇。什么时候
你到了城里,问问别人我们的房子在哪里。大家都知道
我们——有人会很乐意帮助您。如果找不到人,请致电我们
通过公用电话,我们会来接您。

算法和启发式之间的区别很微妙,
两个术语有些重叠。就本书而言,主要
两者之间的区别在于间接级别
解决方案。算法直接为您提供指令。一个
启发式告诉您如何自己发现说明,或者
至少在哪里可以找到它们。

One of the best explanations I have read comes from the great book Code Complete, which I now quote:

A heuristic is a technique that helps you look for an answer. Its
results are subject to chance because a heuristic tells you only how
to look, not what to find. It doesn’t tell you how to get directly
from point A to point B; it might not even know where point A and
point B are. In effect, a heuristic is an algorithm in a clown suit.
It’s less predict- able, it’s more fun, and it comes without a 30-day,
money-back guarantee.

Here is an algorithm for driving to someone’s house: Take Highway 167
south to Puy-allup. Take the South Hill Mall exit and drive 4.5 miles
up the hill. Turn right at the light by the grocery store, and then
take the first left. Turn into the driveway of the large tan house on
the left, at 714 North Cedar.

Here’s a heuristic for getting to someone’s house: Find the last
letter we mailed you. Drive to the town in the return address. When
you get to town, ask someone where our house is. Everyone knows
us—someone will be glad to help you. If you can’t find anyone, call us
from a public phone, and we’ll come get you.

The difference between an algorithm and a heuristic is subtle, and the
two terms over-lap somewhat. For the purposes of this book, the main
difference between the two is the level of indirection from the
solution. An algorithm gives you the instructions directly. A
heuristic tells you how to discover the instructions for yourself, or
at least where to look for them.

抚笙 2024-08-30 03:03:03

他们找到了一个次优的解决方案,而对所找到的解决方案的质量没有任何保证,很明显,这对于启发式多项式的开发是有意义的。这些方法的应用适合解决现实世界的问题或从计算角度来看非常困难的大问题,甚至没有一种算法能够在多项式时间内找到近似解。

They find a solution suboptimally without any guarantee as to the quality of solution found, it is obvious that it makes sense to the development of heuristics only polynomial. The application of these methods is suitable to solve real world problems or large problems so awkward from the computational point of view that for them there is not even an algorithm capable of finding an approximate solution in polynomial time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文