第62章 从 Method 到功能模块
第59章已经定义:
Matching
↓
Matching Algorithm
第61章进一步建立:
Cognitive Model
↓
State Machine
但是,一个 Method 如果只有一个函数实现,仍然不能直接构成完整的系统能力。
因此第62章解决:
Method
↓
Function
↓
Module
↓
Capability
核心问题是:
如何把认知理论中的 Method 转化为系统中可以独立运行、组合和管理的功能模块。
62.1 Method 的理论位置
在前面的理论体系中:
Method 是认知任务在工程系统中的具体实现过程。
因此 Method 位于:
Cognitive Task
↓
Method
↓
Execution
例如:
Object Recognition
↓
recognizeObject()
Object Matching
↓
matchObject()
Memory Retrieval
↓
retrieveMemory()
Method 描述的是:
系统如何完成一个具体认知操作。
62.2 Method 不等于 Function
Function 是 Method 的一种程序实现形式。
因此:
Method
↓
Function
但两者概念层级不同。
Method
=
认知任务的工程实现定义
而:
Function
=
程序中的可调用执行单元
例如:
理论:
Object Matching
可以实现为:
Function:
matchObject($objectA, $objectB)
所以:
Method ≠ Function
而是:
Method
↓
Function
62.3 为什么需要 Module
当一个认知能力需要多个 Function 协同完成时,就出现了 Module。
例如:
Object Recognition
可能需要:
extractFeatures()
normalizeInput()
identifyType()
matchKnownObjects()
buildObject()
这些 Function 共同完成:
Object Recognition
因此:
Function
↓
Function
↓
Function
↓
Module
模块是:
一组围绕同一认知功能组织起来的 Method / Function 集合。
62.4 Module 的定义
可以定义:
功能模块是围绕特定认知任务,由多个 Method、Function、数据结构和规则组成的独立工程单元。
基本结构:
Module
├── Input
├── Methods
├── Functions
├── Data
├── Rules
├── State
└── Output
因此:
Module
=
Input
+
Processing
+
Data
+
Rules
+
Output
62.5 Method → Function → Module
这是第62章最重要的工程映射。
理论认知任务
↓
Method
↓
Function
↓
Module
↓
System Capability
例如:
Object Recognition
↓
recognizeObject()
↓
ObjectRecognitionModule
↓
Object Recognition Capability
再例如:
Memory Retrieval
↓
retrieveMemory()
↓
MemoryModule
↓
Memory Retrieval Capability
62.6 一个 Module 不一定只有一个 Method
这是必须明确的。
简单模块:
Module A
└── methodA()
复杂模块:
Module B
├── methodA()
├── methodB()
├── methodC()
├── methodD()
└── methodE()
因此:
Module
=
Methods
+
Data
+
Rules
+
State
而不是:
Module = Function
62.7 Method 的输入与输出
一个可工程化的 Method 必须定义 Input 和 Output。
例如:
Method:
matchObject
输入:
Object A
Object B
Matching Criteria
输出:
Matching Result
表示为:
Input
↓
Method
↓
Output
例如:
Object A
Object B
↓
matchObject()
↓
MatchResult
这使 Method 可以被其他模块调用。
62.8 Module 的输入输出
Module 则进一步封装多个 Method。
例如:
ObjectRecognitionModule
输入:
Raw Input
内部:
extractElement()
normalizeElement()
identifyObject()
classifyObject()
输出:
Object
结构:
Raw Input
↓
Object Recognition Module
↓
Object
因此 Module 对外隐藏内部实现,只暴露功能接口。
62.9 Module 的内部结构
一个标准功能模块可以表示为:
Module
│
├── Interface
│
├── Controller
│
├── Methods
│
├── Data
│
├── Rules
│
├── State
│
└── Output
其中:
Interface
对外提供什么功能
Controller
如何组织内部执行
Methods
具体执行过程
Data
使用什么数据
Rules
遵循什么规则
State
当前运行状态
Output
产生什么结果
62.10 Module 与 State Machine
第61章的状态机可以管理 Module 的运行状态。
例如:
ObjectRecognitionModule
可以具有:
Idle
↓
Processing
↓
Recognizing
↓
Completed
因此:
Module
↓
State Machine
↓
Runtime
形成:
Module
├── Methods
├── Data
├── Rules
└── State Machine
这使模块不仅能够执行,还能够管理自身运行状态。
62.11 Module 与 Object
模块处理的是 Data Object。
例如:
ObjectRecognitionModule
处理:
Input Object
输出:
Recognized Object
因此:
Data Object
↓
Module
↓
Data Object
模块并不一定创造全新的对象,也可能:
读取对象
修改对象
分类对象
关联对象
匹配对象
生成对象
62.12 Module 与 Memory
Memory 本身也可以被工程化为功能模块。
例如:
MemoryModule
内部包括:
storeMemory()
retrieveMemory()
updateMemory()
deleteMemory()
matchMemory()
于是:
Memory Theory
↓
Memory Methods
↓
Memory Module
这就是理论到工程的完整转换。
62.13 Module 与 Knowledge
同样:
Knowledge
可以形成:
KnowledgeModule
例如:
storeKnowledge()
retrieveKnowledge()
findRelation()
findClass()
inferKnowledge()
updateKnowledge()
形成:
Knowledge
↓
Knowledge Methods
↓
Knowledge Module
因此:
Memory Module
Knowledge Module
Matching Module
Reasoning Module
Decision Module
可以成为个体认知系统的基础功能模块。
62.14 核心认知功能模块
按照前面的理论体系,可以建立:
Cognitive System
│
├── Perception Module
├── Element Module
├── Object Module
├── Class Module
├── Relation Module
├── Memory Module
├── Knowledge Module
├── Matching Module
├── Reasoning Module
├── Decision Module
├── Action Module
└── Learning Module
这些模块不是简单的软件目录。
它们对应:
认知能力
↓
工程功能
62.15 Perception Module
感知模块负责:
Input
↓
Element
可能包含:
receiveInput()
extractElement()
normalizeInput()
identifySignal()
输出:
Element
结构:
Input
↓
Perception Module
↓
Elements
62.16 Object Module
对象模块负责:
Element
↓
Object
可能包括:
createObject()
identifyObject()
updateObject()
getObject()
结构:
Element
↓
Object Module
↓
Object
62.17 Class Module
Class Module 负责:
Object
↓
Class
以及:
Class
↓
Object Classification
可以包括:
createClass()
findClass()
classifyObject()
inheritClass()
62.18 Relation Module
Relation Module 负责建立对象之间的关系:
Object A
↓
Relation
↓
Object B
例如:
createRelation()
findRelation()
removeRelation()
updateRelation()
最终形成:
Object Graph
62.19 Matching Module
第59章的 Matching Algorithm 可以封装成:
MatchingModule
内部:
exactMatch()
attributeMatch()
relationMatch()
contextMatch()
calculateScore()
evaluateResult()
对外:
match(A, B)
因此:
Matching Theory
↓
Matching Methods
↓
Matching Module
62.20 Reasoning Module
推理模块负责:
Knowledge
+
Rules
+
Objects
+
Relations
↓
Reasoning
可以包括:
findPremise()
applyRule()
deriveRelation()
inferConclusion()
validateInference()
输出:
Reasoning Result
62.21 Decision Module
决策模块负责:
Reasoning Result
↓
Decision
可以包括:
evaluateOption()
compareOptions()
selectAction()
createDecision()
形成:
Decision Module
62.22 Learning Module
学习模块负责修改个体模型:
Experience
↓
Learning
↓
Memory Update
↓
Knowledge Update
↓
Model Update
可以包括:
learn()
updateMemory()
updateKnowledge()
updateRelation()
updateModel()
因此:
Learning Module
实际上连接:
Runtime
↓
Individual Model
62.23 Module 之间的关系
这些模块不是孤立的。
它们之间存在数据流:
Perception
↓
Element
↓
Object
↓
Class
↓
Relation
↓
Matching
↓
Memory / Knowledge
↓
Reasoning
↓
Decision
↓
Action
↓
Learning
因此:
功能模块是认知过程的工程化组织形式。
62.24 Module 与 Module 的调用
一个模块可以调用另一个模块。
例如:
ReasoningModule
↓
KnowledgeModule
↓
RelationModule
↓
ObjectModule
又例如:
MatchingModule
↓
ObjectModule
↓
ClassModule
↓
RelationModule
因此模块之间形成:
Module Dependency
但这种依赖应该保持明确。
62.25 Interface
模块必须有明确接口。
例如:
MatchingModule
对外只暴露:
match()
内部可能有:
exactMatch()
attributeMatch()
relationMatch()
contextMatch()
calculateScore()
调用者不需要知道内部细节。
因此:
External
↓
Public Interface
↓
Module
↓
Internal Methods
这就是模块封装。
62.26 Method 的复用
一个 Method 可以被多个模块使用。
例如:
normalizeObject()
可能被:
ObjectModule
MatchingModule
ReasoningModule
LearningModule
共同调用。
因此:
Method
可以作为底层可复用执行单元。
而:
Module
负责将这些执行单元组织成完整能力。
62.27 Module 的组合
多个模块还可以组合成更高层模块。
例如:
Object Intelligence Module
可以组合:
ObjectModule
ClassModule
RelationModule
MatchingModule
进一步:
Cognitive Engine
可以组合:
PerceptionModule
MemoryModule
KnowledgeModule
ReasoningModule
DecisionModule
LearningModule
因此形成:
Function
↓
Module
↓
Composite Module
↓
Engine
↓
System
62.28 Capability
当一个模块能够稳定完成某种认知任务时,可以将其抽象为 Capability。
例如:
MatchingModule
↓
Matching Capability
ReasoningModule
↓
Reasoning Capability
LearningModule
↓
Learning Capability
因此:
Method
↓
Function
↓
Module
↓
Capability
这是从程序结构到系统能力的转换。
62.29 Module 与 Capability 的区别
二者也不能混淆。
Module
=
怎么实现
而:
Capability
=
能够做什么
例如:
MatchingModule
是工程实现。
而:
Matching Capability
表示系统:
能够进行对象匹配
因此:
Module = Implementation Unit
Capability = Functional Ability
62.30 从 Method 到功能模块
因此第62章的核心转换可以正式定义为:
Cognitive Task
↓
Method
↓
Function
↓
Module
↓
Capability
对应:
认知任务
↓
实现方法
↓
程序函数
↓
功能模块
↓
系统能力
62.31 与状态机的连接
第61章:
State Machine
第62章:
Module
二者结合:
State
↓
Module
↓
Method
↓
Result
↓
Transition
例如:
Matching State
↓
Matching Module
↓
match()
↓
Matching Result
↓
Reasoning State
于是:
State Machine
负责:
什么时候执行。
而:
Module
负责:
执行什么功能。
Method 则负责:
具体怎么执行。
三者形成清晰分工:
State
↓
决定当前阶段
Module
↓
决定当前功能
Method
↓
决定具体实现
62.32 个体认知系统的模块化结构
将第60、61、62章统一:
Individual
↓
Individual Cognitive Model
↓
Cognitive State Machine
↓
Cognitive Modules
↓
Methods
↓
Functions
↓
Data
↓
Results
最终形成:
┌────────────────────────────┐
│ Individual AI System │
├────────────────────────────┤
│ Cognitive State Machine │
├────────────────────────────┤
│ Perception Module │
│ Object Module │
│ Class Module │
│ Relation Module │
│ Memory Module │
│ Knowledge Module │
│ Matching Module │
│ Reasoning Module │
│ Decision Module │
│ Action Module │
│ Learning Module │
└────────────────────────────┘
62.33 工程数据结构
一个模块可以抽象为:
Module
{
id,
name,
type,
version,
state,
methods,
dependencies,
input,
output,
config
}
Method:
Method
{
id,
name,
input,
output,
rules,
implementation
}
Capability:
Capability
{
id,
name,
module,
methods,
input,
output
}
由此形成:
Module
↓
Methods
↓
Functions
↓
Data
62.34 一个完整示例
以 Object Matching 为例。
理论层:
Matching
↓
工程 Method:
ObjectMatchingMethod
↓
Function:
matchObject()
↓
Module:
MatchingModule
↓
Capability:
Object Matching Capability
↓
State Machine:
Matching
↓
Executing
↓
Completed
↓
Result:
MatchingResult
完整链条:
Matching Theory
↓
Matching Method
↓
matchObject()
↓
Matching Module
↓
Matching Capability
↓
State Machine
↓
Matching Result
这就是从认知理论到软件系统能力的完整工程化路径。
62.35 第62章核心定义
Method
Method 是认知任务在工程系统中的具体实现过程。
Function
Function 是 Method 在程序执行层中的可调用实现单元。
Module
Module 是围绕特定功能组织多个 Method、Function、数据、规则和状态的独立工程单元。
Capability
Capability 是系统通过一个或多个功能模块能够实际完成的认知能力。
62.36 最终模型
第62章最终形成:
Cognitive Task
↓
Method
↓
Function
↓
Module
↓
Capability
如果加入第61章:
State Machine
↓
State
↓
Module
↓
Method
↓
Function
↓
Data
↓
Result
↓
Transition
最终整个 WSaiOS 工程认知链变成:
Element
↓
Object
↓
Class
↓
Relation
↓
Cognitive Model
↓
State Machine
↓
Module
↓
Method
↓
Function
↓
Data
↓
Computation
↓
Result
↓
Learning
↓
Model Update
因此,第62章完成的是一个非常关键的工程转换:
Method 解决“如何执行一个认知任务”,Module 解决“如何组织多个执行过程形成一个完整功能”,Capability 则表示“系统因此具备了什么能力”。
最终形成:
Method
↓
执行单元
Module
↓
功能单元
Capability
↓
能力单元
这使 WSaiOS 从认知模型 + 状态机进一步进入真正的模块化认知操作系统结构。