Skip to content
Snippets Groups Projects
Commit bd9276fc authored by Michael Zbyszyński's avatar Michael Zbyszyński
Browse files

adding machine learning class

parent c69a917d
Branches
Tags
No related merge requests found
/*
* machineLearning.h
* Created by Michael Zbyszynski on 10 Jan 2016
* Copyright © 2017 Goldsmiths. All rights reserved.
*/
#include "machineLearning.h"
RAPIDMIX_BEGIN_NAMESPACE
void trainingData2rapidLib (const trainingData &newTrainingData, std::vector<trainingExample> &trainingSet) {
for (int h = 0; h < newTrainingData.trainingSet.size(); ++h) { //Go through every phrase
for (int i = 0; i < newTrainingData.trainingSet[h].elements.size(); ++i) { //...and every element
trainingExample tempExample;
tempExample.input = newTrainingData.trainingSet[h].elements[i].input;
if (newTrainingData.trainingSet[h].elements[i].output.size() > 0) {
tempExample.output = newTrainingData.trainingSet[h].elements[i].output;
} else {
std::unordered_map<std::string, int>::const_iterator mappedLabel = newTrainingData.labels.find(newTrainingData.trainingSet[h].label);
tempExample.output.push_back(double(mappedLabel->second));
}
trainingSet.push_back(tempExample);
}
}
};
template<>
bool machineLearning<classification>::train(const trainingData &newTrainingData) {
std::vector<trainingExample> trainingSet;
trainingData2rapidLib(newTrainingData, trainingSet);
return classification::train(trainingSet);
}
template<>
bool machineLearning<regression>::train(const trainingData &newTrainingData) {
std::vector<trainingExample> trainingSet;
trainingData2rapidLib(newTrainingData, trainingSet);
return regression::train(trainingSet);
}
RAPIDMIX_END_NAMESPACE
/*
* machineLearning.h
* Created by Michael Zbyszynski on 10 Jan 2016
* Copyright © 2017 Goldsmiths. All rights reserved.
*/
#ifndef machineLearning_h
#define machineLearning_h
#include "rapidMix.h"
#include "trainingData.h"
////////// Include all of the machine learning algorithms here
#include "classification.h"
#include "regression.h"
#include "rapidXmmTools.h"
#include "gvf.h"
RAPIDMIX_BEGIN_NAMESPACE
//* Host class for machine learning algorithms */
template <typename MachineLearningModule>
class machineLearning : public MachineLearningModule {
public:
//* Constructors */
machineLearning() : MachineLearningModule() {};
template<class T>
machineLearning(T type) : MachineLearningModule(type) {};
//* this function becomes specialized in the implementation */
bool train(const trainingData &newTrainingData);
// Could overload this, or specialize, or both
std::vector<double> run(const std::vector<double> &inputVector) {
return MachineLearningModule::process(inputVector);
}
bool reset() {
return MachineLearningModule::reset();
}
private:
MachineLearningModule module;
};
////////// typedefs for calling different algorithms
typedef machineLearning<classification> staticClassification;
typedef machineLearning<regression> staticRegression;
typedef xmmToolConfig xmmConfig;
typedef machineLearning<xmmGmmTool> xmmStaticClassification;
typedef machineLearning<xmmGmrTool> xmmStaticRegression;
typedef machineLearning<xmmHmmTool> xmmTemporalClassification;
typedef machineLearning<xmmHmrTool> xmmTemporalRegression;
typedef machineLearning<GVF> gvf;
RAPIDMIX_END_NAMESPACE
#endif
/*
* rapidmix.h
* Created by Michael Zbyszynski on 12 Jan 2017
* Copyright © 2017 Goldsmiths. All rights reserved.
*/
/////////////////////////////////////////////////////////////////////////////
// ______ _ _ ___ ____ ___ ______ _____ //
// | ___ \ (_) | | | \/ (_) / _ \ | ___ \_ _| //
......
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