Commit 59e5d46a authored by mzed's avatar mzed
Browse files

wrapping DTW in seriesClassification, building with emscripten

parent 308c70ec
......@@ -9,8 +9,9 @@ RL_KNN=src/knnClassification.cpp src/classification.cpp
RL_SVM=src/svmClassification.cpp dependancies/libsvm/libsvm.cpp
RL_NN=src/neuralNetwork.cpp src/regression.cpp
RL_MS=src/modelSet.cpp
RL_DTW = src/dtw.cpp src/seriesClassification.cpp
RL_STREAM=src/rapidStream.cpp
SOURCE_RAPID = $(RL_MS) $(RL_NN) $(RL_KNN) $(RL_SVM) $(RL_STREAM)
SOURCE_RAPID = $(RL_MS) $(RL_NN) $(RL_KNN) $(RL_SVM) $(RL_DTW) $(RL_STREAM)
# destination .js file
OUTPUT_RAPID=rapidLib/RapidLib.js
......
......@@ -15,6 +15,7 @@
BE325F501DB50BFE00F199A8 /* neuralNetwork.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE325F461DB50BFE00F199A8 /* neuralNetwork.cpp */; };
BE325F511DB50BFE00F199A8 /* regression.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE325F4A1DB50BFE00F199A8 /* regression.cpp */; };
BE3852881EE847730008E1BD /* dtw.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE3852871EE847730008E1BD /* dtw.cpp */; };
BE38528B1EE94D740008E1BD /* seriesClassification.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE3852891EE94D740008E1BD /* seriesClassification.cpp */; };
BE553E2C1EE05ED2004EB00F /* libsvm.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE553E2A1EE05ED2004EB00F /* libsvm.cpp */; };
BE553E2F1EE05FE1004EB00F /* svmClassification.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE553E2E1EE05FE1004EB00F /* svmClassification.cpp */; };
/* End PBXBuildFile section */
......@@ -50,6 +51,8 @@
BE325F4B1DB50BFE00F199A8 /* regression.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = regression.h; sourceTree = "<group>"; };
BE3852861EE8415E0008E1BD /* dtw.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = dtw.h; sourceTree = "<group>"; };
BE3852871EE847730008E1BD /* dtw.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = dtw.cpp; sourceTree = "<group>"; };
BE3852891EE94D740008E1BD /* seriesClassification.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = seriesClassification.cpp; sourceTree = "<group>"; };
BE38528A1EE94D740008E1BD /* seriesClassification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = seriesClassification.h; sourceTree = "<group>"; };
BE553E2A1EE05ED2004EB00F /* libsvm.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = libsvm.cpp; sourceTree = "<group>"; };
BE553E2B1EE05ED2004EB00F /* libsvm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = libsvm.h; sourceTree = "<group>"; };
BE553E2D1EE05F03004EB00F /* svmClassification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = svmClassification.h; sourceTree = "<group>"; };
......@@ -133,6 +136,8 @@
BE325F4B1DB50BFE00F199A8 /* regression.h */,
BE3852861EE8415E0008E1BD /* dtw.h */,
BE3852871EE847730008E1BD /* dtw.cpp */,
BE3852891EE94D740008E1BD /* seriesClassification.cpp */,
BE38528A1EE94D740008E1BD /* seriesClassification.h */,
);
name = src;
path = ../../src;
......@@ -210,6 +215,7 @@
BE325F4F1DB50BFE00F199A8 /* modelSet.cpp in Sources */,
BE325F4D1DB50BFE00F199A8 /* classification.cpp in Sources */,
BE325F511DB50BFE00F199A8 /* regression.cpp in Sources */,
BE38528B1EE94D740008E1BD /* seriesClassification.cpp in Sources */,
BE325F501DB50BFE00F199A8 /* neuralNetwork.cpp in Sources */,
BE15ECE31DBA4E1000E88F7C /* jsoncpp.cpp in Sources */,
BE3852881EE847730008E1BD /* dtw.cpp in Sources */,
......
......@@ -5,7 +5,7 @@
#include <algorithm>
#include "regression.h"
#include "classification.h"
#include "dtw.h"
#include "seriesClassification.h"
#include "json.h"
int main(int argc, const char * argv[]) {
......@@ -134,24 +134,25 @@ int main(int argc, const char * argv[]) {
////////////
dtw myDtw;
std::vector<std::vector<double>> trainingSeries;
trainingSeries.push_back( { 1., 5.} );
trainingSeries.push_back( { 2., 4.} );
trainingSeries.push_back( { 3., 3.} );
trainingSeries.push_back( { 4., 2.} );
trainingSeries.push_back( { 5., 1.} );
myDtw.setSeries(trainingSeries);
std::vector<std::vector<double>> inputSeries;
inputSeries.push_back( { 1., 4. } );
inputSeries.push_back( { 2., 3. } );
inputSeries.push_back( { 3., 2. } );
inputSeries.push_back( { 4., 1. } );
std::cout << "dtw: " << myDtw.process(inputSeries) << std::endl;
std::cout << "dtw: " << myDtw.process(trainingSeries) << std::endl;
seriesClassification myDtw;
std::vector<std::vector<double>> seriesOne;
seriesOne.push_back( { 1., 5.} );
seriesOne.push_back( { 2., 4.} );
seriesOne.push_back( { 3., 3.} );
seriesOne.push_back( { 4., 2.} );
seriesOne.push_back( { 5., 1.} );
myDtw.addSeries(seriesOne);
std::vector<std::vector<double>> seriesTwo;
seriesTwo.push_back( { 1., 4. } );
seriesTwo.push_back( { 2., -3. } );
seriesTwo.push_back( { 1., 5. } );
seriesTwo.push_back( { -2., 1. } );
myDtw.addSeries(seriesTwo);
std::cout << "dtw: " << myDtw.process(seriesOne) << std::endl;
std::cout << "dtw: " << myDtw.process(seriesTwo) << std::endl;
return 0;
}
//
// seriesClassification.cpp
// RapidAPI
//
// Created by mzed on 08/06/2017.
// Copyright © 2017 Goldsmiths. All rights reserved.
//
#include <vector>
#include "seriesClassification.h"
#ifdef EMSCRIPTEN
#include "emscripten/seriesClassificationEmbindings.h"
#endif
seriesClassification::seriesClassification() {};
seriesClassification::~seriesClassification() {};
bool seriesClassification::addSeries(std::vector<std::vector<double>> newSeries) {
dtw newDTW;
newDTW.setSeries(newSeries);
dtwClassifiers.push_back(newDTW);
return true;
}
void seriesClassification::clear() {
dtwClassifiers.clear();
}
int seriesClassification::process(std::vector<std::vector<double>> inputSeries) {
//TODO: check vector sizes and reject bad data
int closestSeries = 0;
double lowestCost = dtwClassifiers[0].process(inputSeries);
for (int i = 1; i < dtwClassifiers.size(); ++i) {
double currentCost = dtwClassifiers[i].process(inputSeries);
if (currentCost < lowestCost) {
lowestCost = currentCost;
closestSeries = i;
}
}
return closestSeries;
};
\ No newline at end of file
//
// seriesClassification.hp
// RapidAPI
//
// Created by mzed on 08/06/2017.
// Copyright © 2017 Goldsmiths. All rights reserved.
//
#ifndef seriesClassification_hpp
#define seriesClassification_hpp
#include <vector>
#include "dtw.h"
class seriesClassification {
public:
seriesClassification();
~seriesClassification();
bool addSeries(std::vector<std::vector<double>> newSeries);
void clear();
int process(std::vector<std::vector<double>> inputSeries);
private:
std::vector<dtw> dtwClassifiers;
};
#endif
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