Commit 46a487ba authored by Michael Zbyszyński's avatar Michael Zbyszyński
Browse files

Merge remote-tracking branch 'refs/remotes/origin/develop' into develop

parents 7d650749 34368f86
......@@ -14,7 +14,7 @@
#include "classification.h"
#include "regression.h"
#include "rapidXmmTools.h"
//#include "gvf.h"
#include "rapidGVF.h"
// forward declaration
namespace rapidmix { class trainingData; }
......@@ -58,11 +58,9 @@ typedef machineLearning<xmmGmmTool> xmmStaticClassification;
typedef machineLearning<xmmGmrTool> xmmStaticRegression;
typedef machineLearning<xmmHmmTool> xmmTemporalClassification;
typedef machineLearning<xmmHmrTool> xmmTemporalRegression;
//*/
/*
typedef machineLearning<GVF> gvf;
//*/
typedef machineLearning<rapidGVF> gvfTemporalVariation;
RAPIDMIX_END_NAMESPACE
......
//
// rapidGVF.cpp
//
// Created by Francisco on 04/05/2017.
// Copyright © 2017 Goldsmiths. All rights reserved.
//
#include "rapidGVF.h"
#include "trainingData.h"
rapidGVF::rapidGVF()
{
// Initialised with default configuration
this->gvf = new GVF();
this->currentGesture = GVFGesture();
}
rapidGVF::~rapidGVF()
{
delete this->gvf;
this->currentGesture = NULL;
}
template<>
bool rapidmix::machineLearning<rapidGVF>::train(const trainingData &newTrainingData) {
return rapidGVF::train(newTrainingData);
}
bool rapidGVF::train(const rapidmix::trainingData &newTrainingData) {
if (newTrainingData.trainingSet.size() <= 1) {
// no recorded phrase (only default one)
return false;
}
if (newTrainingData.trainingSet.size() > 1 && newTrainingData.trainingSet[1].elements.size() == 0) {
// empty recorded phrase
return false;
}
//Go through every phrase
for (int h = 0; h < newTrainingData.trainingSet.size(); ++h) {
for (int i = 0; i < newTrainingData.trainingSet[h].elements.size(); ++i) {
this->currentGesture.clear();
std::vector<double> vd = newTrainingData.trainingSet[h].elements[i].input;
// Using template <class InputIterator> vector to change for vec<double> to vec<float>
std::vector<float> vf(vd.begin(), vd.end());
this->currentGesture.addObservation(vf);
}
this->gvf->addGestureTemplate(this->currentGesture);
}
return true;
}
template<>
std::vector<double> rapidmix::machineLearning<rapidGVF>::run(const std::vector<double> &inputVector) {
return rapidGVF::process(inputVector);
}
std::vector<double> rapidGVF::process(const std::vector<double> &inputVector){
gvf->restart();
// Using template <class InputIterator> vector to change for vec<double> to vec<float>
std::vector<float> vf(inputVector.begin(),inputVector.end());
this->currentGesture.addObservation(vf);
this->outcomes = this->gvf->update(this->currentGesture.getLastObservation());
std::vector<double> output;
output.insert(output.end(), this->outcomes.likeliestGesture, 1);
output.insert(output.end(), this->outcomes.likelihoods.begin(), this->outcomes.likelihoods.end());
output.insert(output.end(), this->outcomes.alignments.begin(), this->outcomes.alignments.end());
// output.insert(output.end(), this->outcomes.dynamics.begin(), this->outcomes.dynamics.end());
// output.insert(output.end(), this->outcomes.scalings.begin(), this->outcomes.scalings.end());
// output.insert(output.end(), this->outcomes.scalings.begin(), this->outcomes.scalings.end());
//
return output;
}
//
// rapidGVF.h
//
// Created by Francisco on 04/05/2017.
// Copyright © 2017 Goldsmiths. All rights reserved.
//
#ifndef rapidGVF_h
#define rapidGVF_h
#include <vector>
#include <string>
#include "GVF.h"
namespace rapidmix { class trainingData; }
class rapidGVF {
public:
rapidGVF();
~rapidGVF();
bool train(const rapidmix::trainingData &newTrainingData);
std::vector<double> process(const std::vector<double> &inputVector);
protected:
GVF * gvf;
GVFGesture currentGesture;
GVFOutcomes outcomes;
};
#endif
......@@ -9,7 +9,7 @@
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
#include "machineLearning.h"
#include "trainingData.h"
TEST_CASE( "Tests default GVF ctor.", "[GVF]" ) {
......@@ -36,10 +36,8 @@ TEST_CASE( "Tests default GVFGesture ctor.", "[GVF]" ) {
gvf->setScalingsVariance(0.00001f); //0.00001f); //0.000002f); //0.00004f);
gvf->setDynamicsVariance(0.0001f);
vector<vector<float>> trainingData;
if(gvf->getState() == GVF::STATE_LEARNING)
{
gvf->startGesture();
......@@ -49,7 +47,6 @@ TEST_CASE( "Tests default GVFGesture ctor.", "[GVF]" ) {
// Fill the template
gesture.addObservation(*frame);
}
}
gvf->setState(GVF::STATE_FOLLOWING);
......@@ -66,7 +63,6 @@ TEST_CASE( "Tests default GVFGesture ctor.", "[GVF]" ) {
// Fill the template
gesture.addObservation(*frame);
}
gvf->update(gesture.getLastObservation());
}
......@@ -86,9 +82,9 @@ SCENARIO("Test GVF Regression", "[machineLearning]")
{
GIVEN("gvf object and training dataset")
{
rapidmix::gvf gvf;
rapidmix::gvfTemporalVariation gvf;
rapidmix::trainingData myData;
std::vector<double> input = { 0.2, 0.7 };
std::vector<double> output = { 3.0 };
myData.addElement(input, output);
......@@ -99,18 +95,12 @@ SCENARIO("Test GVF Regression", "[machineLearning]")
gvf.train(myData);
// gvf.process(input);
gvf.process(input);
std::string filepath2 = "/var/tmp/modelSetDescription_gvf.json";
// gvf.writeJSON(filepath2);
// rapidmix::staticClassification gvfFromString;
// gvfFromString.putJSON(gvf.getJSON());
// rapidmix::staticClassification gvfFromFile;
// gvfFromFile.readJSON(filepath2);
std::vector<double> inputVec = { 2.0, 44.2 };
......@@ -246,4 +236,4 @@ unsigned int runGVF(){
// REQUIRE( Factorial(2) == 2 );
// REQUIRE( Factorial(3) == 6 );
// REQUIRE( Factorial(10) == 3628800 );
//}
\ No newline at end of file
//}
......@@ -7,6 +7,10 @@
objects = {
/* Begin PBXBuildFile section */
0BA41BAD1EE6E0ED00B74667 /* trainingData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE2C5EC01ED8459300E9FAFA /* trainingData.cpp */; };
0BA41BAE1EE6E10A00B74667 /* jsoncpp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE2C5E081ED8450E00E9FAFA /* jsoncpp.cpp */; };
0BE2E7371EE56F4F00722712 /* rapidGVF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0BE2E7351EE56F4F00722712 /* rapidGVF.cpp */; };
0BE2E7381EE56F5800722712 /* GVF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0BE2E72F1EE56E6D00722712 /* GVF.cpp */; };
311BA2A61EDC6A8900244DAC /* test_rapidXmmTools.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BE2C5EE21ED8480D00E9FAFA /* test_rapidXmmTools.cpp */; };
311BA2FD1EDC6F9F00244DAC /* rapidXmmTools.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 311BA2A91EDC6ADB00244DAC /* rapidXmmTools.cpp */; };
311BA2FE1EDC6FD000244DAC /* xmmKMeans.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 311BA2C61EDC6EC100244DAC /* xmmKMeans.cpp */; };
......@@ -107,6 +111,13 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
0BE2E72F1EE56E6D00722712 /* GVF.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GVF.cpp; sourceTree = "<group>"; };
0BE2E7301EE56E6D00722712 /* GVF.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GVF.h; sourceTree = "<group>"; };
0BE2E7311EE56E6D00722712 /* GVFGesture.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GVFGesture.h; sourceTree = "<group>"; };
0BE2E7321EE56E6D00722712 /* GVFUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GVFUtils.h; sourceTree = "<group>"; };
0BE2E7331EE56E6D00722712 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
0BE2E7351EE56F4F00722712 /* rapidGVF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = rapidGVF.cpp; sourceTree = "<group>"; };
0BE2E7361EE56F4F00722712 /* rapidGVF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rapidGVF.h; sourceTree = "<group>"; };
0BFFEF1B1E56082700EF19A5 /* test_GVF */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = test_GVF; sourceTree = BUILT_PRODUCTS_DIR; };
0BFFEF261E56083C00EF19A5 /* test_RapidLib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = test_RapidLib; sourceTree = BUILT_PRODUCTS_DIR; };
0BFFEF311E56085C00EF19A5 /* test_rapidXmmTools */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = test_rapidXmmTools; sourceTree = BUILT_PRODUCTS_DIR; };
......@@ -369,6 +380,27 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
0BE2E72E1EE56E6D00722712 /* GVF */ = {
isa = PBXGroup;
children = (
0BE2E72F1EE56E6D00722712 /* GVF.cpp */,
0BE2E7301EE56E6D00722712 /* GVF.h */,
0BE2E7311EE56E6D00722712 /* GVFGesture.h */,
0BE2E7321EE56E6D00722712 /* GVFUtils.h */,
0BE2E7331EE56E6D00722712 /* LICENSE */,
);
path = GVF;
sourceTree = "<group>";
};
0BE2E7341EE56F4F00722712 /* rapidGVF */ = {
isa = PBXGroup;
children = (
0BE2E7351EE56F4F00722712 /* rapidGVF.cpp */,
0BE2E7361EE56F4F00722712 /* rapidGVF.h */,
);
path = rapidGVF;
sourceTree = "<group>";
};
311BA2A41EDC698600244DAC /* pipo */ = {
isa = PBXGroup;
children = (
......@@ -577,6 +609,7 @@
BE2C5A081ED8450C00E9FAFA /* dependencies */ = {
isa = PBXGroup;
children = (
0BE2E72E1EE56E6D00722712 /* GVF */,
311BA2A51EDC698D00244DAC /* xmm */,
311BA2A41EDC698600244DAC /* pipo */,
BE2C5A091ED8450C00E9FAFA /* Maximilian */,
......@@ -696,6 +729,7 @@
BE2C5EBD1ED8459300E9FAFA /* machineLearning */ = {
isa = PBXGroup;
children = (
0BE2E7341EE56F4F00722712 /* rapidGVF */,
311BA2A71EDC6AC300244DAC /* rapidXmmTools */,
BE2C5EBE1ED8459300E9FAFA /* machineLearning.cpp */,
BE2C5EBF1ED8459300E9FAFA /* machineLearning.h */,
......@@ -1043,7 +1077,7 @@
BE325F291DB50BE100F199A8 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0730;
LastUpgradeCheck = 0830;
ORGANIZATIONNAME = Goldsmiths;
TargetAttributes = {
0BFFEF1A1E56082700EF19A5 = {
......@@ -1086,7 +1120,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0BA41BAE1EE6E10A00B74667 /* jsoncpp.cpp in Sources */,
0BE2E7381EE56F5800722712 /* GVF.cpp in Sources */,
0BE2E7371EE56F4F00722712 /* rapidGVF.cpp in Sources */,
BEA7B7211EDD97130003E84B /* test_gvf.cpp in Sources */,
0BA41BAD1EE6E0ED00B74667 /* trainingData.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -1167,6 +1205,8 @@
0BFFEF201E56082700EF19A5 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_WARN_INT_CONVERSION = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = NO;
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
......@@ -1176,6 +1216,8 @@
0BFFEF211E56082700EF19A5 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_WARN_INT_CONVERSION = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = NO;
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
......@@ -1262,8 +1304,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
......@@ -1305,8 +1349,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
......
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