/
NeuralGasSuite.h
149 lines (126 loc) · 4.72 KB
/
NeuralGasSuite.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* This file is part of NeuralGas.
*
* NeuralGas is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* NeuralGas is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with NeuralGas. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file NeuralGasSuite.h
* \author Manuel Noll
* \author Sergio Roa
*
* Copyright(c) 2010 Manuel Noll - All rights reserved
* \version 1.0
* \date 2010
*/
#ifndef NEURALGASSUITE_H
#define NEURALGASSUITE_H
#include <vector>
#include "DataGenerator/DataGenerator.h"
#include "GrowingNeuralGas/GNGModul.h"
#include "GrowingNeuralGas/Testing/ErrorTesting.h"
#include "GrowingNeuralGas/MergeGrowingNeuralGas/MGNGAlgorithm.h"
#include "tools/math_helpers.h"
namespace neuralgas {
//! \class NeuralGasSuite
/*! \brief The class allows running experiments with multiple GNG implementations
*/
template <typename T,typename S> class NeuralGasSuite
{
public:
NeuralGasSuite();
~NeuralGasSuite();
void setRefVectors(const int&);
void add(GNGModul<T,S>*);
void rm(GNGModul<T,S>*);
void rm(const int&);
void setDataGenerator(DataGenerator<T>*);
void setData();
void run();
std::vector<T> getErrors(const int&,const int&, const bool&);
std::vector<T> getErrors(GNGModul<T,S>*,const int&, const bool& );
GNGModul<T,S>* operator[](const int& index){return _algos[index];}
const GNGModul<T,S>* operator[](const int& index) const{return _algos[index];}
const int size() const;
private:
DataGenerator<T>* _dg;
ErrorTesting<T,S>* _et;
std::vector<GNGModul<T,S> *> _algos;
};
template <typename T,typename S> NeuralGasSuite<T,S>::NeuralGasSuite()
{
_et = new ErrorTesting<T,S>;
}
template <typename T,typename S> NeuralGasSuite<T,S>::~NeuralGasSuite()
{
delete _et;
}
template <typename T,typename S> const int NeuralGasSuite<T,S>::size() const
{
return _algos.size();
}
template <typename T,typename S> void NeuralGasSuite<T,S>::add(GNGModul<T,S>* algo)
{_algos.push_back(algo);}
template <typename T,typename S> void NeuralGasSuite<T,S>::rm(GNGModul<T,S>* algo)
{
for (int i=0; i <_algos.size();i++)
if ( *(_algos[i]) == *algo )
{
_algos.erase(_algos.begin() + i);
return;
}
}
template <typename T,typename S> void NeuralGasSuite<T,S>::rm(const int& index)
{_algos.erase(_algos.begin() + index);}
template <typename T,typename S> void NeuralGasSuite<T,S>::setDataGenerator(DataGenerator<T>* dg)
{
_dg=dg;
}
template <typename T,typename S> void NeuralGasSuite<T,S>::setData()
{
for (unsigned int i=0; i <_algos.size();i++)
_algos[i]->setData(_dg->getData());
}
template <typename T,typename S> void NeuralGasSuite<T,S>::run()
{
for (unsigned int i=0; i <_algos.size();i++)
{
std::cout << "Starting run "<<i <<std::endl;
_algos[i]->run();
std::cout << "Run "<<i <<" done"<<std::endl;
}
}
template <typename T,typename S> std::vector<T> NeuralGasSuite<T,S>::getErrors(GNGModul<T,S>* algo,const int& pastTimeSteps, const bool& random )
{
for (int i=0; i <_algos.size();i++)
if ( *(_algos[i]) == *algo )
{
_et->setGNGObject(_algos[i]);
break;
}
return _et->getErrors(pastTimeSteps,random);
}
template <typename T,typename S> std::vector<T> NeuralGasSuite<T,S>::getErrors(const int& num_of_algo,const int& pastTimeSteps, const bool& random )
{
_et->setGNGObject(_algos[num_of_algo]);
return _et->getErrors(pastTimeSteps,random);
}
template <typename T,typename S> void NeuralGasSuite<T,S>::setRefVectors(const int& number)
{
for (unsigned int i=0; i <_algos.size();i++)
{
assert (_algos[i]->size());
_algos[i]->setRefVectors(number);
}
}
} // namespace neuralgas
#endif