启发式算法和算法有什么区别?
启发式算法和算法有什么区别?
What is the difference between a heuristic and an algorithm?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
启发式算法和算法有什么区别?
What is the difference between a heuristic and an algorithm?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(12)
算法是对问题的自动解决方案的描述。该算法的作用是精确定义的。该解决方案可能是也可能不是最好的解决方案,但您从一开始就知道会得到什么样的结果。您使用某种编程语言来实现算法以获得程序(的一部分)。
现在,有些问题很困难,您可能无法在可接受的时间内得到可接受的解决方案。在这种情况下,通过应用一些任意选择(有根据的猜测),您通常可以更快地获得不太糟糕的解决方案:这是一种启发式。
启发式算法仍然是一种算法,但不会探索问题的所有可能状态,或者会从探索最可能的状态开始。
典型的例子来自游戏。在编写国际象棋游戏程序时,您可以想象在某个深度级别尝试每一个可能的动作,并对棋盘应用一些评估函数。启发式方法会排除以明显错误的举动开始的完整分支。
在某些情况下,您并不是在寻找最佳解决方案,而是在寻找符合某些约束的任何解决方案。一个好的启发式方法将有助于在短时间内找到解决方案,但如果唯一的解决方案位于它选择不尝试的状态,也可能找不到任何解决方案。
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.
许多问题没有已知的有效算法来找到最佳解决方案,而启发式方法可以非常快速地产生接近最佳的结果。
有一些重叠:“遗传算法”是一个公认的术语,但严格来说,这些是启发法,而不是算法。
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.
启发式,简而言之就是“有根据的猜测”。维基百科解释得很好。最后,将“普遍接受”方法作为特定问题的最优解决方案。
而算法是包含用于解决问题的有限指令集的方法。该方法已被数学或科学证明可以解决该问题。有正式的方法和证明。
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.
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.
算法是要执行的一组独立的分步操作 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):
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
事实上我不认为他们之间有很多共同点。一些算法在其逻辑中使用启发式(通常是为了减少计算或获得更快的结果)。通常,启发式算法用于所谓的贪婪算法。
启发式是我们认为可以很好地使用的一些“知识”,以便在我们的算法中获得最佳选择(当应该采取选择时)。例如......国际象棋中的启发式可能是(如果可以的话,总是选择对手的皇后,因为你知道这是更强的人物)。启发法并不能保证你会得到正确的答案,但是(如果假设正确)通常会在更短的时间内得到接近最佳的答案。
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.
算法是一组明确定义的解决问题的指令,启发式涉及利用学习和发现的方法来达成解决方案。
因此,如果您知道如何解决问题,请使用算法。如果您需要开发一个解决方案,那么它就是启发法。
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.
启发式算法是算法,因此从这个意义上来说,没有算法,但是,启发式算法采用“猜测”方法来解决问题,产生“足够好”的答案,而不是找到“最佳可能”的解决方案。
一个很好的例子是,您有一个非常困难(读为 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.
算法是一些操作的序列,给定输入计算某些内容(函数)并输出结果。
算法可以产生精确或近似值。
它还可以计算一个很有可能接近精确值的随机值。
启发式算法使用对输入值的一些洞察并计算不精确的值(但可能接近最佳值)。
在一些特殊情况下,启发式可以找到精确的解决方案。
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.
启发式通常是一种优化或策略,通常可以提供足够好的答案,但并不总是且很少是最佳答案。例如,如果你要用蛮力解决旅行商问题,那么一旦其成本超过当前最佳解决方案的成本,就放弃部分解决方案是一种启发式的做法:有时它有帮助,有时没有帮助,而且绝对没有帮助。 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
我认为启发式更多的是人工智能中基于学习的模型中使用的约束,因为未来的解决方案状态很难预测。
但读完上面的答案后我的疑问是
“如何使用随机优化技术成功应用启发式?或者当与随机优化一起使用时它们可以作为成熟的算法发挥作用吗?”
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
我读过的最好的解释之一来自伟大的书 Code Complete,我现在引用:
One of the best explanations I have read comes from the great book Code Complete, which I now quote:
他们找到了一个次优的解决方案,而对所找到的解决方案的质量没有任何保证,很明显,这对于启发式多项式的开发是有意义的。这些方法的应用适合解决现实世界的问题或从计算角度来看非常困难的大问题,甚至没有一种算法能够在多项式时间内找到近似解。
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.