📚 Artificial Intelligence Fundamentals Lab Explained | 人工智能基础实验解析
Artificial Intelligence (AI) is one of the most frequently tested topics in Computer Science examinations. This article walks through the core laboratory experiments you may encounter in your AI fundamentals module, including fuzzy logic, search algorithms, knowledge representation, and simple machine learning models. Each experiment is explained step by step, with exam-style analysis to help you prepare effectively.
人工智能是计算机科学考试中最常考的主题之一。本文将带你完整梳理人工智能基础模块中可能出现的核心实验,包括模糊逻辑、搜索算法、知识表示和简单的机器学习模型。每个实验都会逐步解析,并结合考试风格的分析,帮助你高效备考。
1. Fuzzy Logic Control Experiment | 模糊逻辑控制实验
The fuzzy logic experiment typically involves designing a controller that does not rely on crisp true/false values. For example, a washing machine determines wash time based on dirt level and oiliness. Each input is mapped to membership functions such as Low, Medium, and High, and a rule base is applied to infer the output.
模糊逻辑实验通常涉及设计一个不依赖精确真/假值的控制器。例如,洗衣机根据污垢程度和油污程度决定洗涤时间。每个输入都会被映射到“低、中、高”等隶属函数,然后通过规则库推断输出结果。
Exam Tip: You must be able to draw membership function graphs and apply the Min-Max inference method. The center-of-gravity defuzzification formula is often tested.
考点提示:你必须能够绘制隶属函数图,并运用最小-最大推理法。重心法去模糊化公式也经常被考查。
Consider a simple example where dirt level is 60 (on a 0–100 scale) and oiliness is 40. Given membership functions, you first determine the degree of membership for each linguistic term. Then, using fuzzy rules such as “IF dirt is High AND oiliness is Medium THEN wash time is Long,” the output is clipped to the minimum of the two input membership values.
考虑一个简单例子:污垢程度为60(取值范围0-100),油污程度为40。给定隶属函数后,首先确定每个语言项的隶属度。然后,应用模糊规则,例如“如果污垢程度为高且油污程度为中,则洗涤时间为长”,输出将被裁剪为两个输入隶属度中的最小值。
μ_result(x) = min(μ_dirt(x), μ_oil(x))
Finally, defuzzification converts the fuzzy output into a crisp value using the centroid formula:
最后,去模糊化通过质心公式将模糊输出转换为精确数值:
Crisp Value = Σ(x × μ(x)) ÷ Σμ(x)
2. Search Strategies in State Space | 状态空间搜索策略实验
The search experiment requires you to traverse a state space graph using Breadth-First Search (BFS), Depth-First Search (DFS), and Greedy Best-First Search. You must record the order in which nodes are visited and explain the time and space complexity for each method.
搜索实验要求你使用广度优先搜索(BFS)、深度优先搜索(DFS)和贪婪最佳优先搜索遍历状态空间图。你必须记录节点被访问的顺序,并解释每种方法的时间和空间复杂度。
In a typical exam question, you are given a graph with a start node S and a goal node G. For BFS, you use a queue data structure, visiting all neighbours of the current node before moving to the next level. The algorithm guarantees the shortest path in an unweighted graph.
在典型考题中,你会得到一个包含起始节点S和目标节点G的图。对于BFS,使用队列数据结构,在进入下一层之前先访问当前节点的所有相邻节点。该算法保证在无权图中找到最短路径。
For DFS, you use a stack and explore as far as possible along each branch before backtracking. This approach uses less memory but may not find the shortest path. The order of visited nodes depends entirely on the neighbours’ arrangement.
对于DFS,使用栈并在回溯之前尽量深入探索每条分支。这种方法占用较少内存,但可能找不到最短路径。访问节点的顺序完全取决于邻居节点的排列方式。
BFS: O(|V| + |E|) time, O(|V|) space
DFS: O(|V| + |E|) time, O(|V|) space
3. A* Algorithm Experiment | A* 算法实验
The A* algorithm experiment combines the cost so far (g(n)) with a heuristic estimate to the goal (h(n)). You are typically asked to compute f(n) = g(n) + h(n) for each node and identify the optimal path.
A*算法实验将已花费的代价g(n)与到达目标的启发式估计h(n)相结合。通常要求你计算每个节点的f(n) = g(n) + h(n),并找出最优路径。
A common example is a simple grid map where movement costs 1 per cell and the heuristic is the Manhattan distance. You must maintain two lists: open list (nodes to be evaluated) and closed list (nodes already evaluated).
一个常见例子是简单网格地图,其中每格移动代价为1,启发函数为曼哈顿距离。你必须维护两个列表:开放列表(待评估节点)和关闭列表(已评估节点)。
| Step | Node | g(n) | h(n) | f(n) |
| 1 | Start | 0 | 6 | 6 |
| 2 | Node A | 1 | 5 | 6 |
| 3 | Goal | 2 | 0 | 2 |
The key property of A* is that it is both complete and optimal if the heuristic is admissible, meaning h(n) never overestimates the true cost. This makes A* the preferred algorithm for pathfinding in many AI applications.
A*算法的一个关键特性是:如果启发函数是可采纳的(即h(n)永远不会高估真实代价),那么该算法既是完备的又是最优的。这使得A*成为许多AI应用中路径查找的首选算法。
4. Knowledge Representation with Propositional Logic | 命题逻辑知识表示实验
This experiment focuses on representing real-world facts using propositional logic symbols and logical connectives. You must translate English statements into logical expressions and use truth tables to verify the validity of an argument.
该实验侧重于使用命题逻辑符号和逻辑连接词表示现实世界的事实。你必须将英文语句转换为逻辑表达式,并使用真值表来验证论证的有效性。
For instance, consider the statements: “If it rains, the ground is wet” and “It rains.” Using symbols, let R represent “it rains” and W represent “the ground is wet.” The first statement becomes R → W, and the second is simply R.
例如,考虑以下陈述:“如果下雨,地面就是湿的”以及“天下雨了”。用符号表示,设R代表“下雨”,W代表“地面湿”。第一个陈述变为R → W,第二个陈述就是R。
Using the inference rule Modus Ponens, we can conclude W. In exam settings, you may be asked to construct a truth table with all possible truth value combinations and identify tautologies, contradictions, or satisfiable formulas.
使用假言推理规则,我们可以得出结论W。在考试中,你可能需要构建包含所有真值组合的真值表,并识别重言式、矛盾式或可满足公式。
It is also common to test equivalence laws such as De Morgan’s Laws: ¬(P ∧ Q) ≡ (¬P) ∨ (¬Q) and ¬(P ∨ Q) ≡ (¬P) ∧ (¬Q). Mastering these transformations is essential for simplifying Boolean expressions.
考试还常考查等价定律,如德摩根定律:¬(P ∧ Q) ≡ (¬P) ∨ (¬Q) 和 ¬(P ∨ Q) ≡ (¬P) ∧ (¬Q)。掌握这些变换对于简化布尔表达式至关重要。
5. Decision Tree Learning Experiment | 决策树学习实验
The decision tree experiment requires you to build a classification model from a small dataset. You must compute the Information Gain for each attribute using entropy calculations, then construct the tree by selecting attributes with the highest gain at each node.
决策树实验要求你从一个小型数据集中构建分类模型。你必须通过熵计算获得每个属性的信息增益,然后在每个节点选择增益最高的属性来构建树。
Entropy(S) = -Σ pᵢ × log₂(pᵢ)
For a binary classification problem with 9 positive examples and 5 negative examples, the entropy is:
对于一个包含9个正例和5个负例的二分类问题,熵值为:
Entropy(S) = -(9/14) × log₂(9/14) – (5/14) × log₂(5/14) ≈ 0.940
The Information Gain for an attribute A is calculated as the difference between the entropy of the parent node and the weighted average entropy of the child nodes. You must then select the attribute with the maximum gain as the root node.
属性A的信息增益计算为父节点熵与子节点加权平均熵之差。然后选择增益最大的属性作为根节点。
Gain(S, A) = Entropy(S) – Σ (|Sᵥ| ÷ |S|) × Entropy(Sᵥ)
6. Neural Network Simulation | 神经网络模拟实验
The neural network experiment typically involves a simple perceptron or a single-layer feedforward network. You must compute the weighted sum of inputs, apply the activation function, and update weights based on the error between the predicted output and the target output.
神经网络实验通常涉及简单的感知器或单层前馈网络。你必须计算输入的加权和、应用激活函数,并根据预测输出与目标输出之间的误差更新权重。
For a perceptron with three inputs x₁, x₂, x₃ and corresponding weights w₁, w₂, w₃, the activation value is calculated as:
对于一个具有三个输入x₁、x₂、x₃,对应权重为w₁、w₂、w₃的感知器,激活值计算如下:
Net = w₁x₁ + w₂x₂ + w₃x₃ + b
where b is the bias term. The output is 1 if Net ≥ 0, otherwise 0. If the desired output is different, the weights are updated using the delta rule: Δwᵢ = η × (target – output) × xᵢ, where η is the learning rate.
其中b是偏置项。如果Net ≥ 0,输出为1,否则为0。如果期望输出与实际输出不一致,则使用增量规则更新权重:Δwᵢ = η × (target – output) × xᵢ,其中η为学习率。
In examinations, you may be asked to perform a single iteration of training manually. It is crucial to compute the forward pass and the backward update accurately, including all intermediate values.
在考试中,你可能会被要求手动执行一次训练迭代。准确计算前向传播和反向更新(包括所有中间值)至关重要。
7. Expert Systems and Rule-Based Reasoning | 专家系统与基于规则的推理实验
In the expert system experiment, you work with a knowledge base of IF-THEN rules and an inference engine. A typical question provides a set of facts and rules, asking you to determine which conclusions can be reached using forward chaining or backward chaining.
在专家系统实验中,你将使用由IF-THEN规则组成的知识库和推理引擎。典型问题会提供一组事实和规则,要求你使用前向链或后向链确定能得出哪些结论。
Forward chaining starts from known facts and applies rules to derive new facts until the goal is reached or no more rules apply. Backward chaining starts from the goal and works backward to determine whether the available facts satisfy the rule conditions.
前向链从已知事实出发,应用规则推导出新事实,直到到达目标或没有更多规则可用。后向链从目标出发,向后推理,判断现有事实是否满足规则条件。
A common example includes rules such as: R1: IF animal has feathers THEN animal is a bird; R2: IF animal can fly AND animal lays eggs THEN animal has feathers. You must trace the reasoning path and state which rules fire in what order.
常见示例包括如下规则:R1:如果动物有羽毛,那么动物是鸟;R2:如果动物会飞并且动物下蛋,那么动物有羽毛。你必须追踪推理路径并说明规则按什么顺序被触发。
For exam purposes, remember that forward chaining is data-driven and is useful for planning and monitoring, while backward chaining is goal-driven and is used in diagnostic systems.
就考试而言,记住前向链是数据驱动的,适用于规划和监控;后向链是目标驱动的,用于诊断系统。
8. Natural Language Processing Basics | 自然语言处理基础实验
Natural Language Processing (NLP) experiments introduce text processing, tokenisation, stop-word removal, and frequency analysis. You may be given a short paragraph and asked to produce a bag-of-words representation or compute term frequency scores.
自然语言处理(NLP)实验介绍文本处理、分词、停顿词去除和频率分析。你可能会得到一段短文,要求生成词袋表示或计算词频得分。
Tokenisation divides a sentence into smaller units called tokens, which are usually words or punctuation marks. Stop-word removal filters out common words like “the”, “is”, and “and” that carry little meaningful information for analysis.
分词将句子划分为更小的单元,称为词元,通常是单词或标点符号。停顿词去除会过滤掉“the”、“is”、“and”等在分析中没有太多信息量的常见词。
A simple frequency analysis involves counting the number of times each word appears in a document. The results can be displayed in a table, and the most frequent terms are often considered keywords. Text classification tasks may also ask you to use a Naive Bayes approach.
简单的频率分析涉及计算每个单词在文档中出现的次数。结果可以显示在表格中,最频繁出现的词通常被视为关键词。文本分类任务也可能要求你使用朴素贝叶斯方法。
P(Class | Text) ∝ P(Class) × Π P(Wordᵢ | Class)
In the exam, you should note that Naive Bayes assumes conditional independence between words, which simplifies the calculation even though the assumption rarely holds in real-world language.
在考试中,你应注意到朴素贝叶斯假设词之间条件独立,这简化了计算,尽管该假设在现实语言中很少成立。
9. Turing Test and AI Ethics Evaluation | 图灵测试与AI伦理评估
While many lab sessions are programming-based, an equally important assessment involves evaluating AI systems using the Turing Test framework and discussing ethical issues. This experiment may be conducted as a written response based on a scenario.
虽然许多实验课以编程为主,但同样重要的评估是使用图灵测试框架评价AI系统,并讨论伦理问题。该实验可能以基于情景的书面回答形式进行。
The Turing Test, proposed by Alan Turing in 1950, involves a human interrogator engaging in a text-based conversation with a human and a machine. If the interrogator cannot reliably distinguish the machine from the human, the machine is said to have passed the test.
图灵测试由艾伦·图灵于1950年提出:人类询问者与一个人类和一个机器进行基于文本的对话。如果询问者无法可靠地区分机器与人类,则称该机器通过了测试。
As machine learning models become more powerful, students are expected to discuss ethical issues, including algorithmic bias, data privacy, accountability, and the potential for AI to replace human jobs. Consider the IMPACT framework: identify stakeholders, assess risks, and propose mitigation strategies.
随着机器学习模型日益强大,学生需要讨论伦理问题,包括算法偏见、数据隐私、问责制以及AI取代人类工作的可能性。可考虑IMPACT框架:识别利益相关者、评估风险和提出缓解策略。
10. Common Exam Pitfalls and How to Avoid Them | 常见考试陷阱与应对策略
Students often lose marks in AI experiments due to careless calculation or omission of process explanations. The most common errors include incorrect entropy calculations, forgetting the bias term in neural networks, and confusing BFS with DFS node ordering.
学生通常在AI实验中因计算粗心或遗漏过程解释而失分。最常见的错误包括熵计算错误、在神经网络中忘记偏置项,以及混淆BFS与DFS的节点顺序。
You should also be aware of the difference between completeness and optimality. BFS is complete but does not always find the cheapest path in weighted graphs, while A* finds the optimal path only if the heuristic is admissible. Repeat this point until it becomes automatic.
你还需弄清完备性和最优性之间的区别。BFS是完备的,但在加权图中不一定找到代价最低的路径;A*只有在启发函数可采纳时才找到最优路径。请反复复习该要点直到完全熟练。
- Show all working | 展示全部过程 — hidden marks are often awarded for intermediate steps.
- Use the correct symbols | 使用正确的符号 — write ∧, ∨, ¬, → accurately.
- Check units and scales | 检查单位和量程 — verify whether inputs are in 0–1 or 0–100 ranges.
- Evaluate machine outputs critically | 批判性评估机器输出 — examiners reward reflective commentary.
11. Worked Example Walkthrough | 综合例题演练
Let us now combine the techniques above in a full worked example. Suppose you are given a small dataset with two features: Weather (Sunny, Rainy) and Wind (Strong, Weak), and a target variable Play (Yes, No). The task is to build a decision tree and test which rule base an expert system would use to make a recommendation.
现在让我们通过一个完整的工作示例来综合运用上述技术。假设你有一个小型数据集,包含两个特征:天气(晴、雨)和风力(强、弱),目标变量为是否游玩(是、否)。任务是构建决策树,并测试专家系统会使用哪些规则来提出建议。
| Weather | Wind | Play | Count |
| Sunny | Weak | Yes | 3 |
| Sunny | Strong | No | 2 |
| Rainy | Weak | Yes | 2 |
| Rainy | Strong | No | 1 |
First compute the entropy of the parent set: 5 Yes and 3 No, so S = 8, p_yes = 5/8, p_no = 3/8.
首先计算父集的熵:5个“是”和3个“否”,即S=8,p_是=5/8,p_否=3/8。
Entropy(S) = -(5/8) × log₂(5/8) – (3/8) × log₂(3/8) ≈ 0.954
Now compute the Information Gain for Weather. Sunny gives 3 Yes and 2 No, Rainy gives 2 Yes and 1 No. The weighted entropy is (5/8) × 0.971 + (3/8) × 0.918 ≈ 0.951, so Gain(Weather) = 0.954 – 0.951 = 0.003.
接下来计算天气的信息增益。晴天有3个是和2个否,雨天有2个是和1个否。加权熵为(5/8) × 0.971 + (3/8) × 0.918 ≈ 0.951,因此Gain(天气) = 0.954 – 0.951 = 0.003。
For Wind, the split produces different results, and the higher gain attribute becomes the root. Such computations are typical of section B exam questions. Practising them with a scientific calculator is essential.
对于风力,分裂产生不同结果,信息增益更高的属性将成为根节点。这类计算是B部分考题的典型内容。使用科学计算器进行练习至关重要。
12. Final Revision Checklist | 最终复习清单
To maximise your score, ensure you can independently reproduce all core experiments without referencing notes. The checklist below covers every essential skill from this article.
为了最大化你的分数,请确保你能在不参考笔记的情况下独立复现所有核心实验。以下清单涵盖本文所有关键技能。
- Fuzzy logic: draw membership functions, apply Min-Max rules, perform defuzzification | 模糊逻辑:绘制隶属函数,应用最小-最大规则,执行去模糊化
- Search algorithms: trace BFS, DFS, Greedy, and A* on small graphs | 搜索算法:在小图上追踪BFS、DFS、贪婪和A*算法
- Logic: translate English sentences into propositional formulas, verify with truth tables | 逻辑:将英文句子转换为命题公式,用真值表验证
- Decision trees: compute entropy and information gain, build the tree | 决策树:计算熵和信息增益,构建树
- Neural networks: forward pass, activation function, weight update | 神经网络:前向传播、激活函数、权重更新
- Expert systems: forward and backward chaining trace | 专家系统:前向链和后向链追踪
- NLP: tokenisation, stop-word removal, frequency tables | 自然语言处理:分词、停顿词去除、频率表
- Ethics: articulate the Turing Test and discuss AI safety | 伦理:阐述图灵测试并讨论AI安全问题
Once you can complete each task confidently, attempt past paper questions under timed conditions. The combination of technical accuracy and clear written reasoning is the key to achieving an A*.
一旦你能自信地完成每项任务,请在计时条件下尝试往年真题。技术准确性与清晰书面推理的结合,是获得A*的关键。
Published by TutorHao | Computer Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导Cancel reply