1. A method performed by one or more computers, comprising: receiving a plurality of motion features, each of the motion features including a respective time series of motion vectors and a first label or a second label; determining a respective distance between each pair of the motion features that includes a first motion feature having the first label and a second motion feature having the second label; clustering the motion features into one or more motion clusters based on the distance and a quality threshold, the quality threshold being determined based at least in part on a smallest distance between a motion feature having the first label and a motion feature having the second label; and representing each of the one or more motion clusters using a motion pattern for recognizing a gesture on a mobile device, the motion pattern including a time series of calculated motion vectors.