第207章 Scene Class|场景类
由实时对象、属性、关系和状态形成 Scene Instance
第203章到第206章,ICAI 已经逐步建立了:
Object
对象
↓
Attribute
属性
↓
Relation
关系
↓
State
状态
这些结构分别描述现实世界的不同部分。
但是,机器真正面对的不是一个孤立的 Object,也不是一个孤立的 Attribute。
机器面对的是:
某一个时间点上,同时存在于现实环境中的多个对象、对象属性、对象关系以及它们当前状态的整体。
这个整体,就是:
Scene
场景
因此第207章正式建立:
Scene Class
场景类
↓
Scene Instance
场景实例
207.1 Scene|场景
ICAI 中的 Scene 不是一张图片。
也不是简单的:
scene = "room"
而是一个实时世界结构实例。
可以表示为:
Scenet={Objectt,Attributet,Relationt,Statet}Scene_t = \{Object_t, Attribute_t, Relation_t, State_t\}
即:
Scene
│
├── Objects
│
├── Attributes
│
├── Relations
│
└── States
例如机器人面对桌面上的鸡蛋:
Scene
│
├── Robot Hand
├── Egg
├── Table
│
├── Position
├── Distance
├── Force
├── Pressure
│
├── Hand → near → Egg
├── Egg → on → Table
│
└── Current States
这才是机器当前所面对的完整现实结构。
207.2 Scene Class|场景类
建立基础 Scene Class:
<?php
class Scene
{
protected $id;
protected $name;
protected $objects = array();
protected $relations = array();
protected $states = array();
protected $timestamp;
}
这里:
$id
场景身份
$name
场景名称
$objects
场景对象集合
$relations
场景关系集合
$states
场景状态集合
$timestamp
场景时间
Scene Class 本身只是定义:
一个 ICAI Scene 应该如何组织实时世界信息。
207.3 Scene Instance|场景实例
Class 定义结构。
真正进入 Runtime 的,是 Scene Instance:
$scene = new Scene(
1,
'current_scene'
);
于是:
Scene Class
场景类
↓
Scene Instance
场景实例
这个 Instance 表示:
当前某一个具体时间点的一个具体现实场景。
207.4 Scene Identity|场景身份
Scene 同样需要自己的 ID:
protected $id;
例如:
Scene ID = 5001
因为系统可能连续产生:
Scene 5001
Scene 5002
Scene 5003
它们可能来自同一个物理空间,但代表不同时间的场景状态。
因此:
Room
房间
是空间概念。
而:
Scene Instance
是:
某一时刻机器对这个空间的实时认知实例。
207.5 Scene Time|场景时间
Scene 必须拥有时间。
$this->timestamp = time();
因为:
Scene(t0)
和:
Scene(t1)
可能完全不同。
例如:
t0
Hand → far → Egg
到了:
t1
Hand → near → Egg
到了:
t2
Hand → contacts → Egg
因此:
Scenet0≠Scenet1≠Scenet2Scene_{t0} \neq Scene_{t1} \neq Scene_{t2}
这正是 ICAI 动态认知的基础。
207.6 Scene Object Collection|场景对象集合
Scene 首先需要管理 Object。
public function addObject(Object $object)
{
$this->objects[$object->getId()] = $object;
}
例如:
$scene->addObject($hand);
$scene->addObject($egg);
$scene->addObject($table);
形成:
Scene
│
├── Hand Object
├── Egg Object
└── Table Object
因此 Scene 并不重新定义 Object。
它只是:
把当前参与这个场景的 Object Instance 组织起来。
207.7 Scene 中的 Object 是动态对象
Scene 中保存的是:
Object Instance
而不是:
Object Class
例如:
Object Class
↓
$egg
↓
Egg Object Instance
↓
加入 Scene
因此:
Scene
↓
Object Instance
是实际运行关系。
207.8 Scene Relation Collection|场景关系集合
Scene 还需要保存对象之间的 Relation。
public function addRelation(Relation $relation)
{
$this->relations[] = $relation;
}
例如:
$scene->addRelation(
new Relation(
$hand,
'near',
$egg
)
);
以及:
$scene->addRelation(
new Relation(
$egg,
'on',
$table
)
);
于是:
Scene
│
├── Objects
│
└── Relations
│
├── Hand → near → Egg
└── Egg → on → Table
207.9 Scene State|场景状态
Scene 还需要能够表达整个场景当前状态。
例如:
Scene State
Hand = moving
Egg = stationary
Table = stable
Hand → near → Egg
Egg → on → Table
可以加入:
public function addState(State $state)
{
$this->states[] = $state;
}
因此:
Scene
│
├── Objects
├── Relations
└── States
形成一个完整的场景实例。
207.10 Attribute 属于 Object
这里必须保持一个重要的架构边界。
Scene 不应该重新复制每个 Attribute。
例如:
Egg Object
│
├── Position
├── Force
├── Pressure
└── Fragility
Scene 保存:
Egg Object Instance
即可。
因此:
Scene
↓
Object
↓
Attribute
形成层级关系。
不是:
Scene
├── Egg
├── Egg Position
├── Egg Pressure
├── Egg Force
全部平铺。
这样才能保持 Object 的完整性。
207.11 Scene 的结构
因此当前完整结构是:
Scene
│
├── Object
│ └── Attributes
│
├── Object
│ └── Attributes
│
├── Relation
│
├── Relation
│
└── State
例如:
Scene
│
┌───────────┼───────────┐
↓ ↓ ↓
Hand Egg Table
│ │
Attributes Attributes
│ │
└──────┬─────┘
↓
Relations
│
↓
States
207.12 Scene Instance 的形成
现在可以把前面章节真正连接起来。
首先创建 Object:
$hand = new Object(
1001,
'device',
'Robot Hand'
);
$egg = new Object(
1002,
'physical_object',
'Egg'
);
$table = new Object(
1003,
'environment',
'Table'
);
然后创建 Scene:
$scene = new Scene(
5001,
'Robot Egg Scene'
);
加入对象:
$scene->addObject($hand);
$scene->addObject($egg);
$scene->addObject($table);
加入关系:
$scene->addRelation(
new Relation(
$hand,
'near',
$egg
)
);
$scene->addRelation(
new Relation(
$egg,
'on',
$table
)
);
现在:
Scene Instance
│
├── Hand
├── Egg
├── Table
│
├── Hand → near → Egg
└── Egg → on → Table
已经形成。
207.13 Scene Snapshot|场景快照
Scene 可以理解为:
某一时刻现实世界的结构化快照。
例如:
Scene(t0)
Hand
Position = [10,10,20]
Egg
Position = [20,10,20]
Relation
Hand → far → Egg
下一时刻:
Scene(t1)
Hand
Position = [18,10,20]
Egg
Position = [20,10,20]
Relation
Hand → near → Egg
再下一时刻:
Scene(t2)
Hand
Position = [20,10,20]
Egg
Position = [20,10,20]
Relation
Hand → contacts → Egg
因此:
Scene(t0)
↓
Scene(t1)
↓
Scene(t2)
不是三个不同的程序。
而是:
同一个认知运行系统在不同时间形成的不同 Scene Instance。
207.14 Scene Update|场景更新
现实世界变化后,Scene 也必须更新。
可以建立:
public function updateTimestamp()
{
$this->timestamp = time();
}
但真正的更新不是简单修改时间。
而是:
Real-Time Data
↓
Element Update
↓
Object Update
↓
Attribute Update
↓
Relation Update
↓
State Update
↓
Scene Update
因此 Scene 是前面所有实时对象变化的综合结果。
207.15 不为每一个场景写程序
这一点尤其重要。
ICAI 不能采用:
EggScene.php
GlassScene.php
RobotRoomScene.php
KitchenScene.php
FactoryScene.php
然后每个场景分别写逻辑。
这不符合现实世界的动态性。
因为现实世界:
没有完全相同的场景。
因此应该是:
Scene Class
↓
Dynamic Scene Instance
↓
实时对象
+
实时属性
+
实时关系
+
实时状态
场景不是提前写好的。
而是:
由实时数据在运行时形成。
207.16 Scene Formation|场景形成
ICAI 的 Scene 形成过程:
Real-Time Data
实时数据
↓
Element
元素
↓
Object
对象
↓
Attribute
属性
↓
Relation
关系
↓
State
状态
↓
Scene
场景
因此 Scene 是前面结构的综合结果。
可以表示:
Scenet=F(Objectst,Attributest,Relationst,Statest)Scene_t = F( Objects_t, Attributes_t, Relations_t, States_t )
这里的 F 并不是针对某个具体场景编写的程序。
它是通用的 Scene Formation(场景形成)机制。
207.17 Scene 与人工感知逻辑
这一步开始更加接近人的实际认知过程。
人看到桌面上的鸡蛋时,不是先运行:
EggScene.php
而是同时形成:
桌面
鸡蛋
手
距离
位置
接触关系
空间关系
当前状态
然后形成一个整体:
“我现在面对的是一个桌面上有鸡蛋、我的手正在接近鸡蛋的场景。”
ICAI 的 Scene Instance 就是把这种现实结构转换为软件对象结构。
207.18 Scene Class 基础实现
第207章可以建立第一版:
<?php
class Scene
{
protected $id;
protected $name;
protected $objects = array();
protected $relations = array();
protected $states = array();
protected $timestamp;
public function __construct(
$id,
$name
) {
$this->id = $id;
$this->name = $name;
$this->timestamp = time();
}
public function addObject(Object $object)
{
$this->objects[$object->getId()] = $object;
}
public function addRelation(Relation $relation)
{
$this->relations[] = $relation;
}
public function addState(State $state)
{
$this->states[] = $state;
}
public function getObjects()
{
return $this->objects;
}
public function getRelations()
{
return $this->relations;
}
public function getStates()
{
return $this->states;
}
public function getTimestamp()
{
return $this->timestamp;
}
}
这个版本暂时只负责:
创建 Scene
+
加入 Object
+
加入 Relation
+
加入 State
+
读取 Scene
不在本章加入 Cognition、Method 或 Action。
207.19 Scene Instance 的完整结构
到这里,一个运行中的 Scene Instance 可以表示为:
Scene Instance
│
├── Object Instance
│ ├── Attributes
│ └── State
│
├── Object Instance
│ ├── Attributes
│ └── State
│
├── Relation Instance
│
├── Relation Instance
│
└── Scene State
例如:
Scene Instance
│
┌───────────────┼───────────────┐
↓ ↓ ↓
Hand Egg Table
│ │
Attributes Attributes
│ │
└───────┬───────┘
↓
Relations
│
↓
States
这就是 ICAI 当前的实时场景对象结构。
207.20 从 Object 到 Scene
前面几个章节现在可以连成一条完整的软件工程链:
Element
元素
↓
Object
对象
↓
Attribute
属性
↓
Relation
关系
↓
State
状态
↓
Scene
场景
对应现实认知:
有什么
↓
是什么对象
↓
具有什么属性
↓
与什么对象发生关系
↓
当前处于什么状态
↓
当前世界是什么场景
这已经形成一个完整的场景构建层。
207.21 本章核心原则
第207章正式确立:
Scene 不是预先编写好的程序,而是由实时 Object、Attribute、Relation 和 State 在运行时共同形成的 Scene Instance。
因此:
不是:
一个场景
↓
一个程序
而是:
Scene Class
↓
实时数据
↓
动态 Object
↓
动态 Attribute
↓
动态 Relation
↓
动态 State
↓
Scene Instance
这与 ICAI 的核心思想完全一致:
世界不是重复的,因此机器不能依赖为每一个场景预先编写固定程序。
机器需要的是:
通用对象结构
+
动态属性
+
动态关系
+
动态状态
然后在实时运行过程中形成当前 Scene。
207.22 第207章完成
到第207章,ICAI 软件对象体系已经形成:
Real-Time Data
实时数据
↓
Element
元素
↓
Object
对象
↓
Attribute
属性
↓
Relation
关系
↓
State
状态
↓
Scene
场景
↓
Scene Instance
场景实例
最终,机器获得的不再是孤立的数据:
Data
也不是孤立的对象:
Object
而是:
Scene Instance
│
┌──────────┼──────────┐
↓ ↓ ↓
Objects Relations States
│
Attributes
这就是 ICAI 当前实时世界的对象化表示。
下一章进入:
第208章 Scene Update Engine|场景更新引擎
核心解决:
Scene Instance
↓
Real-Time Data
↓
Object Update
↓
Attribute Update
↓
Relation Update
↓
State Update
↓
New Scene State
也就是让 Scene 不是一次生成后固定不动,而是随着现实世界变化持续更新。