Commit 50fefa87 authored by mzed's avatar mzed
Browse files

Merge branch 'dev'

parents 349e7c3e 4828e8fa
......@@ -10,7 +10,8 @@
#include <vector>
#include <cmath>
#include <cassert>
#include "dtw.h"
#include <limits>
#include "dtw.h"
template<typename T>
dtw<T>::dtw() {};
......
......@@ -6,7 +6,7 @@
// Copyright © 2016 Goldsmiths. All rights reserved.
//
#include <cmath>
#include <math.h>
#include <utility>
#include <map>
#include <vector>
......@@ -86,7 +86,7 @@ T knnClassification<T>::run(const std::vector<T> &inputVector) {
for (int i = 0; i < currentK; ++i) {
nearestNeighbours[i] = {0, 0.};
};
std::pair<int, T> farthestNN = {0, 0.};
std::pair<int, T> farthestNN {0, 0.};
std::vector<T> pattern;
for (int h = 0; h < numInputs; h++) {
......@@ -95,7 +95,7 @@ T knnClassification<T>::run(const std::vector<T> &inputVector) {
//Find k nearest neighbours
int index = 0;
for (typename std::vector<trainingExampleTemplate<T> >::iterator it = neighbours.begin(); it != neighbours.end(); ++it) {
for (auto it = neighbours.cbegin(); it != neighbours.cend(); ++it) {
//find Euclidian distance for this neighbor
T euclidianDistance = 0;
for(int j = 0; j < numInputs ; ++j){
......@@ -126,20 +126,18 @@ T knnClassification<T>::run(const std::vector<T> &inputVector) {
//majority vote on nearest neighbours
std::map<int, int> classVoteMap;
typedef std::pair<int, int> classVotePair;
for (int i = 0; i < currentK; ++i){
int classNum = (int) std::round(neighbours[nearestNeighbours[i].first].output[0]);
using classVotePair = std::pair<int, int>;
for (int i = 0; i < currentK; ++i) {
int classNum = (int) round(neighbours[nearestNeighbours[i].first].output[0]);
if ( classVoteMap.find(classNum) == classVoteMap.end() ) {
classVoteMap.insert(classVotePair(classNum, 1));
} else {
classVoteMap[classNum]++;
++classVoteMap[classNum];
}
}
T foundClass = 0;
int mostVotes = 0;
std::map<int, int>::iterator p;
for(p = classVoteMap.begin(); p != classVoteMap.end(); ++p)
{
for (auto p = classVoteMap.cbegin(); p != classVoteMap.cend(); ++p) {
if (p->second > mostVotes) {
mostVotes = p->second;
foundClass = p->first;
......@@ -156,7 +154,7 @@ void knnClassification<T>::getJSONDescription(Json::Value &jsonModelDescription)
jsonModelDescription["whichInputs"] = this->vector2json(whichInputs);
jsonModelDescription["k"] = desiredK;
Json::Value examples;
for (typename std::vector<trainingExampleTemplate<T> >::iterator it = neighbours.begin(); it != neighbours.end(); ++it) {
for (auto it = neighbours.cbegin(); it != neighbours.cend(); ++it) {
Json::Value oneExample;
oneExample["class"] = it->output[0];
oneExample["features"] = this->vector2json(it->input);
......
......@@ -29,7 +29,7 @@ numOutputs(-1)
template<typename T>
modelSet<T>::~modelSet() {
for (typename std::vector<baseModel<T>*>::iterator i = myModelSet.begin(); i != myModelSet.end(); ++i) {
for (typename std::vector<baseModel<T>*>::const_iterator i = myModelSet.cbegin(); i != myModelSet.cend(); ++i) {
delete *i;
}
};
......@@ -64,7 +64,7 @@ bool modelSet<T>::train(const std::vector<trainingExampleTemplate<T> > &training
template<typename T>
bool modelSet<T>::reset() {
for (typename std::vector<baseModel<T>*>::iterator i = myModelSet.begin(); i != myModelSet.end(); ++i) {
for (typename std::vector<baseModel<T>*>::const_iterator i = myModelSet.cbegin(); i != myModelSet.cend(); ++i) {
delete *i;
}
myModelSet.clear();
......
......@@ -6,6 +6,7 @@
* @copyright Copyright © 2017 Goldsmiths. All rights reserved.
*/
#include <limits>
#include "searchWindow.h"
template<typename T>
......
......@@ -9,6 +9,8 @@
#include <vector>
#include <cassert>
#include <limits>
#include <algorithm>
#include "seriesClassification.h"
#ifdef EMSCRIPTEN
#include "emscripten/seriesClassificationEmbindings.h"
......@@ -163,7 +165,7 @@ int seriesClassificationTemplate<T>::getMaxLength(std::string label) const {
}
template<typename T>
seriesClassificationTemplate<T>::minMax<T> seriesClassificationTemplate<T>::calculateCosts(std::string label) const {
typename seriesClassificationTemplate<T>::template minMax<T> seriesClassificationTemplate<T>::calculateCosts(std::string label) const {
minMax<T> calculatedMinMax;
bool foundSeries = false;
std::vector<T> labelCosts;
......@@ -188,7 +190,7 @@ seriesClassificationTemplate<T>::minMax<T> seriesClassificationTemplate<T>::calc
}
template<typename T>
seriesClassificationTemplate<T>::minMax<T> seriesClassificationTemplate<T>::calculateCosts(std::string label1, std::string label2) const {
typename seriesClassificationTemplate<T>::template minMax<T> seriesClassificationTemplate<T>::calculateCosts(std::string label1, std::string label2) const {
minMax<T> calculatedMinMax;
bool foundSeries = false;
std::vector<T> labelCosts;
......
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