Example #1
0
def test_dimensionality():
    feature_list = [
        (features.StrokeCount(), 1),
        (
            features.ConstantPointCoordinates(strokes=4,
                                              points_per_stroke=20,
                                              fill_empty_with=0),
            160,
        ),
        (
            features.ConstantPointCoordinates(strokes=0,
                                              points_per_stroke=20,
                                              fill_empty_with=0),
            60,
        ),
        (
            features.ConstantPointCoordinates(strokes=0,
                                              points_per_stroke=20,
                                              pen_down=False),
            40,
        ),
        (features.AspectRatio(), 1),
        (features.Width(), 1),
        (features.Height(), 1),
        (features.Time(), 1),
        (features.CenterOfMass(), 2),
    ]
    for feat, dimension in feature_list:
        assert feat.get_dimension() == dimension
Example #2
0
def test_normalize_features_one():
    """Test create_ffiles._normalize_features with one point."""
    feature_list = [features.Width(), features.Height()]
    prepared = [([123], 1)]
    is_traindata = True
    out = create_ffiles._normalize_features(feature_list, prepared,
                                            is_traindata)
    assert out == [([0.0], 1)]
Example #3
0
def normalize_features_one_test():
    """Test create_ffiles._normalize_features with one point."""
    feature_list = [features.Width(), features.Height()]
    prepared = [([123], 1)]
    is_traindata = True
    out = create_ffiles._normalize_features(feature_list, prepared,
                                            is_traindata)
    nose.tools.assert_equal(out, [([0.0], 1)])
Example #4
0
def test_normalize_features_two_classes():
    """Test create_ffiles._normalize_features with two classes."""
    feature_list = [features.Width(), features.Height()]
    prepared = [([123], 1), ([100], 1), ([500], 2)]
    is_traindata = True
    out = create_ffiles._normalize_features(feature_list, prepared,
                                            is_traindata)
    # Mean: 241; Range: 400
    assert out == [([-0.295], 1), ([-0.3525], 1), ([0.6475], 2)]
Example #5
0
def test_normalize_features_two_feats2():
    """Test create_ffiles._normalize_features with two points."""
    feature_list = [features.Width(), features.Height()]
    prepared = [([123, 123], 1), ([100, 100], 1)]
    is_traindata = True
    out = create_ffiles._normalize_features(feature_list, prepared,
                                            is_traindata)
    # Mean: 111.5; Range: 23
    assert out == [([0.5, 0.5], 1), ([-0.5, -0.5], 1)]

    # Now the other set
    prepared = [([111.5, 146], 1), ([146, 111.5], 1), ([54, 54], 1)]
    is_traindata = False
    out = create_ffiles._normalize_features(feature_list, prepared,
                                            is_traindata)
    assert out == [([0.0, 1.5], 1), ([1.5, 0.0], 1), ([-2.5, -2.5], 1)]
Example #6
0
def test_normalize_features_two():
    """Test create_ffiles._normalize_features with two points."""
    feature_list = [features.Width(), features.Height()]
    prepared = [([123], 1), ([100], 1)]
    is_traindata = True
    out = create_ffiles._normalize_features(feature_list, prepared,
                                            is_traindata)
    # Mean: 111.5; Range: 23
    assert out == [([0.5], 1), ([-0.5], 1)]

    # Now the other set
    prepared = [([111.5], 1), ([90], 1), ([180], 1)]
    is_traindata = False
    out = create_ffiles._normalize_features(feature_list, prepared,
                                            is_traindata)
    assert out == [([0.0], 1), ([-0.93478260869565222], 1),
                   ([2.9782608695652173], 1)]
Example #7
0
def print_featurelist_test():
    """Test features.print_featurelist."""
    feature_list = [
        features.StrokeCount(),
        features.ConstantPointCoordinates(strokes=4,
                                          points_per_stroke=20,
                                          fill_empty_with=0),
        features.ConstantPointCoordinates(strokes=0,
                                          points_per_stroke=20,
                                          fill_empty_with=0),
        features.ConstantPointCoordinates(strokes=0,
                                          points_per_stroke=20,
                                          pen_down=False),
        features.AspectRatio(),
        features.Width(),
        features.Height(),
        features.Time(),
        features.CenterOfMass()
    ]
    features.print_featurelist(feature_list)
Example #8
0
def height_test():
    feature_list = [features.Height()]
    a = testhelper.get_symbol_as_handwriting(97705)
    # TODO: Check if this is correct
    nose.tools.assert_equal(a.feature_extraction(feature_list), [263.0])
Example #9
0
def test_height():
    feature_list = [features.Height()]
    a = testhelper.get_symbol_as_handwriting(97705)
    # TODO: Check if this is correct
    assert a.feature_extraction(feature_list) == [263.0]