| Algorithm 4: Recognize Activity |
| Input: Ar{a1,a2…an}, a set of activity |
| at, test sample |
| w1,w2, weight of ratio |
| n, select the number of training instances with the highest similarity |
| Output:label, label of at |
| 1. Time←getTime(Ar)//get bt and et |
| 2. AllRatio←Ø |
| 3. k←SelectK(Ar)//SelectK is used to select the optimal k |
| 4. clf←KMeans(n_clusters=k)//clustering |
| 5. clf.fit(Time)//fitting the data |
| 6. m←clf.predict({at.bt,at.et})//find the cluster where the test sample is located |
| 7. for each a in Ar: |
| 8. if cluster(a) == m: |
| 9. ratio←getRatio(a,at,w1,w2)//calculate ratio |
| 10. AllRatio←◡ratio |
| 11. end if |
| 12. end for |
| 13. sort(AllRatio)//sort max to min |
| 14. for i in range(n): |
| 15. val← getALLRatio(i)//get the first n instances of maximum ratio |
| 16. topk_y←◡val |
| 17. end for |
| 18. label←vote(topk_y)//vote for label |
| 19. return label |