- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在阅读我得到的 AI 教科书,我已经来到了我的部分的最后一个作业问题:
“以您选择的任何语言实现第 69 页概述的统一算法。”
在第 69 页,您有以下统一算法的伪代码:
function unify(E1, E2);
begin
case
both E1 and E2 are constants or the empty list:
if E1 = E2 then return {}
else return FAIL;
E1 is a variable:
if E1 occurs in E2 then return FAIL
else return {E2/E1}
E2 is a variable
if E2 occurs in E1 then FAIL
else return {E1/E2}
either E1 or E2 are empty then return FAIL
otherwise:
begin
HE1 := first element of E1;
HE2 := first element of E2;
SUBS1 := unify(HE1, HE2);
if SUBS1 := FAIL then return FAIL;
TE1 := apply(SUBS1, rest of E1);
TE2 := apply(SUBS1, rest of E2);
SUBS2 := unify(TE1, TE2);
if SUBS2 = FAIL then return FAIL;
else return composition(SUBS1, SUBS2)
end
end
end
最佳答案
对于任何感兴趣的人,我在
http://www.cs.trincoll.edu/~ram/cpsc352/notes/unification.html有更多的上下文。
让我们看看第一行:
function unify(E1, E2)
Expression
并从中派生出其他类,如
List
,
Variable
, 或
Constant
.然而,在我看来,这是矫枉过正。我在 C# 中使用
dynamic
实现了这个。关键词。
Dictionary<string, Object>
的绑定(bind)列表.
public static Dictionary<string, object> Unify(dynamic e1, dynamic e2)
{
if ((IsConstant(e1) && IsConstant(e2)))
{
if (e1 == e2)
return new Dictionary<string,object>();
throw new Exception("Unification failed");
}
if (e1 is string)
{
if (e2 is List && Occurs(e1, e2))
throw new Exception("Cyclical binding");
return new Dictionary<string, object>() { { e1, e2 } };
}
if (e2 is string)
{
if (e1 is List && Occurs(e2, e1))
throw new Exception("Cyclical binding");
return new Dictionary<string, object>() { { e2, e1 } };
}
if (!(e1 is List) || !(e2 is List))
throw new Exception("Expected either list, string, or constant arguments");
if (e1.IsEmpty || e2.IsEmpty)
{
if (!e1.IsEmpty || !e2.IsEmpty)
throw new Exception("Lists are not the same length");
return new Dictionary<string, object>();
}
var b1 = Unify(e1.Head, e2.Head);
var b2 = Unify(Substitute(b1, e1.Tail), Substitute(b1, e2.Tail));
foreach (var kv in b2)
b1.Add(kv.Key, kv.Value);
return b1;
}
List
class 实际上是我为库实现的 Lisp 样式列表。
关于artificial-intelligence - 如何用 Java 或 C# 等语言实现统一算法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1396558/
Closed. This question is off-topic。它当前不接受答案。 想改善这个问题吗? Update the question,所以它是用于堆栈溢出的on-topic。 已关闭8
我们正在为跳棋游戏开发神经网络。在我们的训练数据中, 0代表空白单元格,1代表白 block ,-1代表白王,2代表黑 block ,-2代表黑王 因此,我们需要的是范围为 [-2, 2] 的激活函数
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 9
我回答了一个问题,其中给出了两个启发式算法,要对其进行 A* 以找到从起始状态到目标状态的路径。 其中一种启发式方法通过减少一个节点的扩展找到了一条路径 - 现在出于这个原因,我们可以说这种启发式方法
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我正在尝试用 C 语言实现一些 AI 规划算法,但被基本概念困住了 :) 在跳到主要问题之前,我尝试实现一些支持命题逻辑的小框架: FORMULA f = PROPOSITION(a + 3 > 0)
我知道决策树试图将具有高熵的分类器放在决策树上。然而,信息增益如何发挥作用呢? 信息增益定义为: InformationGain = EntropyBefore - EntropyAfter 决策树是
我正在研究梳子方法,以减少模糊逻辑规则的“组合爆炸”。有一个示例,摘自“Programming Game AI from example”(由 Mat Buckland 撰写): The theory
我知道人工智能领域非常广阔,有很多关于它的书籍。但我只想知道我可以得到所有人工智能技术的简单介绍的任何资源,例如 它希望有 1 或 2 页的介绍所有技术及其示例,说明如何应用它们或将它们用于什么目的。
我最近对游戏中应用的蒙特卡罗树搜索产生了兴趣。 我读过几篇论文,但我使用“蒙特卡罗树搜索”Chaslot, G 的博士论文,因为我发现它更容易理解蒙特卡罗树搜索的基础知识 我试图对其进行编码,但遇到了
我最近开始在 coursera 上学习概率图形模型,开始后 2 周我开始相信我在概率方面不是那么好,因此我什至无法关注第一个主题(贝叶斯网络)。话虽如此,我想努力学习这门类(class),所以您能否向
我觉得这应该是AI的问题。 是否有任何算法可以在给定任何数字序列的情况下找到模式? 模式可以是抽象的,因为它可以是... 例如: 12112111211112 ... ( increasing num
这是我了解神经网络开始的一件事,是我不太了解最初要设置“偏见”的原因吗? 我了解Perceptron会根据以下内容计算其输出: P * W + b> 0 然后可以基于b = b + [G-O]计算学习
我正在尝试为“连续蛇”游戏实现 AI。它与普通的蛇游戏非常不同,至少就 AI 而言。基本上,蛇的驾驶方式有点像汽车,两个玩家中第一个撞上他的踪迹或另一个人的踪迹输掉比赛。此外,屏幕环绕其边框。 如果您
有人可以用非常简单的词来解释它是什么。也提供一个例子。因此,例如,如果您必须找到某事物的启发式函数,它应该是什么样子的? 以问题为例: 对于水壶问题http://www.math.tamu.edu/~
我想要一个词(例如“Apple)并处理一个文本(或者更多)。我想提出相关的术语。例如:处理Apple的文档并发现iPod,iPhone,Mac是与“苹果”相关的术语。 关于如何解决这个问题的任何想法?
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 6年前关闭。 Improve thi
关闭。这个问题需要debugging details .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 Improve this questio
我计划将 Nguyen-Widrow 算法用于具有 的 NN多个隐藏层 .在研究的过程中,我发现了很多歧义,我想澄清一下。 以下是 Nguyen-Widrow 算法的伪代码 Initial
我喜欢在强化学习方面做兼职研究。近年来(截至2009年)在rl-competition.org举办了强化学习竞赛。有一些非常有趣的问题,但这似乎已停止。我很想提高我的技能和知识,并与该领域的其他爱好者
我是一名优秀的程序员,十分优秀!