seriesClassification.cpp 1.55 KB
Newer Older
1
2
3
//
//  seriesClassification.cpp
//
mzed's avatar
mzed committed
4
//  Created by Michael Zbyszynski on 08/06/2017.
5
6
7
8
9
10
11
12
13
14
15
16
17
//  Copyright © 2017 Goldsmiths. All rights reserved.
//

#include <vector>
#include "seriesClassification.h"
#ifdef EMSCRIPTEN
#include "emscripten/seriesClassificationEmbindings.h"
#endif

seriesClassification::seriesClassification() {};

seriesClassification::~seriesClassification() {};

mzed's avatar
mzed committed
18
bool seriesClassification::trainLabel(const std::vector<trainingSeries> &seriesSet) {
mzed's avatar
mzed committed
19
20
    reset();
    bool trained = true;
mzed's avatar
mzed committed
21
    allTrainingSeries = seriesSet;
mzed's avatar
mzed committed
22

mzed's avatar
mzed committed
23
24
    //TODO: calculate some size statistics here?
    
mzed's avatar
mzed committed
25
26
27
    return trained;
};

mzed's avatar
mzed committed
28
void seriesClassification::reset() {
mzed's avatar
mzed committed
29
30
    allCosts.clear();
    allTrainingSeries.clear();
31
32
}

mzed's avatar
mzed committed
33
34
std::string seriesClassification::runLabel(const std::vector<std::vector<double>> &inputSeries) {
    dtw dtw;
35
    int closestSeries = 0;
mzed's avatar
mzed committed
36
    allCosts.clear();
mzed's avatar
mzed committed
37
    double lowestCost = dtw.getCost(inputSeries, allTrainingSeries[0].input);
mzed's avatar
mzed committed
38
    allCosts.push_back(lowestCost);
mzed's avatar
mzed committed
39
40
41
    
    for (int i = 1; i < allTrainingSeries.size(); ++i) {
        double currentCost = dtw.getCost(inputSeries, allTrainingSeries[i].input);
mzed's avatar
mzed committed
42
        allCosts.push_back(currentCost);
43
44
45
46
47
        if (currentCost < lowestCost) {
            lowestCost = currentCost;
            closestSeries = i;
        }
    }
mzed's avatar
mzed committed
48
    return allTrainingSeries[closestSeries].label;
mzed's avatar
mzed committed
49
50
};

mzed's avatar
mzed committed
51

mzed's avatar
mzed committed
52
53
54
55
56
57
58
59
//std::vector<double> seriesClassification::getCosts() {
//    return allCosts;
//}
//
//std::vector<double> seriesClassification::getCosts(const std::vector<trainingExample> &trainingSet) {
//    run(trainingSet);
//    return allCosts;
//}