Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (125)
Showing with 2788 additions and 2430 deletions
**/.DS_Store
**/Thumbs.db
docs/html/
/emscripten_output/*
# Created by https://www.gitignore.io/api/emacs
......
......@@ -11,3 +11,6 @@
[submodule "dependencies/xmm"]
path = dependencies/xmm
url = https://github.com/Ircam-RnD/xmm
[submodule "dependencies/repovizz2_cpp"]
path = dependencies/repovizz2_cpp
url = https://github.com/slowmountain/repovizz2_cpp.git
cmake_minimum_required(VERSION 2.8.9)
project (rapidmix)
# The version number.
set (rapidmix_VERSION_MAJOR 2)
set (rapidmix_VERSION_MINOR 2)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
# Compiler Flags
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -fPIC")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -DJSON_DEBUG -fPIC")
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
set(CMAKE_BUILD_TYPE "Release")
endif()
# Main lib
include_directories(${PROJECT_SOURCE_DIR}/src)
# RAPID-MIX dependencies
include_directories(dependencies/RapidLib/src)
include_directories(dependencies/xmm/src)
include_directories(dependencies/GVF)
include_directories(dependencies/Maximilian)
include_directories(dependencies/Maximilian/libs)
include_directories(dependencies/pipo/sdk/src)
include_directories(dependencies/pipo/sdk/src/host)
include_directories(dependencies/pipo/modules)
include_directories(dependencies/pipo/modules/collection)
include_directories(dependencies/pipo/modules/bayesfilter/src)
include_directories(dependencies/pipo/modules/finitedifferences)
include_directories(dependencies/pipo/modules/rta/src)
include_directories(dependencies/pipo/modules/rta/src/util)
include_directories(dependencies/pipo/modules/rta/src/statistics)
include_directories(dependencies/pipo/modules/rta/src/signal)
include_directories(dependencies/pipo/modules/rta/bindings/lib)
# Third party dependencies
include_directories(dependencies/third_party/json)
# Source Files
file(GLOB_RECURSE RAPIDMIX_SRC "${PROJECT_SOURCE_DIR}/src/*.cpp")
file(GLOB GVF_SRC "${PROJECT_SOURCE_DIR}/dependencies/GVF/GVF.cpp")
# Maximilian
file(GLOB MAXI_SRC "${PROJECT_SOURCE_DIR}/dependencies/Maximilian/maximilian.cpp")
file(GLOB MAXI_SRC ${MAXI_SRC} "${PROJECT_SOURCE_DIR}/dependencies/Maximilian/libs/maxiFFT.cpp")
file(GLOB MAXI_SRC ${MAXI_SRC} "${PROJECT_SOURCE_DIR}/dependencies/Maximilian/libs/fft.cpp")
#PiPo
file(GLOB_RECURSE PIPO_SRC "${PROJECT_SOURCE_DIR}/dependencies/pipo/sdk/src/*")
file(GLOB_RECURSE PIPO_SRC ${PIPO_SRC} "${PROJECT_SOURCE_DIR}/dependencies/pipo/modules/bayesfilter/src/*")
file(GLOB_RECURSE PIPO_SRC ${PIPO_SRC} "${PROJECT_SOURCE_DIR}/dependencies/pipo/modules/collection/*")
file(GLOB_RECURSE PIPO_SRC ${PIPO_SRC} "${PROJECT_SOURCE_DIR}/dependencies/pipo/modules/finitedifferences/*")
file(GLOB_RECURSE PIPO_SRC ${PIPO_SRC} "${PROJECT_SOURCE_DIR}/dependencies/pipo/modules/rta/src/util/*")
file(GLOB_RECURSE PIPO_SRC ${PIPO_SRC} "${PROJECT_SOURCE_DIR}/dependencies/pipo/modules/rta/src/signal/*")
file(GLOB_RECURSE PIPO_SRC ${PIPO_SRC} "${PROJECT_SOURCE_DIR}/dependencies/pipo/modules/rta/src/statistics/*")
list(REMOVE_ITEM PIPO_SRC "${PROJECT_SOURCE_DIR}/dependencies/pipo/modules/rta/src/signal/rta_onepole.c")
list(REMOVE_ITEM PIPO_SRC "${PROJECT_SOURCE_DIR}/dependencies/pipo/modules/rta/src/signal/rta_resample.c")
list(REMOVE_ITEM PIPO_SRC "${PROJECT_SOURCE_DIR}/dependencies/pipo/modules/rta/src/statistics/rta_cca.c")
# RapidLib
file(GLOB RAPIDLIB_SRC "${PROJECT_SOURCE_DIR}/dependencies/RapidLib/src/*.cpp")
file(GLOB RAPIDLIB_DEP "${PROJECT_SOURCE_DIR}/dependencies/RapidLib/dependencies/libsvm/libsvm.cpp")
# XMM
file(GLOB_RECURSE XMM_SRC "${PROJECT_SOURCE_DIR}/dependencies/xmm/src/*")
file(GLOB JSON_SRC "${PROJECT_SOURCE_DIR}/dependencies/third_party/jsoncpp.cpp")
# Set the source for the main library, using the groups defined above
set(RAPIDMIX_FULL_SRC ${RAPIDMIX_SRC}
${GVF_SRC}
${MAXI_SRC}
${PIPO_SRC}
${RAPIDLIB_SRC}
${RAPIDLIB_DEP}
${XMM_SRC}
${JSON_SRC}
)
add_library(RAPID-MIX_API SHARED ${RAPIDMIX_FULL_SRC})
add_executable(rapidmixTest tests/rapidMixTest.cpp )
add_executable(helloRapidMix ${PROJECT_SOURCE_DIR}/examples/HelloRapidMix/HelloRapidMix/main.cpp)
if (APPLE)
find_library(ACCELERATE Accelerate)
if (NOT ACCELERATE)
message(FATAL_ERROR "Accelearate not found")
endif()
target_link_libraries(RAPID-MIX_API ${ACCELERATE})
endif()
target_link_libraries(rapidmixTest RAPID-MIX_API)
target_link_libraries(helloRapidMix RAPID-MIX_API)
This diff is collapsed.
/**
* Gesture Variation Follower class allows for early gesture recognition and variation tracking
*
* @details Original algorithm designed and implemented in 2011 at Ircam Centre Pompidou
* by Baptiste Caramiaux and Nicola Montecchio. The library has been created and is maintained by Baptiste Caramiaux
*
* Copyright (C) 2015 Baptiste Caramiaux, Nicola Montecchio
* STMS lab Ircam-CRNS-UPMC, University of Padova, Goldsmiths College University of London
*
* The library is under the GNU Lesser General Public License (LGPL v3)
*/
#ifndef _H_GVF
#define _H_GVF
#include "GVFUtils.h"
#include "GVFGesture.h"
#include <random>
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <random>
#include <cmath>
using namespace std;
class GVF
{
public:
/**
* GVF possible states
*/
enum GVFState
{
STATE_CLEAR = 0, /**< STATE_CLEAR: clear the GVF and be in standby */
STATE_LEARNING, /**< STATE_LEARNING: recording mode, input gestures are added to the templates */
STATE_FOLLOWING, /**< STATE_FOLLOWING: tracking mode, input gestures are classifed and their variations tracked (need the GVF to be trained) */
STATE_BYPASS /**< STATE_BYPASS: by pass GVF but does not erase templates or training */
};
#pragma mark - Constructors
/**
* GVF default constructor
* @details use default configuration and parameters, can be changed using accessors
*/
GVF();
/**
* GVF default destructor
*/
~GVF();
#pragma mark - Gesture templates
/**
* Start a gesture either to be recorded or followed
*/
void startGesture();
/**
* Add an observation to a gesture template
* @details
* @param data vector of features
*/
void addObservation(vector<float> data);
/**
* Add gesture template to the vocabulary
*
* @details a gesture template is a GVFGesture object and can be added directly to the vocabulqry or
* recorded gesture templates by using this method
* @param gestureTemplate the gesture template to be recorded
*/
void addGestureTemplate(GVFGesture & gestureTemplate);
/**
* Replace a specific gesture template by another
*
* @param gestureTemplate the gesture template to be used
* @param index the gesture index (as integer) to be replaced
*/
void replaceGestureTemplate(GVFGesture & gestureTemplate, int index);
/**
* Remove a specific template
*
* @param index the gesture index (as integer) to be removed
*/
void removeGestureTemplate(int index);
/**
* Remove every recorded gesture template
*/
void removeAllGestureTemplates();
/**
* Get a specific gesture template a gesture template by another
*
* @param index the index of the template to be returned
* @return the template
*/
GVFGesture & getGestureTemplate(int index);
/**
* Get every recorded gesture template
*
* @return the vecotr of gesture templates
*/
vector<GVFGesture> & getAllGestureTemplates();
/**
* Get number of gesture templates in the vocabulary
* @return the number of templates
*/
int getNumberOfGestureTemplates();
/**
* Get gesture classes
*/
vector<int> getGestureClasses();
#pragma mark - Recognition and tracking
/**
* Set the state of GVF
* @param _state the state to be given to GVF, it is a GVFState
* @param indexes an optional argument providing a list of gesture index.
* In learning mode the index of the gesture being recorded can be given as an argument
* since the type is vector<int>, it should be something like '{3}'. In following mode, the list of indexes
* is the list of active gestures to be considered in the recognition/tracking.
*/
void setState(GVFState _state, vector<int> indexes = vector<int>());
/**
* Return the current state of GVF
* @return GVFState the current state
*/
GVFState getState();
/**
* Compute the estimated gesture and its potential variations
*
* @details infers the probability that the current observation belongs to
* one of the recorded gesture template and track the variations of this gesture
* according to each template
*
* @param observation vector of the observation data at current time
* @return the estimated probabilities and variaitons relative to each template
*/
GVFOutcomes & update(vector<float> & observation);
/**
* Define a subset of gesture templates on which to perform the recognition
* and variation tracking
*
* @details By default every recorded gesture template is considered
* @param set of gesture template index to consider
*/
void setActiveGestures(vector<int> activeGestureIds);
/**
* Restart GVF
* @details re-sample particles at the origin (i.e. initial prior)
*/
void restart();
/**
* Clear GVF
* @details delete templates
*/
void clear();
/**
* Translate data according to the first point
* @details substract each gesture feature by the first point of the gesture
* @param boolean to activate or deactivate translation
*/
void translate(bool translateFlag);
/**
* Segment gestures within a continuous gesture stream
* @details if segmentation is true, the method will segment a continuous gesture into a sequence
* of gestures. In other words no need to call the method startGesture(), it is done automatically
* @param segmentationFlag boolean to activate or deactivate segmentation
*/
void segmentation(bool segmentationFlag);
#pragma mark - [ Accessors ]
#pragma mark > Parameters
/**
* Set tolerance between observation and estimation
* @details tolerance depends on the range of the data
* typially tolerance = (data range)/3.0;
* @param tolerance value
*/
void setTolerance(float tolerance);
/**
* Get the obervation tolerance value
* @details see setTolerance(float tolerance)
* @return the current toleranc value
*/
float getTolerance();
void setDistribution(float _distribution);
/**
* Set number of particles used in estimation
* @details default valye is 1000, note that the computational
* cost directly depends on the number of particles
* @param new number of particles
*/
void setNumberOfParticles(int numberOfParticles);
/**
* Get the current number of particles
* @return the current number of particles
*/
int getNumberOfParticles();
/**
* Number of prediciton steps
* @details it is possible to leave GVF to perform few steps of prediction
* ahead which can be useful to estimate more fastly the variations. Default value is 1
* which means no prediction ahead
* @param the number of prediction steps
*/
void setPredictionSteps(int predictionSteps);
/**
* Get the current number of prediction steps
* @return current number of prediciton steps
*/
int getPredictionSteps();
/**
* Set resampling threshold
* @details resampling threshold is the minimum number of active particles
* before resampling all the particles by the estimated posterior distribution.
* in other words, it re-targets particles around the best current estimates
* @param the minimum number of particles (default is (number of particles)/2)
*/
void setResamplingThreshold(int resamplingThreshold);
/**
* Get the current resampling threshold
* @return resampling threshold
*/
int getResamplingThreshold();
#pragma mark > Dynamics
/**
* Change variance of adaptation in dynamics
* @details if dynamics adaptation variance is high the method will adapt faster to
* fast changes in dynamics. Dynamics is 2-dimensional: the first dimension is the speed
* The second dimension is the acceleration.
*
* Typically the variance is the average amount the speed or acceleration can change from
* one sample to another. As an example, if the relative estimated speed can change from 1.1 to 1.2
* from one sample to another, the variance should allow a change of 0.1 in speed. So the variance
* should be set to 0.1*0.1 = 0.01
*
* @param dynVariance dynamics variance value
* @param dim optional dimension of the dynamics for which the change of variance is applied (default value is 1)
*/
void setDynamicsVariance(float dynVariance, int dim = -1);
/**
* Change variance of adaptation in dynamics
* @details See setDynamicsVariance(float dynVariance, int dim) for more details
* @param dynVariance vector of dynamics variances, each vector index is the variance to be applied to
* each dynamics dimension (consequently the vector should be 2-dimensional).
*/
void setDynamicsVariance(vector<float> dynVariance);
/**
* Get dynamics variances
* @return the vector of variances (the returned vector is 2-dimensional)
*/
vector<float> getDynamicsVariance();
#pragma mark > Scalings
/**
* Change variance of adaptation in scalings
* @details if scalings adaptation variance is high the method will adapt faster to
* fast changes in relative sizes. There is one scaling variance for each dimension
* of the input gesture. If the gesture is 2-dimensional, the scalings variances will
* also be 2-dimensional.
*
* Typically the variance is the average amount the size can change from
* one sample to another. As an example, if the relative estimated size changes from 1.1 to 1.15
* from one sample to another, the variance should allow a change of 0.05 in size. So the variance
* should be set to 0.05*0.05 = 0.0025
*
* @param scalings variance value
* @param dimension of the scalings for which the change of variance is applied
*/
void setScalingsVariance(float scaleVariance, int dim = -1);
/**
* Change variance of adaptation in dynamics
* @details See setScalingsVariance(float scaleVariance, int dim) for more details
* @param vector of scalings variances, each vector index is the variance to be applied to
* each scaling dimension.
* @param vector of variances (should be the size of the template gestures dimension)
*/
void setScalingsVariance(vector<float> scaleVariance);
/**
* Get scalings variances
* @return the vector of variances
*/
vector<float> getScalingsVariance();
#pragma mark > Rotations
/**
* Change variance of adaptation in orientation
* @details if rotation adaptation variance is high the method will adapt faster to
* fast changes in relative orientation. If the gesture is 2-dimensional, there is
* one variance value since the rotation can be defined by only one angle of rotation. If
* the gesture is 3-dimensional, there are 3 variance values since the rotation in 3-d is
* defined by 3 rotation angles. For any other dimension, the rotation is not defined.
*
* The variance is the average amount the orientation can change from one sample to another.
* As an example, if the relative orientation in rad changes from 0.1 to 0.2 from one observation
* to another, the variance should allow a change of 0.1 in rotation angle. So the variance
* should be set to 0.1*0.1 = 0.01
*
* @param rotationsVariance rotation variance value
* @param dim optional dimension of the rotation for which the change of variance is applied
*/
void setRotationsVariance(float rotationsVariance, int dim = -1);
/**
* Change variance of adaptation in orientation
* @details See setRotationsVariance(float rotationsVariance, int dim) for more details
* @param vector of rotation variances, each vector index is the variance to be applied to
* each rotation angle (1 or 3)
* @param vector of variances (should be 1 if the the template gestures are 2-dim or 3 if
* they are 3-dim)
*/
void setRotationsVariance(vector<float> rotationsVariance);
/**
* Get rotation variances
* @return the vector of variances
*/
vector<float> getRotationsVariance();
#pragma mark > Others
/**
* Get particle values
* @return vector of list of estimated particles
*/
const vector<vector<float> > & getParticlesPositions();
/**
* Set the interval on which the dynamics values should be spread at the beginning (before adaptation)
* @details this interval can be used to concentrate the potential dynamics value on a narrow interval,
* typically around 1 (the default value), for instance between -0.05 and 0.05, or to allow at the very
* beginning, high changes in dynamics by spreading, for instance between 0.0 and 2.0
* @param min lower value of the inital values for dynamics
* @param max higher value of the inital values for dynamics
* @param dim the dimension on which the change of initial interval should be applied (optional)
*/
void setSpreadDynamics(float min, float max, int dim = -1);
/**
* Set the interval on which the scalings values should be spread at the beginning (before adaptation)
* @details this interval can be used to concentrate the potential scalings value on a narrow interval,
* typically around 1.0 (the default value), for instance between 0.95 and 1.05, or to allow at the very
* beginning high changes in dynamics by spreading, for instance, between 0.0 and 2.0
* @param min lower value of the inital values for scalings
* @param max higher value of the inital values for scalings
* @param dim the dimension on which the change of initial interval should be applied (optional)
*/
void setSpreadScalings(float min, float max, int dim = -1);
/**
* Set the interval on which the angle of rotation values should be spread at the beginning (before adaptation)
* @details this interval can be used to concentrate the potential angle values on a narrow interval,
* typically around 0.0 (the default value), for instance between -0.05 and 0.05, or to allow at the very
* beginning, high changes in orientation by spreading, for instance, between -0.5 and 0.5
* @param min lower value of the inital values for angle of rotation
* @param max higher value of the inital values for angle of rotation
* @param dim the dimension on which the change of initial interval should be applied (optional)
*/
void setSpreadRotations(float min, float max, int dim = -1);
#pragma mark - Import/Export templates
/**
* Export template data in a filename
* @param filename file name as a string
*/
void saveTemplates(string filename);
/**
* Import template data in a filename
* @details needs to respect a given format provided by saveTemplates()
* @param file name as a string
*/
void loadTemplates(string filename);
protected:
GVFConfig config; // Structure storing the configuration of GVF (in GVFUtils.h)
GVFParameters parameters; // Structure storing the parameters of GVF (in GVFUtils.h)
GVFOutcomes outcomes; // Structure storing the outputs of GVF (in GVFUtils.h)
GVFState state; // State (defined above)
GVFGesture theGesture; // GVFGesture object to handle incoming data in learning and following modes
vector<GVFGesture> gestureTemplates; // vector storing the gesture templates recorded when using the methods addObservation(vector<float> data) or addGestureTemplate(GVFGesture & gestureTemplate)
vector<float> dimWeights; // TOOD: to be put in parameters?
vector<float> maxRange;
vector<float> minRange;
int dynamicsDim; // dynamics state dimension
int scalingsDim; // scalings state dimension
int rotationsDim; // rotation state dimension
float globalNormalizationFactor; // flagged if normalization
int mostProbableIndex; // cached most probable index
int learningGesture;
vector<int> classes; // gesture index for each particle [ns x 1]
vector<float > alignment; // alignment index (between 0 and 1) [ns x 1]
vector<vector<float> > dynamics; // dynamics estimation [ns x 2]
vector<vector<float> > scalings; // scalings estimation [ns x D]
vector<vector<float> > rotations; // rotations estimation [ns x A]
vector<float> weights; // weight of each particle [ns x 1]
vector<float> prior; // prior of each particle [ns x 1]
vector<float> posterior; // poserior of each particle [ns x 1]
vector<float> likelihood; // likelihood of each particle [ns x 1]
// estimations
vector<float> estimatedGesture; // ..
vector<float> estimatedAlignment; // ..
vector<vector<float> > estimatedDynamics; // ..
vector<vector<float> > estimatedScalings; // ..
vector<vector<float> > estimatedRotations; // ..
vector<float> estimatedProbabilities; // ..
vector<float> estimatedLikelihoods; // ..
vector<float> absoluteLikelihoods; // ..
bool tolerancesetmanually;
vector<vector<float> > offsets; // translation offset
vector<int> activeGestures;
vector<float> gestureProbabilities;
vector< vector<float> > particles;
private:
// random number generator
std::random_device rd;
std::mt19937 normgen;
std::normal_distribution<float> *rndnorm;
std::default_random_engine unifgen;
std::uniform_real_distribution<float> *rndunif;
#pragma mark - Private methods for model mechanics
void initPrior();
void initNoiseParameters();
void updateLikelihood(vector<float> obs, int n);
void updatePrior(int n);
void updatePosterior(int n);
void resampleAccordingToWeights(vector<float> obs);
void estimates(); // update estimated outcome
void train();
};
#endif
\ No newline at end of file
//
// GVFGesture.h
// gvf
//
// Created by Baptiste Caramiaux on 22/01/16.
//
//
#ifndef GVFGesture_h
#define GVFGesture_h
#ifndef MAX
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif
class GVFGesture
{
public:
GVFGesture()
{
inputDimensions = 2;
setAutoAdjustRanges(true);
templatesRaw = vector<vector<vector<float > > >();
templatesNormal = vector<vector<vector<float > > >();
clear();
}
GVFGesture(int inputDimension){
inputDimensions = inputDimension;
setAutoAdjustRanges(true);
templatesRaw = vector<vector<vector<float > > >();
templatesNormal = vector<vector<vector<float > > >();
clear();
}
~GVFGesture(){
clear();
}
void setNumberDimensions(int dimensions){
assert(dimensions > 0);
inputDimensions = dimensions;
}
void setAutoAdjustRanges(bool b){
// if(b) bIsRangeMinSet = bIsRangeMaxSet = false;
bAutoAdjustNormalRange = b;
}
void setMax(float x, float y){
assert(inputDimensions == 2);
vector<float> r(2);
r[0] = x; r[1] = y;
setMaxRange(r);
}
void setMin(float x, float y){
assert(inputDimensions == 2);
vector<float> r(2);
r[0] = x; r[1] = y;
setMinRange(r);
}
void setMax(float x, float y, float z){
assert(inputDimensions == 3);
vector<float> r(3);
r[0] = x; r[1] = y; r[2] = z;
setMaxRange(r);
}
void setMin(float x, float y, float z){
assert(inputDimensions == 3);
vector<float> r(3);
r[0] = x; r[1] = y; r[2] = z;
setMinRange(r);
}
void setMaxRange(vector<float> observationRangeMax){
this->observationRangeMax = observationRangeMax;
// bIsRangeMaxSet = true;
normalise();
}
void setMinRange(vector<float> observationRangeMin){
this->observationRangeMin = observationRangeMin;
// bIsRangeMinSet = true;
normalise();
}
vector<float>& getMaxRange(){
return observationRangeMax;
}
vector<float>& getMinRange(){
return observationRangeMin;
}
void autoAdjustMinMax(vector<float> & observation){
if(observationRangeMax.size() < inputDimensions){
observationRangeMax.assign(inputDimensions, -INFINITY);
observationRangeMin.assign(inputDimensions, INFINITY);
}
for(int i = 0; i < inputDimensions; i++){
observationRangeMax[i] = MAX(observationRangeMax[i], observation[i]);
observationRangeMin[i] = MIN(observationRangeMin[i], observation[i]);
}
}
void addObservation(vector<float> observation, int templateIndex = 0){
if (observation.size() != inputDimensions)
inputDimensions = observation.size();
// check we have a valid templateIndex and correct number of input dimensions
assert(templateIndex <= templatesRaw.size());
assert(observation.size() == inputDimensions);
// if the template index is same as the number of temlates make a new template
if(templateIndex == templatesRaw.size()){ // make a new template
// reserve space in raw and normal template storage
templatesRaw.resize(templatesRaw.size() + 1);
templatesNormal.resize(templatesNormal.size() + 1);
}
if(templatesRaw[templateIndex].size() == 0)
{
templateInitialObservation = observation;
templateInitialNormal = observation;
}
for(int j = 0; j < observation.size(); j++)
observation[j] = observation[j] - templateInitialObservation[j];
// store the raw observation
templatesRaw[templateIndex].push_back(observation);
autoAdjustMinMax(observation);
normalise();
}
void normalise()
{
templatesNormal.resize(templatesRaw.size());
for(int t = 0; t < templatesRaw.size(); t++)
{
templatesNormal[t].resize(templatesRaw[t].size());
for(int o = 0; o < templatesRaw[t].size(); o++)
{
templatesNormal[t][o].resize(inputDimensions);
for(int d = 0; d < inputDimensions; d++)
{
templatesNormal[t][o][d] = templatesRaw[t][o][d] / (observationRangeMax[d] - observationRangeMin[d]);
templateInitialNormal[d] = templateInitialObservation[d] / (observationRangeMax[d] - observationRangeMin[d]);
}
}
}
}
void setTemplate(vector< vector<float> > & observations, int templateIndex = 0){
for(int i = 0; i < observations.size(); i++){
addObservation(observations[i], templateIndex);
}
}
vector< vector<float> > & getTemplate(int templateIndex = 0){
assert(templateIndex < templatesRaw.size());
return templatesRaw[templateIndex];
}
int getNumberOfTemplates(){
return templatesRaw.size();
}
int getNumberDimensions(){
return inputDimensions;
}
int getTemplateLength(int templateIndex = 0){
return templatesRaw[templateIndex].size();
}
int getTemplateDimension(int templateIndex = 0){
return templatesRaw[templateIndex][0].size();
}
vector<float>& getLastObservation(int templateIndex = 0){
return templatesRaw[templateIndex][templatesRaw[templateIndex].size() - 1];
}
vector< vector< vector<float> > >& getTemplates(){
return templatesRaw;
}
vector<float>& getInitialObservation(){
return templateInitialObservation;
}
void deleteTemplate(int templateIndex = 0)
{
assert(templateIndex < templatesRaw.size());
templatesRaw[templateIndex].clear();
templatesNormal[templateIndex].clear();
}
void clear()
{
templatesRaw.clear();
templatesNormal.clear();
observationRangeMax.assign(inputDimensions, -INFINITY);
observationRangeMin.assign(inputDimensions, INFINITY);
}
private:
int inputDimensions;
bool bAutoAdjustNormalRange;
vector<float> observationRangeMax;
vector<float> observationRangeMin;
vector<float> templateInitialObservation;
vector<float> templateInitialNormal;
vector< vector< vector<float> > > templatesRaw;
vector< vector< vector<float> > > templatesNormal;
vector<vector<float> > gestureDataFromFile;
};
#endif /* GVFGesture_h */
//
// GVFTypesAndUtils.h
//
//
//
#ifndef __H_GVFTYPES
#define __H_GVFTYPES
#include <map>
#include <vector>
#include <iostream>
#include <random>
#include <iostream>
#include <math.h>
#include <assert.h>
using namespace std;
/**
* Configuration structure
*/
typedef struct
{
int inputDimensions; /**< input dimesnion */
bool translate; /**< translate flag */
bool segmentation; /**< segmentation flag */
} GVFConfig;
/**
* Parameters structure
*/
typedef struct
{
float tolerance; /**< input dimesnion */
float distribution;
int numberParticles;
int resamplingThreshold;
float alignmentVariance;
float speedVariance;
vector<float> scaleVariance;
vector<float> dynamicsVariance;
vector<float> scalingsVariance;
vector<float> rotationsVariance;
// spreadings
float alignmentSpreadingCenter;
float alignmentSpreadingRange;
float dynamicsSpreadingCenter;
float dynamicsSpreadingRange;
float scalingsSpreadingCenter;
float scalingsSpreadingRange;
float rotationsSpreadingCenter;
float rotationsSpreadingRange;
int predictionSteps;
vector<float> dimWeights;
} GVFParameters;
// Outcomes structure
typedef struct
{
int likeliestGesture;
vector<float> likelihoods;
vector<float> alignments;
vector<vector<float> > dynamics;
vector<vector<float> > scalings;
vector<vector<float> > rotations;
} GVFOutcomes;
//--------------------------------------------------------------
// init matrix by allocating memory
template <typename T>
inline void initMat(vector< vector<T> > & M, int rows, int cols){
M.resize(rows);
for (int n=0; n<rows; n++){
M[n].resize(cols);
}
}
//--------------------------------------------------------------
// init matrix and copy values from another matrix
template <typename T>
inline void setMat(vector< vector<T> > & C, vector< vector<float> > & M){
int rows = M.size();
int cols = M[0].size();
//C.resize(rows);
C = vector<vector<T> >(rows);
for (int n=0; n<rows; n++){
//C[n].resize(cols);
C[n] = vector<T>(cols);
for (int m=0;m<cols;m++){
C[n][m] = M[n][m];
}
}
}
//--------------------------------------------------------------
// init matrix by allocating memory and fill with T value
template <typename T>
inline void setMat(vector< vector<T> > & M, T value, int rows, int cols){
M.resize(rows);
for (int n=0; n<rows; n++){
M[n].resize(cols);
for (int m=0; m<cols; m++){
M[n][m] = value;
}
}
}
//--------------------------------------------------------------
// set matrix filled with T value
template <typename T>
inline void setMat(vector< vector<T> > & M, T value){
for (int n=0; n<M.size(); n++){
for (int m=0; m<M[n].size(); m++){
M[n][m] = value;
}
}
}
//--------------------------------------------------------------
template <typename T>
inline void printMat(vector< vector<T> > & M){
for (int k=0; k<M.size(); k++){
cout << k << ": ";
for (int l=0; l<M[0].size(); l++){
cout << M[k][l] << " ";
}
cout << endl;
}
cout << endl;
}
//--------------------------------------------------------------
template <typename T>
inline void printVec(vector<T> & V){
for (int k=0; k<V.size(); k++){
cout << k << ": " << V[k] << (k == V.size() - 1 ? "" : " ,");
}
cout << endl;
}
//--------------------------------------------------------------
template <typename T>
inline void initVec(vector<T> & V, int rows){
V.resize(rows);
}
//--------------------------------------------------------------
template <typename T>
inline void setVec(vector<T> & C, vector<int> &V){
int rows = V.size();
C = vector<T>(rows);
//C.resize(rows);
for (int n=0; n<rows; n++){
C[n] = V[n];
}
}
//--------------------------------------------------------------
template <typename T>
inline void setVec(vector<T> & C, vector<float> & V){
int rows = V.size();
C.resize(rows);
for (int n=0; n<rows; n++){
C[n] = V[n];
}
}
//--------------------------------------------------------------
template <typename T>
inline void setVec(vector<T> & V, T value){
for (int n=0; n<V.size(); n++){
V[n] = value;
}
}
//--------------------------------------------------------------
template <typename T>
inline void setVec(vector<T> & V, T value, int rows){
V.resize(rows);
setVec(V, value);
}
//--------------------------------------------------------------
template <typename T>
inline vector< vector<T> > dotMat(vector< vector<T> > & M1, vector< vector<T> > & M2){
// TODO(Baptiste)
}
//--------------------------------------------------------------
template <typename T>
inline vector< vector<T> > multiplyMatf(vector< vector<T> > & M1, T v){
vector< vector<T> > multiply;
initMat(multiply, M1.size(), M1[0].size());
for (int i=0; i<M1.size(); i++){
for (int j=0; j<M1[i].size(); j++){
multiply[i][j] = M1[i][j] * v;
}
}
return multiply;
}
//--------------------------------------------------------------
template <typename T>
inline vector< vector<T> > multiplyMatf(vector< vector<T> > & M1, vector< vector<T> > & M2){
assert(M1[0].size() == M2.size()); // columns in M1 == rows in M2
vector< vector<T> > multiply;
initMat(multiply, M1.size(), M2[0].size()); // rows in M1 x cols in M2
for (int i=0; i<M1.size(); i++){
for (int j=0; j<M2[i].size(); j++){
multiply[i][j] = 0.0f;
for(int k=0; k<M1[0].size(); k++){
multiply[i][j] += M1[i][k] * M2[k][j];
}
}
}
return multiply;
}
//--------------------------------------------------------------
template <typename T>
inline vector<T> multiplyMat(vector< vector<T> > & M1, vector< T> & Vect){
assert(Vect.size() == M1[0].size()); // columns in M1 == rows in Vect
vector<T> multiply;
initVec(multiply, Vect.size());
for (int i=0; i<M1.size(); i++){
multiply[i] = 0.0f;
for (int j=0; j<M1[i].size(); j++){
multiply[i] += M1[i][j] * Vect[j];
}
}
return multiply;
}
//--------------------------------------------------------------
template <typename T>
inline float getMeanVec(vector<T>& V){
float tSum = 0.0f;
for (int n=0; n<V.size(); n++){
tSum += V[n];
}
return tSum / (float)V.size();
}
template <typename T>
inline vector<vector<float> > getRotationMatrix3d(T phi, T theta, T psi)
{
vector< vector<float> > M;
initMat(M,3,3);
M[0][0] = cos(theta)*cos(psi);
M[0][1] = -cos(phi)*sin(psi)+sin(phi)*sin(theta)*cos(psi);
M[0][2] = sin(phi)*sin(psi)+cos(phi)*sin(theta)*cos(psi);
M[1][0] = cos(theta)*sin(psi);
M[1][1] = cos(phi)*cos(psi)+sin(phi)*sin(theta)*sin(psi);
M[1][2] = -sin(phi)*cos(psi)+cos(phi)*sin(theta)*sin(psi);
M[2][0] = -sin(theta);
M[2][1] = sin(phi)*cos(theta);
M[2][2] = cos(phi)*cos(theta);
return M;
}
template <typename T>
float distance_weightedEuclidean(vector<T> x, vector<T> y, vector<T> w)
{
int count = x.size();
if (count <= 0) return 0;
float dist = 0.0;
for(int k = 0; k < count; k++) dist += w[k] * pow((x[k] - y[k]), 2);
return dist;
}
////--------------------------------------------------------------
//vector<vector<float> > getRotationMatrix3d(float phi, float theta, float psi)
//{
// vector< vector<float> > M;
// initMat(M,3,3);
//
// M[0][0] = cos(theta)*cos(psi);
// M[0][1] = -cos(phi)*sin(psi)+sin(phi)*sin(theta)*cos(psi);
// M[0][2] = sin(phi)*sin(psi)+cos(phi)*sin(theta)*cos(psi);
//
// M[1][0] = cos(theta)*sin(psi);
// M[1][1] = cos(phi)*cos(psi)+sin(phi)*sin(theta)*sin(psi);
// M[1][2] = -sin(phi)*cos(psi)+cos(phi)*sin(theta)*sin(psi);
//
// M[2][0] = -sin(theta);
// M[2][1] = sin(phi)*cos(theta);
// M[2][2] = cos(phi)*cos(theta);
//
// return M;
//}
//float distance_weightedEuclidean(vector<float> x, vector<float> y, vector<float> w)
//{
// int count = x.size();
// if (count <= 0) return 0;
// float dist = 0.0;
// for(int k = 0; k < count; k++) dist += w[k] * pow((x[k] - y[k]), 2);
// return dist;
//}
#endif
......@@ -3,11 +3,27 @@
It has been built with RAPID-MIX technologies, that make it easy to combine sensor data, machine learning algorithms and interactive audio. They provide a full set of functionalities for cross-device and cross-platform development, modular components, and cloud-based services and multimodal data storage.
## Dependencies
Use `git submodule init` followed by `git submodule update` to pull the following library dependencies.
Use `git submodule update --init --recursive` to pull the following library dependencies.
1. RapidLib
2. XMM
3. GVF
4. RepoVizz2 Client
1. XMM
1. PiPo
1. GVF
1. RepoVizz2 Client
## Documentation
Full documentation at http://www.rapidmixapi.com/
## Testing
We are using Catch for C++ testing. Look at the test fixtures in the /tests/test_projetc/test_project.xcodeproj for an example of how to implement them.
\ No newline at end of file
We are using Catch for C++ testing. Look at the test fixtures in the /tests/test_projetc/test_project.xcodeproj for an example of how to implement them.
## Building with CMake
Navigate to /RAPID-MIX_API and run this in a terminal:
`mkdir build
cd build
cmake ..
make
`
Or run the shell script: `./rmix_build_test.sh`
\ No newline at end of file
......@@ -192,7 +192,7 @@ void GVF::addGestureTemplate(GVFGesture & gestureTemplate)
config.inputDimensions = inputDimension;
gestureTemplates.push_back(gestureTemplate);
activeGestures.push_back(gestureTemplates.size());
activeGestures.push_back(int(gestureTemplates.size()));
if(minRange.size() == 0){
minRange.resize(inputDimension);
......
......@@ -114,7 +114,7 @@ public:
void addObservation(vector<float> observation, int templateIndex = 0){
if (observation.size() != inputDimensions)
inputDimensions = observation.size();
inputDimensions = int(observation.size());
// check we have a valid templateIndex and correct number of input dimensions
assert(templateIndex <= templatesRaw.size());
......@@ -178,7 +178,7 @@ public:
}
int getNumberOfTemplates(){
return templatesRaw.size();
return int(templatesRaw.size());
}
int getNumberDimensions(){
......@@ -186,11 +186,11 @@ public:
}
int getTemplateLength(int templateIndex = 0){
return templatesRaw[templateIndex].size();
return int(templatesRaw[templateIndex].size());
}
int getTemplateDimension(int templateIndex = 0){
return templatesRaw[templateIndex][0].size();
return int(templatesRaw[templateIndex][0].size());
}
vector<float>& getLastObservation(int templateIndex = 0){
......
......@@ -82,8 +82,8 @@ inline void initMat(vector< vector<T> > & M, int rows, int cols){
// init matrix and copy values from another matrix
template <typename T>
inline void setMat(vector< vector<T> > & C, vector< vector<float> > & M){
int rows = M.size();
int cols = M[0].size();
int rows = int(M.size());
int cols = int(M[0].size());
//C.resize(rows);
C = vector<vector<T> >(rows);
for (int n=0; n<rows; n++){
......@@ -150,7 +150,7 @@ inline void initVec(vector<T> & V, int rows){
//--------------------------------------------------------------
template <typename T>
inline void setVec(vector<T> & C, vector<int> &V){
int rows = V.size();
int rows = int(V.size());
C = vector<T>(rows);
//C.resize(rows);
for (int n=0; n<rows; n++){
......@@ -161,7 +161,7 @@ inline void setVec(vector<T> & C, vector<int> &V){
//--------------------------------------------------------------
template <typename T>
inline void setVec(vector<T> & C, vector<float> & V){
int rows = V.size();
int rows = int(V.size());
C.resize(rows);
for (int n=0; n<rows; n++){
C[n] = V[n];
......@@ -225,7 +225,7 @@ template <typename T>
inline vector<T> multiplyMat(vector< vector<T> > & M1, vector< T> & Vect){
assert(Vect.size() == M1[0].size()); // columns in M1 == rows in Vect
vector<T> multiply;
initVec(multiply, Vect.size());
initVec(multiply, int(Vect.size()));
for (int i=0; i<M1.size(); i++){
multiply[i] = 0.0f;
for (int j=0; j<M1[i].size(); j++){
......@@ -269,7 +269,7 @@ inline vector<vector<float> > getRotationMatrix3d(T phi, T theta, T psi)
template <typename T>
float distance_weightedEuclidean(vector<T> x, vector<T> y, vector<T> w)
{
int count = x.size();
int count = int(x.size());
if (count <= 0) return 0;
float dist = 0.0;
for(int k = 0; k < count; k++) dist += w[k] * pow((x[k] - y[k]), 2);
......
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
Subproject commit f5cfd55793699b3a8ed9a2ac08cd8db9b9082732
Subproject commit 22c4e36d58eb7f2aecf03fb8da7a07211b76432f
RapidLib @ ab5950e8
Subproject commit 803fe51a29911bf5d8e4652eb6fb3c8dbce21e50
Subproject commit ab5950e8ff4c20b1c9e1ec9b8f369fcadbabdca6
Subproject commit 0643ed47778d5a4e2b95151a2836f50f382915f7
Subproject commit 9029d999f5d381645cf82ae478b3b875ec19800f
Subproject commit 1d708c1e7f97760239899e1d943751d91aea580e
This diff is collapsed.
File added
File added
File added