# Constructing skill trees

Constructing skill trees (CST) is a hierarchical reinforcement learning algorithm which can build skill trees from a set of sample solution trajectories obtained from demonstration. CST uses an incremental MAP (maximum a posteriori) change point detection algorithm to segment each demonstration trajectory into skills and integrate the results into a skill tree. CST was introduced by George Konidaris, Scott Kuindersma, Andrew Barto and Roderic Grupen in 2010.

## Algorithm

CST consists of mainly three parts;change point detection, alignment and merging. The main focus of CST is online change-point detection. The change-point detection algorithm is used to segment data into skills and uses the sum of discounted reward $R_{t}$ as the target regression variable. Each skill is assigned an appropriate abstraction. A particle filter is used to control the computational complexity of CST.
The change point detection algorithm is implemented as follows. The data for times $t\in T$ and models Q with prior $p(q\in Q)$ are given. The algorithm is assumed to be able to fit a segment from time $j+1$ to t using model q with the fit probability $P(j,t,q)_^$. A linear regression model with Gaussian noise is used to compute $P(j,t,q)$. The Gaussian noise prior has mean zero, and variance which follows $\mathrm {InverseGamma} \left({\frac {v}{2}},{\frac {u}{2}}\right)$. The prior for each weight follows $\mathrm {Normal} (0,\sigma ^{2}\delta )$.
The fit probability $P(j,t,q)$ is computed by the following equation.
    $P(j,t,q)={\frac {\pi ^{-{\frac {n}{2}}}}{\delta ^{m}}}\left|(A+D)^{-1}\right|^{\frac {1}{2}}{\frac {u^{\frac {v}{2}}}{(y+u)^{\frac {u+v}{2}}}}{\frac {\Gamma ({\frac {n+v}{2}})}{\Gamma ({\frac {v}{2}})}}$
Then, CST compute the probability of the changepoint at time j with model q, $P_{t}(j,q)$ and $P_{j}^{\text{MAP}}$ using a Viterbi algorithm.
    $P_{t}(j,q)=(1-G(t-j-1))P(j,t,q)p(q)P_{j}^{\text{MAP}}$
    $P_{j}^{\text{MAP}}=\max _{i,q}{\frac {P_{j}(i,q)g(j-i)}{1-G(j-i-1)}},\forall j<t$
The descriptions of the parameters and variables are as follows;
    $A=\sum _{i=j}^{t}\Phi (x_{i})\Phi (x_{i})^{T}$
       $\Phi (x_{i})$: a vector of m basis functions evaluated at state $x_{i}$
       $y=(\sum _{i=j}^{t}R_{i}^{2})-b^{T}(A+D)^{-1}b$
       $b=\sum _{i=j}^{t}R_{i}\Phi (x_{i})$
       $R_{i}=\sum _{j=i}^{T}\gamma ^{j-i}r_{j}$
       𝛾: Gamma function
       $n=t-j$
       m: The number of basis functions q has.
       D: an m by m matrix with $\delta ^{-1}$ on the diagonal and zeros elsewhere
The skill length l is assumed to follow a Geometric distribution with parameter p
    $g_^(l)=(1-p)^{l-1}p$
    $G_^(l)=(1-(1-p)^{l})$
    $p_^={\frac {1}{k}}$
    k: Expected skill length
Using the method above, CST can segment data into a skill chain. The time complexity of the change point detection is $O(NL)$ and storage size is $O(Nc)$, where N is the number of particles, L is the time of computing $P(j,t,q)$, and there are $O(c)$ change points.
Next step is alignment. CST needs to align the component skills because the change-point does not occur in the exactly same places. Thus, when segmenting second trajectory after segmenting the first trajectory, it has a bias on the location of change point in the second trajectory. This bias follows a mixture of gaussians.
The last step is merging. CST merges skill chains into a skill tree. CST merges a pair of trajectory segments by allocating the same skill. All trajectories have the same goal and it merges two chains by starting at their final segments. If two segments are statistically similar, it merges them. This procedure is repeated until it fails to merge a pair of skill segments. $P(j,t,q)$ are used to determine whether a pair of trajectories are modeled better as one skill or as two different skills.

## Pseudocode

The following pseudocode describes the change point detection algorithm:

## Assumptions

CTS assume that the demonstrated skills form a tree, the domain reward function is known and the best model for merging a pair of skills is the model selected for representing both individually.

## Advantages

CST is much faster learning algorithm than skill chaining. CST can be applied to learning higher dimensional policies. Even unsuccessful episode can improve skills. Skills acquired using agent-centric features can be used for other problems.

## Uses

CST has been used to acquire skills from human demonstration in the PinBall domain. It has been also used to acquire skills from human demonstration on a mobile manipulator.