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

第86章 创建第一个 SAI Individual

第86章 创建第一个 SAI Individual

本章大纲

  1. 创建 Individual
  2. Identity
  3. State
  4. Ability
  5. Memory
  6. Central
  7. InformationReceiver
  8. Individual 启动
  9. 实际运行结果

1. 创建 Individual

在前面的章节中,我们已经分别建立了:

Perception
Cognition
Matching
Understanding
Memory
Reasoning
Rule
Decision
Behavior
Action
Expression
Learning
Detection
Diagnosis
Repair
Verification
Extension
Engine
Adapter
Renderer
Template
Web
API
Vehicle
Industrial Device

这些都是 SAI/ICAI 的组成能力或运行部件。

但是,仅仅拥有这些部件,还不能形成一个真正的 Individual

Individual 是这些内部能力的组织和运行主体

可以把关系表示为:

                    Individual
                         │
        ┌────────────────┼────────────────┐
        ↓                ↓                ↓
     Identity          State           Ability
        │                │                │
        └────────────────┼────────────────┘
                         ↓
                      Memory
                         ↓
                      Central
                         ↓
                InformationReceiver
                         ↓
                    Information
                         ↓
                    Individual
                         ↓
                  Cognitive Cycle

因此:

Individual
    = 一个能够独立接收信息、
      使用自身能力、
      管理自身状态和记忆、
      进行认知运行的 SAI 个体。

这里的 Individual 不是一个页面,也不是一个普通 PHP Class 的名字。

它代表一个具有:

Identity
State
Ability
Memory
Central
InformationReceiver

等基本组成的运行个体


2. Identity

Identity 是 Individual 的身份结构。

如果没有 Identity,系统只能知道:

这是一个系统对象

但无法明确:

这是哪一个 Individual

基本结构:

Identity
├── id
├── name
├── type
├── version
├── created_at
└── status

例如:

$identity = array(
    'id'         => 'Individual_A',
    'name'       => 'SAI Individual A',
    'type'       => 'ICAI',
    'version'    => '1.0.0',
    'created_at' => time(),
    'status'     => 'ACTIVE'
);

其中:

id
    = Individual 唯一身份

name
    = Individual 名称

type
    = Individual 类型

version
    = Individual 运行版本

created_at
    = 创建时间

status
    = 当前身份状态

Identity 的作用是让整个 SAI 内部能够明确:

谁正在运行?

例如:

Individual_A

收到信息:

Machine_A temperature = 92

后,系统内部可以明确:

source:
Machine_A

receiver:
Individual_A

因此:

Identity
    = Individual 的“我是谁”

3. State

State 表示 Individual 当前运行状态。

例如:

Individual State
├── CREATED
├── INITIALIZING
├── READY
├── RUNNING
├── WAITING
├── PAUSED
├── STOPPING
├── STOPPED
├── ERROR
└── UNKNOWN

例如:

$state = array(
    'value'     => 'CREATED',
    'previous'  => null,
    'changed_at'=> time()
);

启动以后:

CREATED
   ↓
INITIALIZING
   ↓
READY
   ↓
RUNNING

停止:

RUNNING
   ↓
STOPPING
   ↓
STOPPED

异常:

RUNNING
   ↓
ERROR

State 不是 Identity。

Identity
    = 我是谁

State
    = 我现在处于什么状态

例如:

Individual_A
State = RUNNING

表示:

身份 = Individual_A
状态 = RUNNING

4. Ability

Ability 表示 Individual 当前能够使用的能力资源。

根据前面的 SAI 结构,可以形成:

Ability
├── Perception
├── Cognition
├── Matching
├── Understanding
├── Memory
├── Reasoning
├── Decision
├── Behavior
├── Action
├── Expression
├── Learning
├── Detection
├── Diagnosis
├── Repair
└── Verification

例如第一个 Individual 可以定义:

$abilities = array(
    'PERCEPTION',
    'COGNITION',
    'MEMORY',
    'REASONING',
    'DECISION',
    'BEHAVIOR',
    'ACTION',
    'EXPRESSION'
);

能力还可以进一步结构化:

$ability = array(
    'id'       => 'Ability_Perception',
    'name'     => 'Perception',
    'type'     => 'COGNITIVE',
    'state'    => 'ACTIVE',
    'methods'  => array(
        'receive',
        'analyze',
        'extract'
    )
);

这里需要区分:

Ability
    = 能够做什么

Method
    = 如何执行

Action
    = 当前具体执行什么

例如:

Ability:
SET_SPEED

Method:
setSpeed()

Action:
SET_SPEED = 800 RPM

因此 Individual 不是把所有能力直接写死在一个 Class 中。

更合理的结构是:

Individual
     ↓
Ability
     ↓
Engine / Method
     ↓
Action

5. Memory

Individual 必须拥有自己的 Memory。

因为 Individual 如果每次收到信息都完全重新开始,就无法形成:

历史
经验
事实
关系
状态变化
学习结果

因此:

Individual
      ↓
    Memory
      ├── ShortMemory
      └── LongMemory

其中:

ShortMemory
    = 当前任务和当前场景记忆

LongMemory
    = 历史事实、关系、状态、经验等长期记忆

例如:

$memory = array(
    'short' => array(
        'current_task' => null,
        'current_scene' => null,
        'current_information' => null
    ),

    'long' => array(
        'facts'      => array(),
        'relations' => array(),
        'experiences' => array(),
        'history'    => array()
    )
);

当 Individual 第一次收到:

Machine_A temperature = 72

可以形成:

ShortMemory
    temperature = 72

经过验证以后,可以进入:

LongMemory
    Machine_A temperature history

下一次收到:

Machine_A temperature = 92

Individual 就可以比较:

previous = 72
current  = 92
change   = +20

从而形成:

State Change

因此:

Memory
    = Individual 的历史连续性

6. Central

Central 是 Individual 内部的核心协调中心

Central 不等于 Cognition,也不等于 Reasoning。

它主要负责:

接收输入
协调内部部件
组织运行顺序
传递数据
管理运行状态
返回结果

基本结构:

Central
├── InformationReceiver
├── Perception
├── Cognition
├── Memory
├── Reasoning
├── Decision
├── Behavior
├── Action
├── Expression
└── Feedback

运行:

Information
     ↓
Central
     ↓
Perception
     ↓
Cognition
     ↓
Reasoning
     ↓
Decision
     ↓
Behavior
     ↓
Action
     ↓
Expression

Central 的职责是协调

例如:

class Central
{
    protected $state = 'READY';

    public function process($information)
    {
        $this->state = 'RUNNING';

        /*
         * 组织 Individual 内部运行流程
         */

        $result = array(
            'state' => 'SUCCESS',
            'information' => $information
        );

        $this->state = 'READY';

        return $result;
    }

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

这里 Central 没有自己发明:

Cognition
Reasoning
Decision

它只是组织这些部件运行。

所以:

Central
    = 协调中心

Cognition
    = 认知

Reasoning
    = 推理

Decision
    = 决策

7. InformationReceiver

InformationReceiver 是 Individual 接收外部或内部信息的入口。

信息可能来自:

Sensor
Vehicle
Industrial Device
Web
API
Operator
External System
Feedback
Memory

统一进入:

InformationReceiver

结构:

InformationReceiver
├── Source
├── Type
├── Data
├── Timestamp
└── State

例如:

$information = array(
    'source'    => 'Machine_A',
    'type'      => 'SENSOR_DATA',

    'data' => array(
        'temperature' => 92,
        'speed'       => 1200,
        'load'        => 82
    ),

    'timestamp' => time(),
    'state'     => 'RECEIVED'
);

InformationReceiver:

class InformationReceiver
{
    public function receive($information)
    {
        if (!is_array($information)) {
            return array(
                'state' => 'INVALID'
            );
        }

        return array(
            'state'       => 'RECEIVED',
            'information' => $information
        );
    }
}

它的职责只有:

接收
检查基本结构
形成 Information
交给 Central

它不负责:

认知
推理
决策
行动

所以:

InformationReceiver
        ↓
Information
        ↓
Central

8. Individual 启动

现在把:

Identity
State
Ability
Memory
Central
InformationReceiver

组织成第一个 Individual。

可以建立:

class Individual
{
    protected $identity;
    protected $state;
    protected $abilities;
    protected $memory;
    protected $central;
    protected $receiver;

    public function __construct()
    {
        $this->identity = array(
            'id'   => 'Individual_A',
            'name' => 'SAI Individual A',
            'type' => 'ICAI'
        );

        $this->state = 'CREATED';

        $this->abilities = array(
            'PERCEPTION',
            'COGNITION',
            'MEMORY',
            'REASONING',
            'DECISION',
            'BEHAVIOR',
            'ACTION',
            'EXPRESSION'
        );

        $this->memory = array(
            'short' => array(),
            'long'  => array()
        );

        $this->central = new Central();

        $this->receiver = new InformationReceiver();
    }

    public function start()
    {
        $this->state = 'INITIALIZING';

        /*
         * 初始化内部组件
         */

        $this->state = 'READY';

        return true;
    }

    public function receive($information)
    {
        if ($this->state !== 'READY' &&
            $this->state !== 'RUNNING') {

            return array(
                'state' => 'NOT_READY'
            );
        }

        $received = $this->receiver->receive($information);

        if ($received['state'] !== 'RECEIVED') {
            return $received;
        }

        $this->state = 'RUNNING';

        $result = $this->central->process(
            $received['information']
        );

        $this->state = 'READY';

        return $result;
    }

    public function getIdentity()
    {
        return $this->identity;
    }

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

    public function getAbilities()
    {
        return $this->abilities;
    }

    public function getMemory()
    {
        return $this->memory;
    }
}

这里已经形成一个最基本的:

SAI Individual

9. 实际运行结果

创建:

$individual = new Individual();

启动:

$individual->start();

启动前:

State = CREATED

启动过程:

CREATED
   ↓
INITIALIZING
   ↓
READY

然后发送第一条信息:

$information = array(
    'source' => 'Machine_A',

    'type' => 'SENSOR_DATA',

    'data' => array(
        'temperature' => 72
    )
);

$result = $individual->receive($information);

实际运行路径:

Information
     ↓
InformationReceiver
     ↓
RECEIVED
     ↓
Central
     ↓
RUNNING
     ↓
Process
     ↓
READY

结果可以得到:

Individual:
Individual_A

State:
READY

Received:
Machine_A

Information:
temperature = 72

Result:
SUCCESS

结构化结果:

array(
    'individual' => 'Individual_A',

    'state' => 'READY',

    'result' => array(
        'state' => 'SUCCESS',

        'information' => array(
            'source' => 'Machine_A',

            'type' => 'SENSOR_DATA',

            'data' => array(
                'temperature' => 72
            )
        )
    )
);

这就是第一个 Individual 的真实最小运行链路

创建
 ↓
Identity
 ↓
State
 ↓
Ability
 ↓
Memory
 ↓
Central
 ↓
InformationReceiver
 ↓
Information
 ↓
Central Process
 ↓
Result
 ↓
READY

第一个 SAI Individual 的完整结构

                         Individual_A
                              │
             ┌────────────────┼────────────────┐
             ↓                ↓                ↓
         Identity           State           Ability
             │                │                │
             └────────────────┼────────────────┘
                              ↓
                           Memory
                              │
                    ┌─────────┴─────────┐
                    ↓                   ↓
               ShortMemory         LongMemory
                             
                              ↓
                           Central
                              │
                              ↓
                    InformationReceiver
                              │
                              ↓
                         Information
                              │
                              ↓
                         Perception
                              │
                              ↓
                          Cognition
                              │
                              ↓
                          Reasoning
                              │
                              ↓
                          Decision
                              │
                              ↓
                          Behavior
                              │
                              ↓
                           Action
                              │
                              ↓
                         Feedback
                              │
                              └────────→ Memory

第一个 Individual 的最小对象

可以将它概括成:

$individual = array(
    'identity' => array(
        'id'   => 'Individual_A',
        'name' => 'SAI Individual A',
        'type' => 'ICAI'
    ),

    'state' => 'READY',

    'abilities' => array(
        'PERCEPTION',
        'COGNITION',
        'MEMORY',
        'REASONING',
        'DECISION',
        'BEHAVIOR',
        'ACTION',
        'EXPRESSION'
    ),

    'memory' => array(
        'short' => array(),
        'long'  => array()
    ),

    'central' => 'Central',

    'information_receiver' =>
        'InformationReceiver'
);

这个结构已经能够回答几个最基本的问题:

它是谁?
    → Identity

现在什么状态?
    → State

能够做什么?
    → Ability

记住什么?
    → Memory

谁负责内部协调?
    → Central

信息从哪里进入?
    → InformationReceiver

Individual 的第一次运行

最终形成:

                    Individual_A
                         │
                         ↓
                InformationReceiver
                         │
                         ↓
                    Information
                         │
                         ↓
                      Central
                         │
                         ↓
                    Perception
                         │
                         ↓
                     Cognition
                         │
                         ↓
                     Memory
                         │
                         ↓
                    Reasoning
                         │
                         ↓
                     Decision
                         │
                         ↓
                     Behavior
                         │
                         ↓
                      Action
                         │
                         ↓
                    Feedback
                         │
                         └────────→ Memory

因此,第86章真正建立的是一个非常重要的概念:

之前:
SAI = 一组能力和机制

现在:
SAI = 可以组织这些能力并独立运行的 Individual

Individual 是 SAI/ICAI 从“功能集合”进入“独立运行个体”的关键结构。

本章核心关系:

Identity
    = 我是谁

State
    = 我现在是什么状态

Ability
    = 我能够做什么

Memory
    = 我保存了什么历史

Central
    = 我如何组织内部运行

InformationReceiver
    = 我如何接收信息

Individual
    = 将上述结构组织成一个独立运行主体

最终:

Information
      ↓
InformationReceiver
      ↓
   Individual
      ↓
    Central
      ↓
  Perception
      ↓
   Cognition
      ↓
   Memory
      ↓
  Reasoning
      ↓
   Decision
      ↓
   Behavior
      ↓
    Action
      ↓
   Feedback
      ↓
    Memory

这就形成了第一个 SAI Individual 的最小运行闭环

Leave a Reply

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