TTK
Loading...
Searching...
No Matches
DimensionReduction.h
Go to the documentation of this file.
1
46
52
53#pragma once
54
55#include <Debug.h>
56#include <TopoMap.h>
57
58namespace ttk {
59
60 class DimensionReduction : virtual public Debug {
61
62 public:
64
66 enum class METHOD {
68 SE = 0,
70 LLE = 1,
72 MDS = 2,
74 T_SNE = 3,
76 ISOMAP = 4,
78 PCA = 5,
80 TOPOMAP = 6,
81 };
82
83 inline void setSEParameters(const std::string &Affinity,
84 const float Gamma,
85 const std::string &EigenSolver,
86 const bool InputIsADistanceMatrix) {
87 if(InputIsADistanceMatrix) {
88 se_Affinity = "precomputed";
89 } else {
90 se_Affinity = Affinity;
91 }
92 se_Gamma = Gamma;
93 se_EigenSolver = EigenSolver;
94 }
95
96 inline void setLLEParameters(const float Regularization,
97 const std::string &EigenSolver,
98 const float Tolerance,
99 const int MaxIteration,
100 const std::string &Method_s,
101 const float HessianTolerance,
102 const float ModifiedTolerance,
103 const std::string &NeighborsAlgorithm) {
104 lle_Regularization = Regularization;
105 lle_EigenSolver = EigenSolver;
106 lle_Tolerance = Tolerance;
107 lle_MaxIteration = MaxIteration;
108 lle_Method = Method_s;
109 lle_HessianTolerance = HessianTolerance;
110 lle_ModifiedTolerance = ModifiedTolerance;
111 lle_NeighborsAlgorithm = NeighborsAlgorithm;
112 }
113
114 inline void setMDSParameters(const bool Metric,
115 const int Init,
116 const int MaxIteration,
117 const int Verbose,
118 const float Epsilon,
119 const bool Dissimilarity) {
120 mds_Metric = Metric;
121 mds_Init = Init;
122 mds_MaxIteration = MaxIteration;
123 mds_Verbose = Verbose;
124 mds_Epsilon = Epsilon;
125 if(Dissimilarity) {
126 mds_Dissimilarity = "precomputed";
127 } else {
128 mds_Dissimilarity = "euclidean";
129 }
130 }
131
132 inline void setTSNEParameters(const float Perplexity,
133 const float Exaggeration,
134 const float LearningRate,
135 const int MaxIteration,
136 const int MaxIterationProgress,
137 const float GradientThreshold,
138 const std::string &Metric,
139 const std::string &Init,
140 const int Verbose,
141 const std::string &Method_s,
142 const float Angle) {
143 tsne_Perplexity = Perplexity;
144 tsne_Exaggeration = Exaggeration;
145 tsne_LearningRate = LearningRate;
146 tsne_MaxIteration = MaxIteration;
147 tsne_MaxIterationProgress = MaxIterationProgress;
148 tsne_GradientThreshold = GradientThreshold;
149 tsne_Metric = Metric;
150 tsne_Init = Init;
151 tsne_Verbose = Verbose;
152 tsne_Method = Method_s;
153 tsne_Angle = Angle;
154 }
155
156 inline void setISOParameters(const std::string &EigenSolver,
157 const float Tolerance,
158 const int MaxIteration,
159 const std::string &PathMethod,
160 const std::string &NeighborsAlgorithm) {
161 iso_EigenSolver = EigenSolver;
162 iso_Tolerance = Tolerance;
163 iso_MaxIteration = MaxIteration;
164 iso_PathMethod = PathMethod;
165 iso_NeighborsAlgorithm = NeighborsAlgorithm;
166 }
167
168 inline void setPCAParameters(const bool Copy,
169 const bool Whiten,
170 const std::string &SVDSolver,
171 const float Tolerance,
172 const std::string &MaxIteration) {
173 pca_Copy = Copy;
174 pca_Whiten = Whiten;
175 pca_SVDSolver = SVDSolver;
176 pca_Tolerance = Tolerance;
177 pca_MaxIteration = MaxIteration;
178 }
179 inline void setTopoParameters(const size_t AngularSampleNb, bool CheckMST) {
180 topomap_AngularSampleNb = AngularSampleNb;
181 topomap_CheckMST = CheckMST;
182 }
183
184 inline void setInputModulePath(const std::string &modulePath) {
185 ModulePath = modulePath;
186 }
187
188 inline void setInputModuleName(const std::string &moduleName) {
189 ModuleName = moduleName;
190 }
191
192 inline void setInputFunctionName(const std::string &functionName) {
193 FunctionName = functionName;
194 }
195
196 inline void setInputMethod(METHOD method) {
197
198 this->Method = method;
199
200#ifndef TTK_ENABLE_SCIKIT_LEARN
201 if(this->Method != METHOD::TOPOMAP) {
202 this->printWrn("TTK has been built without scikit-learn.");
203 this->printWrn("Defaulting to the `TopoMap` backend.");
204 this->Method = METHOD::TOPOMAP;
205 }
206#endif
207
208 std::string methodName;
209 switch(this->Method) {
210 case METHOD::SE:
211 methodName = "Spectral Embedding";
212 break;
213 case METHOD::LLE:
214 methodName = "Locally Linear Embedding";
215 break;
216 case METHOD::MDS:
217 methodName = "Multi-Dimensional Scaling";
218 break;
219 case METHOD::T_SNE:
220 methodName = "t-distributed Stochastic Neighbor Embedding";
221 break;
222 case METHOD::ISOMAP:
223 methodName = "Isomap Embedding";
224 break;
225 case METHOD::PCA:
226 methodName = "Principal Component Analysis";
227 break;
228 case METHOD::TOPOMAP:
229 methodName = "TopoMap (IEEE VIS 2020)";
230 break;
231 }
232 this->printMsg("Using backend `" + methodName + "`");
233 }
234
235 inline void setInputNumberOfComponents(const int numberOfComponents) {
236 this->NumberOfComponents = numberOfComponents;
237 }
238
239 inline void setInputNumberOfNeighbors(const int numberOfNeighbors) {
240 this->NumberOfNeighbors = numberOfNeighbors;
241 }
242
243 inline void setInputIsDeterministic(const int isDeterm) {
244 this->IsDeterministic = isDeterm;
245 }
246
247 inline void setIsInputDistanceMatrix(const bool data) {
248 this->IsInputADistanceMatrix = data;
249 if(data) {
250 this->se_Affinity = "precomputed";
251 this->mds_Dissimilarity = "precomputed";
252 this->tsne_Metric = "precomputed";
253 this->iso_Metric = "precomputed";
254 } else {
255 this->se_Affinity = "nearest_neighbors";
256 this->mds_Dissimilarity = "euclidean";
257 this->tsne_Metric = "euclidean";
258 this->iso_Metric = "euclidean";
259 }
260 }
261
262 int execute(std::vector<std::vector<double>> &outputEmbedding,
263 const std::vector<double> &inputMatrix,
264 const int nRows,
265 const int nColumns,
266 int *insertionTimeForTopoMap = nullptr) const;
267
268 protected:
269 // se
270 std::string se_Affinity{"nearest_neighbors"};
271 float se_Gamma{1};
272 std::string se_EigenSolver{"None"};
273
274 // lle
276 std::string lle_EigenSolver{"auto"};
277 float lle_Tolerance{1e-3};
279 std::string lle_Method{"standard"};
282 std::string lle_NeighborsAlgorithm{"auto"};
283
284 // mds
285 bool mds_Metric{true};
286 int mds_Init{4};
289 float mds_Epsilon{0};
290 std::string mds_Dissimilarity{"euclidean"};
291
292 // tsne
299 std::string tsne_Metric{"euclidean"};
300 std::string tsne_Init{"random"};
302 std::string tsne_Method{"barnes_hut"};
303 float tsne_Angle{0.5};
304
305 // iso
306 std::string iso_EigenSolver{"auto"};
307 float iso_Tolerance{1e-3};
309 std::string iso_PathMethod{"auto"};
310 std::string iso_NeighborsAlgorithm{"auto"};
311 std::string iso_Metric{"euclidean"};
312
313 // pca
314 bool pca_Copy{true};
315 bool pca_Whiten{false};
316 std::string pca_SVDSolver{"auto"};
318 std::string pca_MaxIteration{"auto"};
319
320 // TopoMap
324
325 // testing
326 std::string ModulePath{"default"};
327 std::string ModuleName{"dimensionReduction"};
328 std::string FunctionName{"doIt"};
329
331
335 char majorVersion_{'0'};
337 };
338} // namespace ttk
Minimalist debugging class.
Definition Debug.h:88
int printWrn(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
Definition Debug.h:159
TTK VTK-filter that apply dimension reduction algorithms on input.
void setInputIsDeterministic(const int isDeterm)
void setPCAParameters(const bool Copy, const bool Whiten, const std::string &SVDSolver, const float Tolerance, const std::string &MaxIteration)
void setInputNumberOfNeighbors(const int numberOfNeighbors)
TopoMap::STRATEGY topomap_Strategy
void setInputModuleName(const std::string &moduleName)
void setIsInputDistanceMatrix(const bool data)
void setTSNEParameters(const float Perplexity, const float Exaggeration, const float LearningRate, const int MaxIteration, const int MaxIterationProgress, const float GradientThreshold, const std::string &Metric, const std::string &Init, const int Verbose, const std::string &Method_s, const float Angle)
void setLLEParameters(const float Regularization, const std::string &EigenSolver, const float Tolerance, const int MaxIteration, const std::string &Method_s, const float HessianTolerance, const float ModifiedTolerance, const std::string &NeighborsAlgorithm)
void setISOParameters(const std::string &EigenSolver, const float Tolerance, const int MaxIteration, const std::string &PathMethod, const std::string &NeighborsAlgorithm)
void setSEParameters(const std::string &Affinity, const float Gamma, const std::string &EigenSolver, const bool InputIsADistanceMatrix)
void setInputMethod(METHOD method)
void setInputFunctionName(const std::string &functionName)
void setTopoParameters(const size_t AngularSampleNb, bool CheckMST)
void setMDSParameters(const bool Metric, const int Init, const int MaxIteration, const int Verbose, const float Epsilon, const bool Dissimilarity)
void setInputModulePath(const std::string &modulePath)
int execute(std::vector< std::vector< double > > &outputEmbedding, const std::vector< double > &inputMatrix, const int nRows, const int nColumns, int *insertionTimeForTopoMap=nullptr) const
void setInputNumberOfComponents(const int numberOfComponents)
The Topology ToolKit.
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)