Commit a3f0d14e authored by mzed's avatar mzed
Browse files

adding getCost functions

parent 3e931c47
......@@ -153,6 +153,9 @@ int main(int argc, const char * argv[]) {
myDtw.addSeries(seriesTwo);
assert(myDtw.run(seriesOne) == 0);
assert(myDtw.getCosts()[0] == 0);
assert(myDtw.getCosts()[1] == 19.325403217417502);
assert(myDtw.run(seriesTwo) == 1);
std::vector<std::vector<std::vector<double>>> seriesSet;
......@@ -211,6 +214,9 @@ int main(int argc, const char * argv[]) {
assert(myDtw2T.runTrainingSet(tsOne) == 0);
assert(myDtw2T.runTrainingSet(tsTwo) == 1);
assert(myDtw.getCosts()[0] == 19.325403217417502);
assert(myDtw2T.getCosts(tsOne)[0] == 0);
return 0;
}
......@@ -60,16 +60,17 @@ void seriesClassification::reset() {
int seriesClassification::run(const std::vector<std::vector<double>> &inputSeries) {
//TODO: check vector sizes and reject bad data
int closestSeries = 0;
allCosts.clear();
double lowestCost = dtwClassifiers[0].run(inputSeries);
for (int i = 0; i < dtwClassifiers.size(); ++i) {
allCosts.push_back(lowestCost);
for (int i = 1; i < dtwClassifiers.size(); ++i) {
double currentCost = dtwClassifiers[i].run(inputSeries);
allCosts.push_back(currentCost);
if (currentCost < lowestCost) {
lowestCost = currentCost;
closestSeries = i;
}
}
return closestSeries;
};
......@@ -79,4 +80,13 @@ int seriesClassification::runTrainingSet(const std::vector<trainingExample> &tra
newSeries.push_back(trainingSet[i].input);
}
return run(newSeries);
};
\ No newline at end of file
};
std::vector<double> seriesClassification::getCosts() {
return allCosts;
}
std::vector<double> seriesClassification::getCosts(const std::vector<trainingExample> &trainingSet) {
runTrainingSet(trainingSet);
return allCosts;
}
\ No newline at end of file
......@@ -30,8 +30,12 @@ public:
int run(const std::vector<std::vector<double>> &inputSeries);
int runTrainingSet(const std::vector<trainingExample> &inputSet);
std::vector<double> getCosts();
std::vector<double> getCosts(const std::vector<trainingExample> &inputSet);
private:
std::vector<dtw> dtwClassifiers;
std::vector<double> allCosts;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment