Features

Feature extraction algorithms.

Each algorithm works on the HandwrittenData class. They have to be applied like this:

>>> import features
>>> a = HandwrittenData(...)
>>> feature_list = [features.StrokeCount(),
                    features.ConstantPointCoordinates(strokes=4,
                                                      points_per_stroke=20,
                                                      fill_empty_with=0)
                   ]
>>> x = a.feature_extraction(feature_list)
class hwrt.features.AspectRatio

Aspect ratio of a recording as a 1 dimensional feature.

get_dimension()

Get the dimension of the returned feature. This equals the number of elements in the returned list of numbers.

class hwrt.features.Bitmap(size=16)

Get a fixed-size bitmap of the recording.

get_dimension()

Get the dimension of the returned feature. This equals the number of elements in the returned list of numbers.

class hwrt.features.CenterOfMass

Center of mass of a recording as a 2 dimensional feature.

get_dimension()

Get the dimension of the returned feature. This equals the number of elements in the returned list of numbers.

class hwrt.features.ConstantPointCoordinates(strokes=4, points_per_stroke=20, fill_empty_with=0, pen_down=True, pixel_env=0, scaling_factor=32)
Take the first points_per_stroke=20 points coordinates of the first

strokes=4 strokes as features. This leads to \(2 \cdot \text{points_per_stroke} \cdot \text{strokes}\) features.

If points is set to 0, the first points_per_stroke point coordinates and the pen_down feature is used. This leads to \(3 \cdot \text{points_per_stroke}\) features.

Parameters:

strokes : int

points_per_stroke : int

fill_empty_with : float

pen_down : boolean

pixel_env : int

How big should the pixel map around the given point be?

get_dimension()

Get the dimension of the returned feature. This equals the number of elements in the returned list of numbers.

class hwrt.features.DouglasPeuckerPoints(epsilon=0.2)

Get the number of points which are left after applying the Douglas Peucker line simplification algorithm.

get_dimension()

Get the dimension of the returned feature. This equals the number of elements in the returned list of numbers.

class hwrt.features.Feature

Abstract class which defines which methods to implement for features.

get_dimension()

Return the length of the list which __call__ will return.

class hwrt.features.FirstNPoints(n=81)

Similar to the ConstantPointCoordinates feature, this feature takes the first n=81 point coordinates. It also has the fill_empty_with=0 to make sure that the dimension of this feature is always the same.

get_dimension()

Get the dimension of the returned feature. This equals the number of elements in the returned list of numbers.

class hwrt.features.Height

Height of a recording as a a 1 dimensional feature.

Note

This is the current hight. So if the recording was scaled, this will not be the original height.

get_dimension()

Get the dimension of the returned feature. This equals the number of elements in the returned list of numbers.

class hwrt.features.Ink

Ink as a 1 dimensional feature. It gives a numeric value for the amount of ink this would eventually have consumed.

get_dimension()

Get the dimension of the returned feature. This equals the number of elements in the returned list of numbers.

class hwrt.features.ReCurvature(strokes=4)

Re-curvature is a 1 dimensional, stroke-global feature for a recording. It is the ratio \(\frac{\text{height}(s)}{\text{length}(s)}\). If length(s) == 0, then the re-curvature is defined to be 1.

get_dimension()

Get the dimension of the returned feature. This equals the number of elements in the returned list of numbers.

class hwrt.features.StrokeCenter(strokes=4)

Get the stroke center of mass coordinates as a 2 dimensional feature.

get_dimension()

Get the dimension of the returned feature. This equals the number of elements in the returned list of numbers.

class hwrt.features.StrokeCount

Stroke count as a 1 dimensional recording.

get_dimension()

Get the dimension of the returned feature. This equals the number of elements in the returned list of numbers.

class hwrt.features.StrokeIntersections(strokes=4)
Count the number of intersections which strokes in the recording have
with each other in form of a symmetrical matrix for the first stroke=4 strokes. The feature dimension is \(round(\frac{\text{strokes}^2}{2} + \frac{\text{strokes}}{2})\) because the symmetrical part is discarded.
stroke1 stroke2 stroke3  
stroke1 0 1 0 ...
stroke2 1 2 0 ...
stroke3 0 0 0 ...
... ... ... ... ...

Returns values of upper triangular matrix (including diagonal) from left to right, top to bottom.

..warning

This method has an error. It should probably not be used.
get_dimension()

Get the dimension of the returned feature. This equals the number of elements in the returned list of numbers.

class hwrt.features.Time

The time in milliseconds it took to create the recording. This is a 1 dimensional feature.

get_dimension()

Get the dimension of the returned feature. This equals the number of elements in the returned list of numbers.

class hwrt.features.Width

Width of a recording as a 1 dimensional feature.

Note

This is the current width. So if the recording was scaled, this will not be the original width.

get_dimension()

Get the dimension of the returned feature. This equals the number of elements in the returned list of numbers.

hwrt.features.get_features(model_description_features)

Get features from a list of dictionaries

Parameters:model_description_features : list of dictionaries

Examples

>>> l = [{'StrokeCount': None},              {'ConstantPointCoordinates':               [{'strokes': 4},                {'points_per_stroke': 81},                {'fill_empty_with': 0},                {'pen_down': False}]              }             ]
>>> get_features(l)
[StrokeCount, ConstantPointCoordinates
 - strokes: 4
 - points per stroke: 81
 - fill empty with: 0
 - pen down feature: False
]
hwrt.features.print_featurelist(feature_list)

Print the feature_list in a human-readable form.

Parameters:

feature_list : list

feature objects

Previous topic

Data Multiplication

Next topic

Create feature files

This Page