### 3.1. Concept

This section proposes a new model called the CMKF. The model intends to track the movements of a human by essentially increasing the number of states on which the prediction depends. This approach uses mathematical curve matching to relate the motion of the human at the present instant to some similar motion in the past, and thus make a better prediction of the man's state.

We consider two curves-*P* denoting the man's trajectory in the past or the past curve, and *C* denoting the man's current trajectory or the current curve. We search in *P* for stretches where the present curve *C* matches. When a strong match is found we try to predict the next movement of the man based on how it had behaved in the past. At each instant of time, a weight is assigned to the curve matching algorithm (CMA) and the KF depending on whether the present motion of the man strongly resembles his past motion. The weighted mean of the CMA and the KF is then calculated, according to which the mobile robot is moved. To facilitate finding matches of curve *C* in curve *P*, we encode them as strings *C*' and *P*', respectively, and apply computationally light string matching algorithms to calculate the extent and degree of matches.

### 3.2. Justification for using curve matching

In the experiment setup, we consider a mobile robot always centered in on the human target. Whenever the human makes a move, the robot head moves accordingly to bring the human back to the center of its sensor image. Under such situations, if the human target suddenly changes direction, the KF cannot catch up immediately because it cannot predict the target using the last few states that the body was going to make such a move. Under more general circumstances, it is impossible to predict if a human will make a sudden move from his present position. However, an alternate solution is to utilize past records of motion to help predict complicated movements of human subjects. That is why we extend KF to the area of mathematical curve matching in order to increase the state-space which may be used for prediction making.

It is also noted that current trajectory may not always significantly match any motion in the past. Hence, the CMA prediction should only be used when there is ample evidence that a repetition in trajectory is taking place. The algorithm will supply the robot with a weighted average of the KF prediction as stated above and the value predicted by CMA. The better the present motion curve matches one in the past, the higher the weight of the prediction returned by the CMA. Also converting the curves into strings ensures lightweight computation, and hence viable for implementation in real-time systems. In the following sections, we describe in more detail each of the aspects of the CMA.

### 3.3. Converting the curve into a string

Two curves are initially calculated. The first curve *C* denotes the current motion of the human, and the second curve *P* denotes his past motion. Each curve is taken and converted into a corresponding string denoted as *C*' and *P*', respectively. These two strings are then matched. The length of *C*' represents the length of the time through which the present motion has been following a past motion. The string matching algorithm also calculates the extent to which the strings have matched. Initially, both *P*' and *C*' are null. As the robot starts tracking, the motion of the human gradually gets started to store in *P*'. Thus, *P*' gives the entire history of the motion which the robot has tracked till the present moment. *C*' stores only that much amount of the ending portion of *P*' that can be matched to an earlier instant in *P*'. Thus, *C*' only contains the last few frames of data which can be matched to a previous motion of the man. If the current motion does not match any previous motion already stored in *P*', we re-initialize *C*' to null.

We choose to encode the point-wise variation of the curve. Let us consider a motion Γ(*s*). The curve is sampled at specified intervals. The relative difference of the neighboring sample points in the graph is calculated (as shown in Figure 1). The value obtained at each sample point is then converted into an integer. A sequence of integers denoting every sampled portion of the curve is thus obtained.

The advantage of encoding the difference between successive sampled points is that similar curvatures with different range of values will be encoded in a similar manner. The curves will match not only in those portions where both the position and movement characteristics of the body is exactly the same, but also those portions where only the curvature of motion is the same. We thus have

{\text{\Phi}}_{i}=\text{\Delta}\text{\Gamma}\left({s}_{i}\right)=\text{\Gamma}\left({s}_{i}+\text{\Delta}s\right)-\text{\Gamma}\left({s}_{i}\right)

(1)

where Φ is the string of integers to which the curve is being converted, and *i* denotes a particular sampled point corresponding to a particular character in the string.

To make the method more robust, we may compute an averaged difference

{\text{\Phi}}_{i}=A\nu \text{\Delta}\text{\Gamma}\left({s}_{i}\right)=\frac{1}{k}\sum _{j=0}^{k-1}\text{\Delta}\text{\Gamma}\left({s}_{i}+j\delta \right)

(2)

over some fixed *j* and *k*. *δ* is some fixed non-negative real number.

The result is then multiplied by some experimentally decided integer *M* to space out the values obtained. We then convert each Φ_{
i
} to the nearest integer.

{\text{\Phi}}_{i}^{\prime}=\text{int}\left(M{\text{\Phi}}_{i}\right)

(3)

int is the integer function, which finds the greatest integer lesser than or equal to the number.

The sequence Φ'_{1}Φ'_{2},...,Φ'_{
k
} thus becomes the desired string encoding of the motion curve.

Note that many special features of the curve, such as rotationally invariant points, etc., need not be taken for our purpose of curve matching. This procedure helps reduce time taken for the algorithm to run.

### 3.4. Matching the two strings

During the string matching, the possibility of the data being noisy should be kept in mind. Hence, we keep an accuracy factor *ε*. There is a match between corresponding characters if

\left|{P}_{k}^{\prime}-{C}_{{k}^{\prime}}^{\prime}\right|\le \epsilon

(4)

where *P*' and *C*' are the two strings denoting the previous history and the current motion, respectively, and *k* and *k*' are the indices where they match.

### 3.5. Update of the strings

Initially, the string *C*' includes the latest move only. *P*' and *C*' are then matched and the points where they have matched are stored. The next move is checked at exactly these points in the previous memory string *P*'. If there is a match with the next move as well, *C'* (which denotes how much the present move has matched some action in its previous history) is augmented to include the present move, otherwise *C*' is re-initialized to contain the latest character only.

Whenever a portion of the string is matched, the curve matching prediction returned is the immediate next move taken by the human at the point where the curve has been matched. If there is more than one place where the present motion curve has matched, then we take the average of the readings. Also, as will be seen in part E, the weight of the CMA is automatically reduced if the body has been shown to act differently after each such matching motion.

Note that if the augmented *C*' curve has to match, it will match only in those indices where the unaugmented *C*' had previously matched. This way, the entirety of *P*' need not be scanned for a match every time the current string is updated. Figure 2 demonstrates how much of the present move will be matched to the previous motion. The present move will constitute *C* and the remaining curve will constitute *P*.

### 3.6. Complexity of the CMA

Curve matching is computationally expensive. There have to be a number of algorithmic procedures which need to be adopted in order to lessen the computation required for curve matching.

Let us assume the length of *P*' to be *n*. We assume that character comparisons take place in a constant time *c*_{1}. The first value of *C*' is matched in *O*(*n*) time, by a naïve string matching algorithm. Thus, the first step has a complexity of

T\left(n\right)=n{c}_{1}=O\left(n\right)

(5)

where *T*(*n*) is the time taken to run. Let the first character of *C*' match in *p* separate locations in the recorded database. The next time a character comes in, we only need to check it against the *p* positions, and not all of the *n* positions in the database. *p ≤ n*. The time required per iteration (as only one new data is obtained in one iteration) now is

T\left(n\right)=p{c}_{1}=O\left(p\right)

(6)

The value of *p* is non-increasing for a particular match. As more of *C*' is matched, the number of positions in *P*', where it has matched will get reduced. Generally, *C*' will initially match in only some select indices in *P*', hence, it can be assumed that the entire process will require less time per cycle, even in the worst case. The time taken is an important metric as this algorithm has to be online.

For improvements in running time when *P*' becomes large, *P*' is made to contain only a limited amount of history (such as only those portions of the motion which have been matched repeatedly). The amount of history which is to be stored can be optimized based on the frame rate of the sensor used, i.e., the time required to make the CMKF prediction should not exceed the frame rate of the sensor. This will help in restricting the continuous increase in the length of the stored string *P*', and also help reduce the running time.

### 3.7. Assigning a weight to the CMA

Three cases need to be taken into account when deciding the weight of the prediction from the CMA.

#### Case (i) : Length of the match

The first aspect is the extent to which the curve matches exactly. This is very important, as this will govern whether exactly such a motion has indeed taken place in the past. If the curve only matches to a very small extent, then it will be evident that the present motion is not a strong repetition of its past motion.

This can be determined by the number of characters the two strings have matched exactly, and number of characters that were matched with some error.

{w}_{CMA}\mathrm{\propto}\frac{{l}_{{C}^{\prime},exact}}{{l}_{{C}^{\prime},total}}\times f\left({l}_{{C}^{\prime},total}\right)

(7)

where *w*_{
CMA
} is the weight of the CMA, *l*_{
C',exact
} is the number of characters in *C'* that has matched exactly to the corresponding characters in *P*', and *l*_{
C', total
} the total number of characters in *C*'. If *l*_{
C', exact
} equals *l*_{
C', total
} then the curves have matched exactly, and the weight given to the CMA is high. The function *f* is a function which has a value close to 1 when *l*_{
C', total
} is high. This is done to give more importance to longer matched curves. The function *f* can be chosen to be any suitable function, such as the sigmoid function.

#### Case (ii): Frequency of the match in history

The second aspect to be taken into consideration is the number of times *C*' has been matched in *P*'. There may be a case where the present motion has been repeated more than once in the past.

The more times the curve has matched, the more predictable and characteristic the behavior of the human is, and lesser is the error which the prediction is liable to have. Also, it may happen that the curve has matched just a few times but for long periods. In all such cases, the weight of the CMA is assigned to a high value.

{w}_{CMA}\mathrm{\propto}1-\frac{1}{{l}_{{C}^{\prime},total}\times \left(\mathit{m}+1\right)}

(8)

where *m* is the number of matches. As the values of *l*_{
C', exact
} and *m* increase, the weight of the CMA also increases.

#### Case (iii): Motion maintenance after similar trajectory

The final aspect that needs to be investigated is motion maintenance after similar trajectory, i.e., whether or not, after similar curvature of motion in the past, the immediate next action of the human was the same. If there is more than one type of action after a matched curvature, then we know that even after a similar trajectory in the past, the body does not behave predictably. So, the weight attached to this reading has to be lessened. The weight will be attached based on the number of instances the body has taken one particular motion or the other after a certain motion. In our experiment, we always try to center the robot on the human. Hence, the human is always located at the center in the robot point of view. Any movement to any direction is either along the positive direction with respect to the origin of the robot, or to the negative direction. Hence, we can express the weight as

{w}_{CMA}\mathrm{\propto}\delta \left(\left|\frac{{a}_{+}-{a}_{-}}{{a}_{+}+{a}_{-}}\right|\right)

(9)

where *a*_{+} is the number of actions in the positive direction (according to the chosen reference), and *a*_{-} is the number of actions in the negative direction, following matched motions. Here, delta function δ(·) has the value as follows: 1 for δ(0); otherwise |*a*| for δ(|*a*|). Note that the weight is the highest if there is a motion maintenance, and is low in cases of inconsistent behavior.

### 3.8. Flowchart of entire process

CMKF consists of taking the KF prediction, the CMA prediction and assigning a weight to each of them, depending on their importance to the context. Then, the weighted average of their predictions is taken to move the robot. The entire process is described by the following six steps:

**Step 1 :** The human's position is calculated using sensors.

**Step 2 :** The KF prediction is obtained.

**Step 3 :** The CMA prediction is obtained.

**Step 4 :** The weight of the CMA is calculated as the product of the three terms shown in cases (i), (ii), and (iii).

{w}_{CMA}=k\times \frac{{l}_{{C}^{\prime},exact}}{{l}_{{C}^{\prime},total}}\times f\left({l}_{{C}^{\prime},total}\right)\times \left[1-\frac{1}{{l}_{{C}^{\prime},total}\times \left(m+1\right)}\right]\times \delta \left(\left|\frac{{a}_{+}-{a}_{-}}{{a}_{+}+{a}_{-}}\right|\right)

(10)

*w*_{
CMA
} can have a maximum value of 1 (the value of the constant of proportionality *k* is adjusted in the appropriate manner), and that too in the most ideal case. The weight attached to the KF is

{w}_{KF}=1-{w}_{CMA}

(11)

where *w*_{
KF
} is the weight of the prediction of the KF. It is evident that in a majority of the cases the weight of the KF far outweighs the weight of the CMA. It is only in those cases that the motion is highly repetitive that *w*_{
CMA
} will be very high.

**Step 5 :** Make the robot move according to the weighted average of the KF prediction and the prediction based on CMA.

**Step 6 :** The position of the human is obtained, the Kalman matrices are updated and the entire process beginning from Step 1 is repeated.