# Learning and Planning Based on Merged Experience from Multiple Situations for a Service Robot
## 2 Learning and Planning Methods
### Learn Activity Schema with Abstract Methods
#### 2.3.3.1. The Example  
In our system, the robot has basic action knowledge consisting of methods and operators. In general, there are two cases that the robot needs to learn from: 1) the first time when the robot faces a new task consisting of the subtasks sequence provided by a human teacher; 2) a failure situation of an existing task happens due to the learned activity schema not being applied, and a subtasks sequence is provided to recover from the failure situation. For the purpose of formulating general concepts from a single training example and domain knowledge, deductive generalization is employed [8]. To improve the adaptability and flexibility of conceptual experience (activity schema), an abstract method is used as the middle layer. The learning algorithm is elaborated in Algorithm 1, which goes through the following steps:  
```
1:generalize a robot activity experience \(e\) using EBG
2:abstract and translate operators to enriched abstract operators \(\Omega\)
3:\(AM\leftarrow\) abstract (\(M\))
4:\(|\)for each \(m_{i}\) in \(M\)do
5:\(|\)name(\(am_{i}\)) \(\leftarrow\) name(\(m_{i}\)); argument(\(am_{i}\)) \(\leftarrow\) argument(\(m_{i}\))
6:\(|\) subtasks of \(am_{i}\) \(\leftarrow\) sequence of enriched abstract operators \(\Omega_{i}\) under \(am_{i}\)
7:\(|\)preconditions of \(am_{i}\) \(\leftarrow\)\(F(\Omega_{i})\)
8:\(|\)\(F(AM)\)\(\leftarrow\)\(F(AM)\)\(\circ\)\(F(AM)\)
9:\(ma\leftarrow\) (\(t\), \(AM\), \(\Omega\))
10:Merge(\(ma\), \(ma\))
11:\(|\)if\(AM^{\prime}\
eq AM\)then
12:\(|\)if\(AM^{\prime}\subset AM\)then
13:\(|\)\(AMF\) \(\leftarrow\) add generalize(\(AM^{\prime}\) - \(AM\)) ; return
14:\(|\)else
15: add \(subtask\) to the \(ma\) under the preconditions \(F(\Omega_{i})\)-\(F(sub_{k}\))
16:\(|\)\(F(AM)\)\(\leftarrow\) add \(am\); return
17:\(|\) add \(\Omega_{i}\) to the \(am_{i}\) under the preconditions \(F(\Omega_{i})\); num(\(sub_{k}\))\(\leftarrow\) num(\(sub_{k}\))+1
18:\(|\)for\(k\) = 1 to num(sub\({}_{k}\)?) 19:\(|\)\(F(sub_{i})\)\(\leftarrow\) add not(\(F(\Omega_{i})\) - \(F(sub_{i})\)?) 20:\(|\)return\(ma^{\prime}\)
```  
**Algorithm 2** Learning activity schema with abstract methods  
1. Generalize a robot activity experience \(e\) using explanation-based generalization (EBG) as the work [2]. 2. The generalized operators are abstracted and translated to enriched abstract operators \(\Omega\)[2] with features. In the first case, the taught subtask sequence \(M\) can be directly transformed into a corresponding abstract method sequence \(AM\) (line 3). The name and arguments of the abstract method are the same as the corresponding subtasks (lines 5-6), and each abstract method consists of a sequence of corresponding abstract operators (line 7). In this way, the initial three-layer structure of an activity schema is built: the schema layer, the abstract method layer and the abstract operator layer. 4. In the second case, the corresponding abstract method sequence \(AM\) is obtained using the previous method. If \(AM^{\prime}\) (original abstract method sequence) is a true subset of \(AM\), the complement of set \(AM^{\prime}\) in set \(AM\) will be extracted as a free abstract method and generalized as \(AMF\) (line 13). The generalization process involves replacing the observed constants in the arguments of abstract methods, operators and their preconditions with variables. If \(AM\) does not contain the same sequence as \(AM^{\prime}\), it is created as a new branch of the activity schema \(ma\) under the preconditions \(F(AM)\) (line 15), and preconditions of other branches will be adjusted as noted in line 16. Otherwise, the preconditions of \(AM\) and \(AM^{\prime}\) (\(AM\) is the same as \(AM^{\prime}\)) will be merged, and the abstract operator sequence \(\Omega_{i}\) under each \(am_{i}\) should be checked.