Preparing for the last battle - gestures generation Skip to content →

Preparing for the last battle – gestures generation

The neural network requires to train it before using. We are expected to provide sets od date that will be used for the purpose of learning. It means that we need a generator which will create gestures in a form readable by the NN.

I would like to remind you that all of the sources are available in my Github repository. Moreover, in the README file, you can find short project description with its main assumptions.

Generation strategy and generators

The generation strategy is fairly simple:

In the configuration object, we store information about a number of points which represent a gesture. Then, using provided generator the ideal point is created. What “the ideal point” means? Let me explain, a gesture consists of series of points. A generator generates points from the beginning to the end. The ideal point is the next point which hasn’t been mutated. Before adding generated point to the result list, the algorithm mutates it.

Depending on which gesture we want to create, we use a different generator. For example, line diagonal left is generated with LineDiagonalLeftGenerator:

On the other hand, CircleGenerator has slightly different logic:


By mutating a point I mean moving it by a random number of pixels. DefaultMutator is responsible for basic points movement:

maximumNeighbourDeviatiation defines the maximum number of pixels by which a point could be moved. As you can see, mutating vectors are randomized, a direction of the movement also.

Mutations are important in the process of learning the neural network. Gestures drawn by users are not ideal. That’s why it is important to train the NN with not perfect gestures.

Checking generated gestures

Having a gesture generated, I had to somehow verify the result. JFreeChart seemed to have been a perfect choice. I wrote a simple class which as one of the arguments takes the lists of points and prints them at the coordinate system.

Let’s check how it looks.

Without mutations:

With maximumNeighbourDeviatiation = 1:

maximumNeighbourDeviatiation = 3:

At first glance, it may seem that LineVerticalGenerator does not work as expected. But take a look at the scale on the axis. Everything is ok 🙂

Published in Get Noticed 2017 Programming