首页 理论 架构 工程 文档 白皮书 著作 研究 案例 下载 博客 关于 开始使用 →

第246章 ICAI学习MVC

第246章 ICAI学习MVC

246.1 学习MVC提出背景

在ICAI运行过程中,认知产生判断,行为产生动作,动作产生结果,结果又会产生新的信息。

如果机器个体只完成:

Cognition→Behavior→Action→ResultCognition\rightarrow Behavior\rightarrow Action\rightarrow Result

而不能进一步处理结果,那么机器个体的运行就只能停留在一次性的行为层面。

真正具有持续性的机器个体必须能够把行为结果转化为后续可使用的信息,并经过记忆、经验和学习形成个体自身的更新。

因此,ICAI需要建立独立的学习处理链:

Feedback→Memory→Experience→Learning→UpdateFeedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow Update

这就是ICAI学习MVC的基本结构。

学习MVC并不是传统意义上的模型训练系统,而是机器个体对自身运行过程中产生的信息、结果、反馈、经验和知识结构进行整理、比较、归纳、更新和保存的工程机制。


246.2 ICAI学习MVC定义

ICAI学习MVC是将机器个体运行产生的反馈信息,通过学习服务和学习引擎进行处理,并最终更新机器个体记忆、知识、能力、方法、状态或其他个体结构的一种工程架构。

其基本结构为:

LearningRequest→Controller→LearningService→LearningEngine→Feedback→Memory→Experience→Learning→UpdateLearningRequest \rightarrow Controller \rightarrow LearningService \rightarrow LearningEngine \rightarrow Feedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow Update

如果学习过程中需要读取历史数据:

LearningEngine→DomainObject→Repository→MySQLLearningEngine \rightarrow DomainObject \rightarrow Repository \rightarrow MySQL

如果学习完成后需要保存新的学习结果:

Learning→Update→DomainObject→Repository→MySQLLearning \rightarrow Update \rightarrow DomainObject \rightarrow Repository \rightarrow MySQL

因此,完整学习链可以表示为:

Result→Feedback→Memory→Experience→Learning→UpdateResult \rightarrow Feedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow Update


246.3 学习MVC的五个核心对象

ICAI学习MVC包含五个核心概念:

LearningMVC={Feedback,Memory,Experience,Learning,Update}LearningMVC= \{Feedback,Memory,Experience,Learning,Update\}

其中:

**Feedback(反馈)**负责描述行为或动作产生的结果信息。

**Memory(记忆)**负责保存机器个体已经获得并需要继续使用的信息。

**Experience(经验)**负责从历史运行过程中形成具有应用价值的经验结构。

**Learning(学习)**负责对反馈、记忆和经验进行计算、比较、归纳和知识更新。

**Update(更新)**负责将学习结果实际作用于机器个体。

五者之间并不是简单的数据保存关系,而是一条逐步转换关系:

Feedback→Memory→Experience→Learning→UpdateFeedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow Update


246.4 Feedback反馈

Feedback是机器个体对自身行为结果进行再次获取和描述的信息。

在第245章中:

Behavior→Action→ResultBehavior\rightarrow Action\rightarrow Result

第246章进一步建立:

Result→FeedbackResult\rightarrow Feedback

反馈不是简单复制Result。

Result描述的是某次动作或行为产生了什么结果,而Feedback描述的是这个结果对于机器个体后续运行具有什么信息意义。

因此:

Result≠FeedbackResult\neq Feedback

可以定义:

Feedback={Source,Result,Condition,Evaluation,Time,Meaning}Feedback= \{Source,Result,Condition,Evaluation,Time,Meaning\}

其中:

  • Source表示反馈来源;
  • Result表示原始结果;
  • Condition表示结果发生时的条件;
  • Evaluation表示对结果的评价;
  • Time表示反馈产生时间;
  • Meaning表示反馈对于个体运行的意义。

246.5 Feedback与行为结果

行为产生结果:

Behavior→Action→ResultBehavior \rightarrow Action \rightarrow Result

结果产生反馈:

Result→FeedbackResult \rightarrow Feedback

因此完整关系为:

Behavior→Action→Result→FeedbackBehavior \rightarrow Action \rightarrow Result \rightarrow Feedback

例如一个机器个体执行某项业务操作:

目标:完成某项任务
        ↓
行为:执行任务
        ↓
动作:调用具体业务方法
        ↓
结果:任务完成
        ↓
反馈:该方法在当前条件下能够有效完成任务

反馈因此成为学习系统的入口。


246.6 Feedback的分类

为了支持后续学习,反馈可以按照来源和意义进行分类。

例如:

ResultFeedback
StateFeedback
BehaviorFeedback
GoalFeedback
UserFeedback
SystemFeedback
ErrorFeedback
ExceptionFeedback
EnvironmentFeedback

这些反馈并不意味着使用复杂的智能模型进行分类,而是根据预先定义的对象、状态、规则和条件进行离散判断。

例如:

FeedbackType=f(Result,State,Condition,Rule)FeedbackType= f(Result,State,Condition,Rule)

如果某动作执行成功,则形成成功反馈。

如果动作执行失败,则形成失败反馈。

如果动作成功但目标没有完成,则形成目标未完成反馈。

因此:

ActionSuccess≠GoalCompletedActionSuccess\neq GoalCompleted

这一原则同样适用于学习系统。


246.7 Memory记忆

Memory是机器个体对运行过程中需要继续保留的信息进行结构化保存的机制。

机器个体的记忆不是单纯的数据表。

它至少可以包含:

Memory={Information,State,Behavior,Result,Feedback,Experience,History}Memory= \{ Information, State, Behavior, Result, Feedback, Experience, History \}

因此:

Memory≠DatabaseMemory\neq Database

数据库只是持久化介质。

Memory是机器个体层面的领域对象。

其工程关系为:

MemoryObject→Repository→MySQLMemoryObject \rightarrow Repository \rightarrow MySQL

而不是:

Memory=MySQLMemory=MySQL


246.8 Memory的作用

记忆至少承担五项功能:

第一,保存历史信息。

第二,保存过去状态。

第三,保存行为结果。

第四,保存反馈。

第五,为后续经验形成和学习计算提供数据。

因此:

Memory→ExperienceMemory \rightarrow Experience

同时:

Memory→LearningMemory \rightarrow Learning

记忆既是历史保存结构,也是学习输入结构。


246.9 Memory与当前状态

机器个体必须区分当前状态与历史记忆。

因此:

CurrentState≠MemoryCurrentState\neq Memory

当前状态描述机器个体现在是什么状态。

记忆描述机器个体过去发生过什么,以及哪些信息仍然具有后续使用价值。

例如:

当前状态:
任务执行中

历史记忆:
过去三次执行记录
过去三次执行结果
过去三次失败原因
过去成功使用的方法

因此:

CurrentState→RuntimeCurrentState\rightarrow Runtime

而:

Memory→HistoryMemory\rightarrow History

二者共同参与后续认知和学习。


246.10 Experience经验

Experience是机器个体从历史运行信息中形成的、能够支持后续判断和行为的结构化经验。

经验不是原始数据。

例如:

历史数据:
第一次执行失败
第二次执行成功
第三次执行成功

经过整理后,可以形成:

经验:
在条件A下,方法B成功率较高。

因此:

Experience=F(Memory,Feedback,Result,Condition)Experience=F(Memory,Feedback,Result,Condition)

经验的核心价值在于把历史运行信息转换为后续可以调用的经验资源。


246.11 Memory与Experience的区别

Memory和Experience必须严格区分。

Memory≠ExperienceMemory\neq Experience

Memory主要回答:

过去发生了什么?

Experience主要回答:

从过去发生的事情中形成了什么可以继续使用的经验?

例如:

Memory:
2026-09-01 使用方法A,结果失败。

Memory:
2026-09-02 使用方法B,结果成功。

Memory:
2026-09-03 使用方法B,结果成功。

经过学习处理,可以形成:

Experience:
在条件C下,方法B比方法A更适合。

因此:

Memory→ExperienceMemory\rightarrow Experience

是从历史信息到经验结构的转换。


246.12 Learning学习

Learning是ICAI对反馈、记忆和经验进行计算,并形成个体更新结果的过程。

可以定义:

Learning=F(Feedback,Memory,Experience,Knowledge,Condition)Learning= F(Feedback,Memory,Experience,Knowledge,Condition)

其中:

  • Feedback是当前或近期反馈;
  • Memory是历史记忆;
  • Experience是已有经验;
  • Knowledge是已有知识;
  • Condition是学习发生的条件。

学习的结果不是一句自然语言,而是结构化的更新信息。

例如:

LearningResult={Object,ChangedField,OldValue,NewValue,Reason,Source,Time}LearningResult= \{ Object, ChangedField, OldValue, NewValue, Reason, Source, Time \}


246.13 ICAI学习不是模型训练

ICAI中的Learning必须与传统模型训练严格区分。

ICAI学习可以通过:

比较
统计
规则
条件判断
状态判断
历史记录
结果评价
经验形成
知识更新
能力调整
方法调整

完成。

其基本计算形式可以表示为:

L=F(M,E,Fb,K,R,C)L=F(M,E,Fb,K,R,C)

其中:

  • LL 表示Learning;
  • MM 表示Memory;
  • EE 表示Experience;
  • FbFb 表示Feedback;
  • KK 表示Knowledge;
  • RR 表示Rule;
  • CC 表示Condition。

这里的计算属于结构化、离散化和规则化计算。

ICAI学习不依赖神经网络、Transformer、Embedding、向量搜索、Prompt或大模型生成机制。


246.14 LearningService

LearningService负责组织学习业务流程。

其职责不是直接执行所有学习计算,而是组织:

Feedback读取
↓
Memory读取
↓
Experience读取
↓
LearningEngine调用
↓
LearningResult处理
↓
Update执行

因此:

LearningService≠LearningEngineLearningService \neq LearningEngine

LearningService回答:

学习业务应该怎样组织?

LearningEngine回答:

学习计算应该怎样执行?


246.15 LearningEngine

LearningEngine是学习计算的核心工程对象。

其基本输入为:

LearningInput={Feedback,Memory,Experience,Knowledge,Condition}LearningInput= \{Feedback,Memory,Experience,Knowledge,Condition\}

其基本输出为:

LearningResultLearningResult

因此:

LearningEngine:LearningInput→LearningResultLearningEngine : LearningInput \rightarrow LearningResult

LearningEngine可以执行:

反馈比较
历史比较
状态比较
结果比较
经验判断
规则判断
条件判断
变化识别
更新建议生成

最终形成结构化学习结果。


246.16 LearningResult

LearningResult用于描述学习计算产生的结果。

可以定义:

LearningResult={Status,Object,Change,Reason,Source,Condition,Time}LearningResult= \{ Status, Object, Change, Reason, Source, Condition, Time \}

其中:

  • Status表示学习是否成功;
  • Object表示受到影响的对象;
  • Change表示产生的变化;
  • Reason表示变化原因;
  • Source表示学习依据;
  • Condition表示适用条件;
  • Time表示学习发生时间。

例如:

Status: success
Object: Method
Change: method-A → method-B
Reason: method-B在相同条件下连续成功
Condition: condition-C

这就是可执行的结构化学习结果。


246.17 Update更新

Update表示将学习结果实际作用到机器个体结构中。

因此:

Learning≠UpdateLearning\neq Update

Learning负责形成:

应该发生什么变化。

Update负责执行:

实际发生什么变化。

两者关系为:

Learning→LearningResult→UpdateLearning \rightarrow LearningResult \rightarrow Update


246.18 Update的对象

Update可以作用于多个机器个体结构。

例如:

Memory
Experience
Knowledge
Capability
Method
Goal
State
Behavior
Relation
Rule

因此:

Update(Object,LearningResult)→Object′Update(Object,LearningResult) \rightarrow Object’

其中Object表示原对象,Object’表示更新后的对象。


246.19 Update前后的对象变化

设机器个体对象为:

OtO_t

学习结果为:

LtL_t

更新后的对象为:

Ot+1O_{t+1}

则:

Ot+1=Update(Ot,Lt)O_{t+1}=Update(O_t,L_t)

这意味着学习真正改变的是机器个体的结构或状态,而不是只产生一条学习日志。


246.20 Update与Repository

Update不能直接修改MySQL。

正确结构为:

Update→DomainObject→Repository→MySQLUpdate \rightarrow DomainObject \rightarrow Repository \rightarrow MySQL

也就是说,首先更新Domain Object:

Ot→Ot+1O_t\rightarrow O_{t+1}

然后由Repository负责持久化:

Ot+1→Repository→MySQLO_{t+1} \rightarrow Repository \rightarrow MySQL

因此:

Update≠RepositoryUpdate\neq Repository

同时:

Update≠MySQLUpdate\neq MySQL


246.21 学习MVC完整数据流

将五个核心环节连接起来:

Feedback→Memory→Experience→Learning→UpdateFeedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow Update

加入MVC:

LearningRequest→Controller→LearningService→LearningEngine→LearningResult→UpdateLearningRequest \rightarrow Controller \rightarrow LearningService \rightarrow LearningEngine \rightarrow LearningResult \rightarrow Update

加入持久化:

LearningEngine→DomainObject→Repository→MySQLLearningEngine \rightarrow DomainObject \rightarrow Repository \rightarrow MySQL

因此形成完整结构:

Controller→LearningService→LearningEngine→DomainObject→Repository→MySQLController \rightarrow LearningService \rightarrow LearningEngine \rightarrow DomainObject \rightarrow Repository \rightarrow MySQL

读取方向则为:

MySQL→Repository→DomainObject→LearningEngineMySQL \rightarrow Repository \rightarrow DomainObject \rightarrow LearningEngine


246.22 ICAI学习MVC完整流程

完整学习流程可以表示为:

Result→Feedback→Memory→Experience→Learning→LearningResult→Update→DomainObject→Repository→MySQLResult \rightarrow Feedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow LearningResult \rightarrow Update \rightarrow DomainObject \rightarrow Repository \rightarrow MySQL

如果更新结果会影响后续认知,则进一步形成:

Update→CognitionUpdate \rightarrow Cognition

如果更新结果影响后续行为,则:

Update→Capability→Method→BehaviorUpdate \rightarrow Capability \rightarrow Method \rightarrow Behavior

因此:

Behavior→Result→Feedback→Memory→Experience→Learning→Update→CognitionBehavior \rightarrow Result \rightarrow Feedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow Update \rightarrow Cognition

形成完整的个体循环。


246.23 学习与认知的关系

第244章建立了:

CognitiveRequest→CognitiveEngine→CognitiveResultCognitiveRequest \rightarrow CognitiveEngine \rightarrow CognitiveResult

第246章建立:

Feedback→Learning→UpdateFeedback \rightarrow Learning \rightarrow Update

两者连接以后:

Cognition→Behavior→Result→Feedback→Learning→Update→CognitionCognition \rightarrow Behavior \rightarrow Result \rightarrow Feedback \rightarrow Learning \rightarrow Update \rightarrow Cognition

这意味着学习不是独立于认知之外的模块,而是能够改变后续认知条件的个体内部循环。


246.24 学习与能力的关系

能力是机器个体可以执行某类任务的结构。

学习可以改变能力。

例如:

Capabilityt→LearningCapabilityt+1Capability_t \xrightarrow{Learning} Capability_{t+1}

但并不是所有学习都会改变能力。

某些学习只增加记忆:

Learning→MemoryLearning\rightarrow Memory

某些学习形成经验:

Learning→ExperienceLearning\rightarrow Experience

某些学习更新知识:

Learning→KnowledgeLearning\rightarrow Knowledge

某些学习更新能力:

Learning→CapabilityLearning\rightarrow Capability

因此:

LearningResult→UpdateTargetLearningResult \rightarrow UpdateTarget

UpdateTarget决定实际改变哪个个体对象。


246.25 学习与方法的关系

方法是机器个体完成目标时可以调用的结构。

学习可以根据历史结果改变方法选择条件。

例如:

Methodt→Result→Feedback→Learning→Methodt+1Method_t \rightarrow Result \rightarrow Feedback \rightarrow Learning \rightarrow Method_{t+1}

这并不是重新生成一个不可解释的模型,而是对方法对象的结构化属性进行修改。

例如:

Method A
适用条件:C1
历史成功次数:3
历史失败次数:5

Method B
适用条件:C1
历史成功次数:8
历史失败次数:1

学习后可以形成:

C1条件下优先选择Method B

这种变化可以由明确规则和历史统计产生。


246.26 学习与知识更新

知识是机器个体可以调用的能力资源。

学习可以形成新的知识关系:

Learning→KnowledgeUpdateLearning \rightarrow KnowledgeUpdate

例如:

对象A
↓
条件C
↓
方法B
↓
结果成功

经过学习后形成:

知识:
对象A在条件C下适合使用方法B。

因此:

Knowledget+1=Update(Knowledget,LearningResult)Knowledge_{t+1} = Update(Knowledge_t,LearningResult)

知识更新仍然属于结构化数据更新。


246.27 学习与经验更新

经验本身也可以继续变化。

设:

ExperiencetExperience_t

经过新的反馈和学习:

Experiencet+1=Update(Experiencet,LearningResult)Experience_{t+1} = Update(Experience_t,LearningResult)

例如:

原经验:
方法B通常适用于条件C。

新反馈:
方法B在条件C2下连续成功。

新经验:
方法B适用于C和C2。

因此经验并不是一次建立以后永远不变,而是可以随着新的历史数据不断更新。


246.28 学习与记忆更新

学习本身也需要进入记忆。

因此:

Learning→MemoryLearning \rightarrow Memory

形成新的历史:

反馈记录
↓
学习记录
↓
更新记录
↓
新的运行记录

从而:

Memoryt+1=Memoryt+LearningHistoryMemory_{t+1} = Memory_t + LearningHistory

这使机器个体能够保留自身的发展过程。


246.29 学习循环

ICAI学习可以建立如下循环:

Feedback→Memory→Experience→Learning→Update→MemoryFeedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow Update \rightarrow Memory

即:

Feedback→Memory→Experience→Learning→Update→MemoryFeedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow Update \rightarrow Memory

Update产生新的个体状态和知识结构,这些变化又进入后续记忆。

因此:

Memoryt+1=F(Memoryt,Feedback,Learning,Update)Memory_{t+1} = F(Memory_t,Feedback,Learning,Update)


246.30 学习MVC与行为MVC的连接

第245章的核心链:

Behavior→Action→ResultBehavior \rightarrow Action \rightarrow Result

第246章:

Result→Feedback→Learning→UpdateResult \rightarrow Feedback \rightarrow Learning \rightarrow Update

连接后:

Behavior→Action→Result→Feedback→Memory→Experience→Learning→UpdateBehavior \rightarrow Action \rightarrow Result \rightarrow Feedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow Update

因此行为产生学习材料,学习又改变未来行为条件。


246.31 学习MVC与认知MVC的连接

第244章:

Input→Cognition→CognitiveResultInput \rightarrow Cognition \rightarrow CognitiveResult

第245章:

CognitiveResult→BehaviorCognitiveResult \rightarrow Behavior

第246章:

Result→Feedback→Learning→UpdateResult \rightarrow Feedback \rightarrow Learning \rightarrow Update

最终形成:

Input→Cognition→Behavior→Action→Result→Feedback→Memory→Experience→Learning→Update→CognitionInput \rightarrow Cognition \rightarrow Behavior \rightarrow Action \rightarrow Result \rightarrow Feedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow Update \rightarrow Cognition

这就是ICAI认知、行为和学习之间的闭环。


246.32 学习失败

学习本身也可能失败。

因此需要区分:

FeedbackFailure
MemoryFailure
ExperienceFailure
LearningFailure
UpdateFailure
PersistenceFailure

例如:

LearningFailure≠UpdateFailureLearningFailure\neq UpdateFailure

学习计算失败,表示没有形成有效学习结果。

更新失败,表示已经形成学习结果,但是没有成功作用于Domain Object。

持久化失败,则表示Domain Object已经变化,但没有成功保存到MySQL。

因此:

LearningFailure≠UpdateFailure≠PersistenceFailureLearningFailure \neq UpdateFailure \neq PersistenceFailure


246.33 学习结果验证

学习不能因为产生LearningResult就认为成功。

必须进行更新验证。

完整流程:

Learning→LearningResult→Update→VerificationLearning \rightarrow LearningResult \rightarrow Update \rightarrow Verification

验证至少检查:

目标对象是否正确
旧值是否正确
新值是否正确
更新条件是否满足
Domain Object是否变化
Repository是否保存成功
持久化结果是否正确

因此:

LearningCompleted≠UpdateCompletedLearningCompleted\neq UpdateCompleted

同时:

UpdateCompleted≠PersistenceCompletedUpdateCompleted\neq PersistenceCompleted


246.34 学习历史

为了支持机器个体长期运行,需要保存学习历史。

可以定义:

LearningHistory={Feedback,Learning,Update,Result,Time}LearningHistory= \{ Feedback, Learning, Update, Result, Time \}

其基本关系:

Feedbackt→Learningt→UpdatetFeedback_t \rightarrow Learning_t \rightarrow Update_t

并保存:

History={H1,H2,…,Hn}History=\{H_1,H_2,\ldots,H_n\}

这样机器个体可以知道:

什么时候学习
为什么学习
依据什么学习
学习改变了什么
改变是否成功
改变以后产生了什么结果

这为后续诊断和自我维护提供基础。


246.35 学习与自我维护

学习MVC还可以与第151章建立的维护结构连接。

维护结构为:

Maintenance=Risk+Protection+Conflict+Diagnosis+RepairMaintenance= Risk+Protection+Conflict+Diagnosis+Repair

当系统发现异常:

Detection→Feedback→LearningDetection \rightarrow Feedback \rightarrow Learning

学习可以帮助判断:

异常是否重复
异常发生条件
异常历史
异常影响
过去采用的修复方法
修复结果

然后:

Learning→RepairMethod→UpdateLearning \rightarrow RepairMethod \rightarrow Update

因此学习能够为自我维护提供历史经验。


246.36 Learning Domain Object

工程上,学习过程不能只使用数组或数据库记录,而应该建立对应的领域对象。

例如:

class LearningRecord
{
    protected $id;
    protected $individualId;
    protected $feedbackId;
    protected $memoryId;
    protected $experienceId;
    protected $targetType;
    protected $targetId;
    protected $oldValue;
    protected $newValue;
    protected $reason;
    protected $status;
}

这个对象描述的是一次学习记录,而不是一张数据库表。

因此:

LearningRecord≠DatabaseRecordLearningRecord \neq DatabaseRecord

它属于ICAI领域模型的一部分。


246.37 LearningEngine工程结构

LearningEngine可以承担:

读取学习输入
↓
检查反馈
↓
读取记忆
↓
分析历史
↓
形成经验
↓
执行学习规则
↓
生成LearningResult
↓
交给Update

其工程关系:

LearningService→LearningEngineLearningService \rightarrow LearningEngine

LearningEngine再调用:

LearningEngine→MemoryObjectLearningEngine \rightarrow MemoryObject LearningEngine→ExperienceObjectLearningEngine \rightarrow ExperienceObject LearningEngine→DomainObjectLearningEngine \rightarrow DomainObject

最终形成:

LearningEngine→LearningResultLearningEngine \rightarrow LearningResult


246.38 LearningService与LearningEngine边界

必须严格区分:

LearningService≠LearningEngineLearningService\neq LearningEngine

LearningService负责:

业务流程组织
事务边界
对象准备
Engine调用
结果处理
Update协调

LearningEngine负责:

反馈分析
记忆分析
经验判断
规则计算
学习计算
学习结果形成

因此:

Service=ProcessService=Process Engine=CalculationEngine=Calculation


246.39 Learning Update工程边界

Update可以由独立的UpdateService或UpdateEngine承担。

例如:

LearningEngine→LearningResult→UpdateEngine→DomainObjectLearningEngine \rightarrow LearningResult \rightarrow UpdateEngine \rightarrow DomainObject

然后:

DomainObject→Repository→MySQLDomainObject \rightarrow Repository \rightarrow MySQL

因此:

UpdateEngine≠LearningEngineUpdateEngine\neq LearningEngine

二者职责不同。

LearningEngine负责回答:

学到了什么?

UpdateEngine负责回答:

如何把学到的内容作用到机器个体?


246.40 ICAI学习MVC完整工程模型

最终形成:

Controller
    ↓
LearningService
    ↓
LearningEngine
    ↓
Feedback
    ↓
Memory
    ↓
Experience
    ↓
Learning
    ↓
LearningResult
    ↓
Update
    ↓
Domain Object
    ↓
Repository
    ↓
MySQL

如果学习结果改变认知:

Update
    ↓
Cognition

如果学习结果改变行为:

Update
    ↓
Capability
    ↓
Method
    ↓
Behavior
    ↓
Action
    ↓
Result
    ↓
Feedback

因此最终形成完整闭环:

Cognition→Behavior→Action→Result→Feedback→Memory→Experience→Learning→Update→CognitionCognition \rightarrow Behavior \rightarrow Action \rightarrow Result \rightarrow Feedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow Update \rightarrow Cognition


246.41 ICAI学习MVC与个体发展

ICAI中的学习不是独立事件,而是机器个体持续发展的机制。

设机器个体在时间tt的结构为:

ItI_t

经过一次运行和学习:

It→Feedback→Learning→Update→It+1I_t \rightarrow Feedback \rightarrow Learning \rightarrow Update \rightarrow I_{t+1}

因此:

It+1=Update(It,LearningResult)I_{t+1}=Update(I_t,LearningResult)

连续运行以后:

I0→I1→I2→⋯→InI_0\rightarrow I_1\rightarrow I_2\rightarrow\cdots\rightarrow I_n

这意味着机器个体可以通过自身历史形成持续变化的个体结构。


246.42 ICAI学习MVC统一模型

综合本章,可以建立:

LearningMVC=Feedback+Memory+Experience+Learning+UpdateLearningMVC= Feedback + Memory + Experience + Learning + Update

其完整数据流为:

Result→Feedback→Memory→Experience→Learning→LearningResult→Update→DomainObject→Repository→MySQLResult \rightarrow Feedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow LearningResult \rightarrow Update \rightarrow DomainObject \rightarrow Repository \rightarrow MySQL

其完整运行闭环为:

Cognition→Behavior→Action→Result→Feedback→Memory→Experience→Learning→Update→CognitionCognition \rightarrow Behavior \rightarrow Action \rightarrow Result \rightarrow Feedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow Update \rightarrow Cognition

其MVC工程结构为:

Controller→LearningService→LearningEngine→DomainObject→Repository→MySQLController \rightarrow LearningService \rightarrow LearningEngine \rightarrow DomainObject \rightarrow Repository \rightarrow MySQL


246.43 ICAI学习MVC核心边界

本章建立以下工程边界:

Result≠FeedbackResult\neq Feedback Feedback≠MemoryFeedback\neq Memory Memory≠ExperienceMemory\neq Experience Experience≠LearningExperience\neq Learning Learning≠UpdateLearning\neq Update Update≠RepositoryUpdate\neq Repository Repository≠MySQLRepository\neq MySQL

同时:

LearningService≠LearningEngineLearningService\neq LearningEngine LearningEngine≠DomainObjectLearningEngine\neq DomainObject DomainObject≠DatabaseRecordDomainObject\neq DatabaseRecord

这些边界保证学习系统不会退化为简单的数据存储模块。


246.44 本章总结

第246章建立了ICAI学习MVC。

其核心不是单独定义一个“学习模块”,而是建立从行为结果到个体变化的完整工程链:

Feedback→Memory→Experience→Learning→UpdateFeedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow Update

Feedback负责获取运行结果的反馈意义。

Memory负责保存机器个体的历史信息。

Experience负责从历史信息中形成可继续使用的经验。

Learning负责对反馈、记忆、经验、知识、规则和条件进行结构化计算。

Update负责将学习结果真正作用于机器个体。

因此,ICAI学习的核心关系可以表示为:

LearningResult=F(Feedback,Memory,Experience,Knowledge,Rule,Condition)LearningResult = F(Feedback,Memory,Experience,Knowledge,Rule,Condition)

并通过:

Update(It,LearningResult)=It+1Update(I_t,LearningResult)=I_{t+1}

使机器个体从当前状态发展到新的个体状态。

最终形成:

Cognition→Behavior→Action→Result→Feedback→Memory→Experience→Learning→Update→CognitionCognition \rightarrow Behavior \rightarrow Action \rightarrow Result \rightarrow Feedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow Update \rightarrow Cognition

这一闭环使ICAI从“能够认知和执行的机器个体”,进一步形成“能够根据自身运行历史持续积累、调整和发展的机器个体”。

这也是ICAI学习MVC与普通业务MVC最重要的区别:普通MVC主要完成一次业务请求,而ICAI学习MVC不仅处理一次运行结果,而且把运行结果转化为机器个体自身未来运行的一部分。

因此:

ICAI Learning=Feedback+Memory+Experience+Learning+UpdateICAI\ Learning = Feedback + Memory + Experience + Learning + Update

最终形成:

Individualt→Run→Feedback→Learning→Individualt+1Individual_{t} \rightarrow Run \rightarrow Feedback \rightarrow Learning \rightarrow Individual_{t+1}

机器个体由此进入持续运行、持续记忆、持续经验形成、持续学习和持续更新的个体生命周期。

第246章 ICAI学习MVC——真实运行示例补充

246.45 学习MVC真实运行示例

前面的理论建立了:

Feedback→Memory→Experience→Learning→UpdateFeedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow Update

但是,只有当这条链能够真正运行,并且运行结果能够改变机器个体后续状态时,学习MVC才具有工程意义。

因此,本节建立一个不依赖外部框架、不依赖大模型的完整PHP运行示例。

示例模拟一个简单的机器个体:

机器个体:ICAI-001
任务:处理任务请求
方法A:method_A
方法B:method_B

机器个体第一次运行时使用method_A

如果连续运行发现:

method_A:失败
method_B:成功

学习系统就需要完成:

Result
↓
Feedback
↓
Memory
↓
Experience
↓
Learning
↓
Update
↓
Method发生变化

然后第二次遇到相同条件时,机器个体不再继续使用已经证明效果较差的方法A,而选择方法B。

这就是本章所说的“学习真正改变机器个体”。


246.46 示例运行对象

建立一个最小机器个体对象:

class MachineIndividual
{
    private $id;
    private $name;
    private $method;
    private $state;

    public function __construct($id, $name, $method)
    {
        $this->id = $id;
        $this->name = $name;
        $this->method = $method;
        $this->state = 'ready';
    }

    public function getId()
    {
        return $this->id;
    }

    public function getName()
    {
        return $this->name;
    }

    public function getMethod()
    {
        return $this->method;
    }

    public function getState()
    {
        return $this->state;
    }

    public function setMethod($method)
    {
        $this->method = $method;
    }

    public function setState($state)
    {
        $this->state = $state;
    }
}

这里的MachineIndividual是Domain Object。

它不是数据库记录,也不是Engine。

其职责只是描述当前机器个体的结构和状态。


246.47 Feedback对象

建立反馈对象:

class Feedback
{
    private $individualId;
    private $method;
    private $condition;
    private $result;
    private $success;

    public function __construct(
        $individualId,
        $method,
        $condition,
        $result,
        $success
    ) {
        $this->individualId = $individualId;
        $this->method = $method;
        $this->condition = $condition;
        $this->result = $result;
        $this->success = $success;
    }

    public function getIndividualId()
    {
        return $this->individualId;
    }

    public function getMethod()
    {
        return $this->method;
    }

    public function getCondition()
    {
        return $this->condition;
    }

    public function getResult()
    {
        return $this->result;
    }

    public function isSuccess()
    {
        return $this->success;
    }
}

Feedback记录一次运行结果对于后续学习的意义。

例如:

个体:ICAI-001
方法:method_A
条件:condition_C
结果:failed
成功:false

246.48 Memory对象

建立记忆对象:

class Memory
{
    private $records = array();

    public function add(Feedback $feedback)
    {
        $this->records[] = $feedback;
    }

    public function all()
    {
        return $this->records;
    }
}

Memory负责保存已经发生的反馈。

这里为了保持示例简单,使用数组保存。

真实系统中,Memory可以进一步通过:

MemoryObject→MemoryRepository→MySQLMemoryObject \rightarrow MemoryRepository \rightarrow MySQL

实现持久化。

因此,本示例的数组只是运行中的存储实现,不代表Memory本身等于数组。


246.49 Experience对象

经验对象保存从历史反馈中形成的结果:

class Experience
{
    private $records = array();

    public function add($condition, $method, $success)
    {
        if (!isset($this->records[$condition])) {
            $this->records[$condition] = array();
        }

        if (!isset($this->records[$condition][$method])) {
            $this->records[$condition][$method] = array(
                'success' => 0,
                'failure' => 0
            );
        }

        if ($success) {
            $this->records[$condition][$method]['success']++;
        } else {
            $this->records[$condition][$method]['failure']++;
        }
    }

    public function get($condition)
    {
        if (isset($this->records[$condition])) {
            return $this->records[$condition];
        }

        return array();
    }
}

例如经过运行后:

condition_C
├── method_A
│   ├── success = 0
│   └── failure = 2
│
└── method_B
    ├── success = 2
    └── failure = 0

这已经不是原始Memory,而是从Memory中形成的结构化Experience。


246.50 LearningEngine

建立真正执行学习计算的Engine:

class LearningEngine
{
    public function learn($condition, Experience $experience)
    {
        $methods = $experience->get($condition);

        if (empty($methods)) {
            return array(
                'status' => 'no_learning',
                'reason' => '没有可用经验'
            );
        }

        $bestMethod = null;
        $bestScore = -1;

        foreach ($methods as $method => $data) {

            $success = $data['success'];
            $failure = $data['failure'];

            $total = $success + $failure;

            if ($total == 0) {
                continue;
            }

            $score = $success / $total;

            if ($score > $bestScore) {
                $bestScore = $score;
                $bestMethod = $method;
            }
        }

        if ($bestMethod === null) {
            return array(
                'status' => 'no_learning',
                'reason' => '无法形成有效经验'
            );
        }

        return array(
            'status' => 'success',
            'condition' => $condition,
            'method' => $bestMethod,
            'score' => $bestScore
        );
    }
}

这里的学习计算非常明确:

Score(method)=Success(method)Success(method)+Failure(method)Score(method) = \frac{Success(method)} {Success(method)+Failure(method)}

例如:

Score(methodA)=00+2=0Score(method_A)=\frac{0}{0+2}=0

而:

Score(methodB)=22+0=1Score(method_B)=\frac{2}{2+0}=1

因此:

methodB>methodAmethod_B>method_A

机器个体就可以形成明确的学习结果。

这里没有使用任何生成模型。


246.51 LearningService

LearningService负责组织整个学习过程:

class LearningService
{
    private $memory;
    private $experience;
    private $engine;

    public function __construct(
        Memory $memory,
        Experience $experience,
        LearningEngine $engine
    ) {
        $this->memory = $memory;
        $this->experience = $experience;
        $this->engine = $engine;
    }

    public function learnFromFeedback(Feedback $feedback)
    {
        // 1. 保存反馈到Memory
        $this->memory->add($feedback);

        // 2. 从反馈形成Experience
        $this->experience->add(
            $feedback->getCondition(),
            $feedback->getMethod(),
            $feedback->isSuccess()
        );

        // 3. 执行Learning
        return $this->engine->learn(
            $feedback->getCondition(),
            $this->experience
        );
    }
}

此时完整关系已经形成:

Feedback→Memory→Experience→LearningEngineFeedback \rightarrow Memory \rightarrow Experience \rightarrow LearningEngine


246.52 UpdateEngine

学习产生结果以后,还必须真正改变机器个体。

因此建立UpdateEngine:

class UpdateEngine
{
    public function update(
        MachineIndividual $individual,
        array $learningResult
    ) {
        if (
            !isset($learningResult['status']) ||
            $learningResult['status'] !== 'success'
        ) {
            return false;
        }

        if (!isset($learningResult['method'])) {
            return false;
        }

        $individual->setMethod(
            $learningResult['method']
        );

        $individual->setState(
            'updated'
        );

        return true;
    }
}

此时:

LearningResult→UpdateEngine→MachineIndividualLearningResult \rightarrow UpdateEngine \rightarrow MachineIndividual

如果学习结果为:

method = method_B

则:

MachineIndividual.method

会真正从:

method_A

变化为:

method_B

246.53 第一次运行

现在开始真实运行。

首先创建机器个体:

$individual = new MachineIndividual(
    'ICAI-001',
    '任务处理个体',
    'method_A'
);

初始状态:

ID:ICAI-001
Method:method_A
State:ready

第一次运行:

$feedback1 = new Feedback(
    'ICAI-001',
    'method_A',
    'condition_C',
    'failed',
    false
);

调用:

$learningService->learnFromFeedback(
    $feedback1
);

此时:

Result1→Feedback1→Memory1→Experience1→Learning1Result_1 \rightarrow Feedback_1 \rightarrow Memory_1 \rightarrow Experience_1 \rightarrow Learning_1

形成:

condition_C
└── method_A
    ├── success = 0
    └── failure = 1

由于目前只有一个失败记录,系统还不能说明另一个方法一定更好。


246.54 第二次运行

第二次运行继续使用:

method_A

再次失败:

$feedback2 = new Feedback(
    'ICAI-001',
    'method_A',
    'condition_C',
    'failed',
    false
);

$learningService->learnFromFeedback(
    $feedback2
);

现在经验变成:

condition_C
└── method_A
    ├── success = 0
    └── failure = 2

因此:

Score(methodA)=0Score(method_A)=0


246.55 第三次运行

现在机器个体采用另一种方法:

$feedback3 = new Feedback(
    'ICAI-001',
    'method_B',
    'condition_C',
    'success',
    true
);

$learningService->learnFromFeedback(
    $feedback3
);

Experience变成:

condition_C
├── method_A
│   ├── success = 0
│   └── failure = 2
│
└── method_B
    ├── success = 1
    └── failure = 0

计算:

Score(methodA)=0Score(method_A)=0 Score(methodB)=1Score(method_B)=1

LearningEngine因此形成:

LearningResult
{
    status: success,
    condition: condition_C,
    method: method_B,
    score: 1
}

246.56 执行Update

得到LearningResult以后:

$learningResult = $learningService->learnFromFeedback(
    $feedback3
);

$updateEngine->update(
    $individual,
    $learningResult
);

机器个体发生实际变化:

更新前:

Method = method_A

更新后:

Method = method_B

因此:

Individualt→Learning→Update→Individualt+1Individual_t \rightarrow Learning \rightarrow Update \rightarrow Individual_{t+1}

这才构成真正的学习。


246.57 第四次运行验证学习结果

如果第四次再次遇到:

condition_C

机器个体现在的Method已经是:

method_B

因此:

echo $individual->getMethod();

得到:

method_B

说明学习结果已经进入机器个体自身结构。

这一步非常重要。

如果系统只是输出:

学习完成

但机器个体仍然使用:

method_A

那么只能说明产生了一条学习记录,而不能说明机器个体真正完成了学习更新。

因此:

LearningLog≠LearningUpdateLearningLog\neq LearningUpdate

真正的学习验证必须观察:

Individualt≠Individualt+1Individual_t\neq Individual_{t+1}

并且这种变化能够影响下一次运行。


246.58 完整可运行PHP代码

下面将上述对象组合成一个单文件运行程序。

文件:

learning_mvc_demo.php

完整代码:

<?php

class MachineIndividual
{
    private $id;
    private $name;
    private $method;
    private $state;

    public function __construct($id, $name, $method)
    {
        $this->id = $id;
        $this->name = $name;
        $this->method = $method;
        $this->state = 'ready';
    }

    public function getId()
    {
        return $this->id;
    }

    public function getName()
    {
        return $this->name;
    }

    public function getMethod()
    {
        return $this->method;
    }

    public function getState()
    {
        return $this->state;
    }

    public function setMethod($method)
    {
        $this->method = $method;
    }

    public function setState($state)
    {
        $this->state = $state;
    }
}

class Feedback
{
    private $individualId;
    private $method;
    private $condition;
    private $result;
    private $success;

    public function __construct(
        $individualId,
        $method,
        $condition,
        $result,
        $success
    ) {
        $this->individualId = $individualId;
        $this->method = $method;
        $this->condition = $condition;
        $this->result = $result;
        $this->success = $success;
    }

    public function getIndividualId()
    {
        return $this->individualId;
    }

    public function getMethod()
    {
        return $this->method;
    }

    public function getCondition()
    {
        return $this->condition;
    }

    public function getResult()
    {
        return $this->result;
    }

    public function isSuccess()
    {
        return $this->success;
    }
}

class Memory
{
    private $records = array();

    public function add(Feedback $feedback)
    {
        $this->records[] = $feedback;
    }

    public function all()
    {
        return $this->records;
    }
}

class Experience
{
    private $records = array();

    public function add($condition, $method, $success)
    {
        if (!isset($this->records[$condition])) {
            $this->records[$condition] = array();
        }

        if (!isset($this->records[$condition][$method])) {
            $this->records[$condition][$method] = array(
                'success' => 0,
                'failure' => 0
            );
        }

        if ($success) {
            $this->records[$condition][$method]['success']++;
        } else {
            $this->records[$condition][$method]['failure']++;
        }
    }

    public function get($condition)
    {
        if (isset($this->records[$condition])) {
            return $this->records[$condition];
        }

        return array();
    }
}

class LearningEngine
{
    public function learn($condition, Experience $experience)
    {
        $methods = $experience->get($condition);

        if (empty($methods)) {
            return array(
                'status' => 'no_learning',
                'reason' => '没有可用经验'
            );
        }

        $bestMethod = null;
        $bestScore = -1;

        foreach ($methods as $method => $data) {

            $success = $data['success'];
            $failure = $data['failure'];

            $total = $success + $failure;

            if ($total == 0) {
                continue;
            }

            $score = $success / $total;

            if ($score > $bestScore) {
                $bestScore = $score;
                $bestMethod = $method;
            }
        }

        if ($bestMethod === null) {
            return array(
                'status' => 'no_learning',
                'reason' => '无法形成有效经验'
            );
        }

        return array(
            'status' => 'success',
            'condition' => $condition,
            'method' => $bestMethod,
            'score' => $bestScore
        );
    }
}

class LearningService
{
    private $memory;
    private $experience;
    private $engine;

    public function __construct(
        Memory $memory,
        Experience $experience,
        LearningEngine $engine
    ) {
        $this->memory = $memory;
        $this->experience = $experience;
        $this->engine = $engine;
    }

    public function learnFromFeedback(Feedback $feedback)
    {
        $this->memory->add($feedback);

        $this->experience->add(
            $feedback->getCondition(),
            $feedback->getMethod(),
            $feedback->isSuccess()
        );

        return $this->engine->learn(
            $feedback->getCondition(),
            $this->experience
        );
    }
}

class UpdateEngine
{
    public function update(
        MachineIndividual $individual,
        array $learningResult
    ) {
        if (
            !isset($learningResult['status']) ||
            $learningResult['status'] !== 'success'
        ) {
            return false;
        }

        if (!isset($learningResult['method'])) {
            return false;
        }

        $individual->setMethod(
            $learningResult['method']
        );

        $individual->setState(
            'updated'
        );

        return true;
    }
}


/*
 * Bootstrap
 */

$individual = new MachineIndividual(
    'ICAI-001',
    '任务处理个体',
    'method_A'
);

$memory = new Memory();
$experience = new Experience();
$learningEngine = new LearningEngine();

$learningService = new LearningService(
    $memory,
    $experience,
    $learningEngine
);

$updateEngine = new UpdateEngine();


/*
 * 初始状态
 */

echo "===== 初始机器个体 =====\n";
echo "ID: " . $individual->getId() . "\n";
echo "Name: " . $individual->getName() . "\n";
echo "Method: " . $individual->getMethod() . "\n";
echo "State: " . $individual->getState() . "\n\n";


/*
 * 第一次运行
 */

echo "===== 第一次运行 =====\n";

$feedback1 = new Feedback(
    'ICAI-001',
    'method_A',
    'condition_C',
    'failed',
    false
);

$result1 = $learningService->learnFromFeedback(
    $feedback1
);

echo "Method: method_A\n";
echo "Result: failed\n";
echo "Learning Status: " . $result1['status'] . "\n\n";


/*
 * 第二次运行
 */

echo "===== 第二次运行 =====\n";

$feedback2 = new Feedback(
    'ICAI-001',
    'method_A',
    'condition_C',
    'failed',
    false
);

$result2 = $learningService->learnFromFeedback(
    $feedback2
);

echo "Method: method_A\n";
echo "Result: failed\n";
echo "Learning Status: " . $result2['status'] . "\n\n";


/*
 * 第三次运行
 */

echo "===== 第三次运行 =====\n";

$feedback3 = new Feedback(
    'ICAI-001',
    'method_B',
    'condition_C',
    'success',
    true
);

$learningResult = $learningService->learnFromFeedback(
    $feedback3
);

echo "Method: method_B\n";
echo "Result: success\n";
echo "Learning Status: "
    . $learningResult['status']
    . "\n";

echo "Learned Method: "
    . $learningResult['method']
    . "\n";

echo "Score: "
    . $learningResult['score']
    . "\n\n";


/*
 * Update
 */

echo "===== 执行Update =====\n";

$oldMethod = $individual->getMethod();

$updated = $updateEngine->update(
    $individual,
    $learningResult
);

$newMethod = $individual->getMethod();

echo "Old Method: "
    . $oldMethod
    . "\n";

echo "New Method: "
    . $newMethod
    . "\n";

echo "Update: "
    . ($updated ? 'success' : 'failed')
    . "\n\n";


/*
 * 第四次运行验证
 */

echo "===== 第四次运行验证 =====\n";

echo "Current Method: "
    . $individual->getMethod()
    . "\n";

echo "Current State: "
    . $individual->getState()
    . "\n";

if ($individual->getMethod() === 'method_B') {
    echo "Learning Verification: success\n";
} else {
    echo "Learning Verification: failed\n";
}

echo "\n";


/*
 * Memory统计
 */

echo "===== Memory =====\n";

echo "Feedback Count: "
    . count($memory->all())
    . "\n";

echo "\n";


/*
 * Experience统计
 */

echo "===== Experience =====\n";

$experienceData = $experience->get('condition_C');

foreach ($experienceData as $method => $data) {

    $total = $data['success'] + $data['failure'];

    $score = 0;

    if ($total > 0) {
        $score = $data['success'] / $total;
    }

    echo $method
        . " success="
        . $data['success']
        . " failure="
        . $data['failure']
        . " score="
        . $score
        . "\n";
}

246.59 运行命令

该示例不需要Composer,也不需要第三方框架。

在命令行进入文件所在目录:

php learning_mvc_demo.php

如果当前环境没有配置PHP PATH,可以直接使用PHP可执行文件:

D:\wamp\bin\php\php5.6.25\php.exe learning_mvc_demo.php

或者:

D:\wamp\bin\php\php7.0.10\php.exe learning_mvc_demo.php

具体使用哪一个PHP版本,应以实际机器已经安装并能够正常运行的版本为准。


246.60 预期运行结果

如果代码运行正常,核心结果应类似:

===== 初始机器个体 =====
ID: ICAI-001
Name: 任务处理个体
Method: method_A
State: ready

===== 第一次运行 =====
Method: method_A
Result: failed
Learning Status: success

===== 第二次运行 =====
Method: method_A
Result: failed
Learning Status: success

===== 第三次运行 =====
Method: method_B
Result: success
Learning Status: success
Learned Method: method_B
Score: 1

===== 执行Update =====
Old Method: method_A
New Method: method_B
Update: success

===== 第四次运行验证 =====
Current Method: method_B
Current State: updated
Learning Verification: success

===== Memory =====
Feedback Count: 3

===== Experience =====
method_A success=0 failure=2 score=0
method_B success=1 failure=0 score=1

这里最关键的不是输出文字,而是:

Old Method: method_A
New Method: method_B

以及:

Learning Verification: success

这证明学习结果已经真正改变了机器个体的Domain Object。


246.61 示例中的真实学习过程

整个程序实际执行的是:

机器个体
Method = method_A
        ↓
执行
        ↓
失败
        ↓
Feedback
        ↓
Memory
        ↓
Experience
        ↓
Learning
        ↓
发现method_A得分为0
        ↓
发现method_B得分为1
        ↓
LearningResult = method_B
        ↓
Update
        ↓
机器个体Method = method_B
        ↓
再次运行
        ↓
验证更新结果

数学上可以表示为:

Score(A)=02=0Score(A)=\frac{0}{2}=0 Score(B)=11=1Score(B)=\frac{1}{1}=1

因此:

SelectMethod(C)=BSelectMethod(C)=B

最终:

Methodt=AMethod_t=A

经过学习:

Methodt+1=BMethod_{t+1}=B


246.62 这个示例为什么属于ICAI学习

这个例子并不是简单的“数据库统计”。

因为系统发生了三个连续变化。

第一,系统保存了历史:

Feedback→MemoryFeedback\rightarrow Memory

第二,系统从历史中形成经验:

Memory→ExperienceMemory\rightarrow Experience

第三,系统利用经验改变机器个体:

Experience→Learning→UpdateExperience\rightarrow Learning\rightarrow Update

最终:

Individualt≠Individualt+1Individual_t\neq Individual_{t+1}

而且变化后的机器个体能够影响下一次运行。

这才形成:

Learning→IndividualDevelopmentLearning\rightarrow IndividualDevelopment


246.63 如果只保存数据则不属于完整学习

例如系统只执行:

$memory->add($feedback);

然后把数据保存到数据库。

这只能表示:

Result→MemoryResult\rightarrow Memory

它没有形成:

Memory→ExperienceMemory\rightarrow Experience

也没有:

Experience→LearningExperience\rightarrow Learning

更没有:

Learning→UpdateLearning\rightarrow Update

因此:

MemoryStorage≠ICAILearningMemoryStorage\neq ICAILearning

数据库保存历史是学习的基础,但不是学习本身。


246.64 如果只计算不更新也不属于完整学习

另外一种情况是:

计算结果:

method_B更好

但是机器个体仍然保持:

Method = method_A

那么:

LearningResultLearningResult

虽然已经产生,但是:

Update=FailureUpdate=Failure

因此:

LearningCompleted≠IndividualUpdatedLearningCompleted\neq IndividualUpdated

ICAI学习必须进一步验证:

Individualt+1Individual_{t+1}

是否真正产生。


246.65 从内存数组到真实MySQL

本示例为了保证单文件即可运行,Memory和Experience使用内存数组。

正式ICAI工程则应进一步转换为:

FeedbackObject
        ↓
MemoryRepository
        ↓
MySQL

ExperienceObject
        ↓
ExperienceRepository
        ↓
MySQL

MachineIndividual
        ↓
IndividualRepository
        ↓
MySQL

最终:

Memory→Repository→MySQLMemory \rightarrow Repository \rightarrow MySQL Experience→Repository→MySQLExperience \rightarrow Repository \rightarrow MySQL Individual→Repository→MySQLIndividual \rightarrow Repository \rightarrow MySQL

这样机器个体重新启动以后,仍然可以读取过去的记忆和经验,而不会因为PHP进程结束而全部消失。


246.66 从单文件运行到正式MVC

本示例将所有Class放在一个PHP文件中,是为了验证学习逻辑本身能够真实执行。

正式项目应拆分为:

app/
├── controllers/
│   └── LearningController.php
│
├── services/
│   └── LearningService.php
│
├── engines/
│   ├── LearningEngine.php
│   └── UpdateEngine.php
│
├── models/
│   ├── MachineIndividual.php
│   ├── Feedback.php
│   ├── Memory.php
│   └── Experience.php
│
└── repositories/
    ├── IndividualRepository.php
    ├── MemoryRepository.php
    └── ExperienceRepository.php

正式结构:

Controller→LearningService→LearningEngine→DomainObject→Repository→MySQLController \rightarrow LearningService \rightarrow LearningEngine \rightarrow DomainObject \rightarrow Repository \rightarrow MySQL

而:

LearningResult→UpdateEngine→DomainObjectLearningResult \rightarrow UpdateEngine \rightarrow DomainObject

这样单文件示例中的逻辑就能够自然迁移到ICAI正式工程。


246.67 与第244、245章形成完整闭环

第244章:

Input→Cognition→CognitiveResultInput \rightarrow Cognition \rightarrow CognitiveResult

第245章:

CognitiveResult→Behavior→Action→ResultCognitiveResult \rightarrow Behavior \rightarrow Action \rightarrow Result

第246章:

Result→Feedback→Memory→Experience→Learning→UpdateResult \rightarrow Feedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow Update

三章连接后:

Input→Cognition→Behavior→Action→Result→Feedback→Memory→Experience→Learning→Update→CognitionInput \rightarrow Cognition \rightarrow Behavior \rightarrow Action \rightarrow Result \rightarrow Feedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow Update \rightarrow Cognition

这条链已经构成ICAI从认知到行为、从行为到结果、从结果到学习、从学习到个体变化的基础运行闭环。


246.68 本示例的工程结论

这个运行示例证明,ICAI学习MVC至少需要完成五个真实动作:

Feedback→Memory→Experience→Learning→UpdateFeedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow Update

其中:

Feedback必须能够获取真实运行结果。

Memory必须能够保存历史。

Experience必须能够从历史形成结构化经验。

Learning必须能够根据经验产生明确的学习结果。

Update必须能够真正修改机器个体。

最终还必须验证:

UpdateResult=SuccessUpdateResult=Success

以及:

Individualt+1≠IndividualtIndividual_{t+1} \neq Individual_t

并进一步验证:

Behaviort+1Behavior_{t+1}

确实能够受到更新后的个体结构影响。

因此,一个完整的ICAI学习过程不是:

Input→LearningLogInput\rightarrow LearningLog

而是:

Result→Feedback→Memory→Experience→Learning→LearningResult→Update→Individualt+1Result \rightarrow Feedback \rightarrow Memory \rightarrow Experience \rightarrow Learning \rightarrow LearningResult \rightarrow Update \rightarrow Individual_{t+1}

这才是可以实际运行、可以验证、可以持续积累的ICAI学习MVC。

Leave a Reply

Your email address will not be published. Required fields are marked *