TTK
Loading...
Searching...
No Matches
DimensionReduction.h
Go to the documentation of this file.
1
49
72
73#pragma once
74
75#include <Debug.h>
76#include <TopoMap.h>
78
79namespace ttk {
80
81 class DimensionReduction : virtual public Debug {
82
83 public:
85
87 enum class METHOD {
89 SE = 0,
91 LLE = 1,
93 MDS = 2,
95 T_SNE = 3,
97 ISOMAP = 4,
99 PCA = 5,
103 AE = 7,
104 };
105
106 inline void setSEParameters(const std::string &Affinity,
107 const float Gamma,
108 const std::string &EigenSolver,
109 const bool InputIsADistanceMatrix) {
110 if(InputIsADistanceMatrix) {
111 se_Affinity = "precomputed";
112 } else {
113 se_Affinity = Affinity;
114 }
115 se_Gamma = Gamma;
116 se_EigenSolver = EigenSolver;
117 }
118
119 inline void setLLEParameters(const float Regularization,
120 const std::string &EigenSolver,
121 const float Tolerance,
122 const int MaxIteration,
123 const std::string &Method_s,
124 const float HessianTolerance,
125 const float ModifiedTolerance,
126 const std::string &NeighborsAlgorithm) {
127 lle_Regularization = Regularization;
128 lle_EigenSolver = EigenSolver;
129 lle_Tolerance = Tolerance;
130 lle_MaxIteration = MaxIteration;
131 lle_Method = Method_s;
132 lle_HessianTolerance = HessianTolerance;
133 lle_ModifiedTolerance = ModifiedTolerance;
134 lle_NeighborsAlgorithm = NeighborsAlgorithm;
135 }
136
137 inline void setMDSParameters(const bool Metric,
138 const int Init,
139 const int MaxIteration,
140 const int Verbose,
141 const float Epsilon,
142 const bool Dissimilarity) {
143 mds_Metric = Metric;
144 mds_Init = Init;
145 mds_MaxIteration = MaxIteration;
146 mds_Verbose = Verbose;
147 mds_Epsilon = Epsilon;
148 if(Dissimilarity) {
149 mds_Dissimilarity = "precomputed";
150 } else {
151 mds_Dissimilarity = "euclidean";
152 }
153 }
154
155 inline void setTSNEParameters(const float Perplexity,
156 const float Exaggeration,
157 const float LearningRate,
158 const int MaxIteration,
159 const int MaxIterationProgress,
160 const float GradientThreshold,
161 const std::string &Metric,
162 const std::string &Init,
163 const int Verbose,
164 const std::string &Method_s,
165 const float Angle) {
166 tsne_Perplexity = Perplexity;
167 tsne_Exaggeration = Exaggeration;
168 tsne_LearningRate = LearningRate;
169 tsne_MaxIteration = MaxIteration;
170 tsne_MaxIterationProgress = MaxIterationProgress;
171 tsne_GradientThreshold = GradientThreshold;
172 tsne_Metric = Metric;
173 tsne_Init = Init;
174 tsne_Verbose = Verbose;
175 tsne_Method = Method_s;
176 tsne_Angle = Angle;
177 }
178
179 inline void setISOParameters(const std::string &EigenSolver,
180 const float Tolerance,
181 const int MaxIteration,
182 const std::string &PathMethod,
183 const std::string &NeighborsAlgorithm) {
184 iso_EigenSolver = EigenSolver;
185 iso_Tolerance = Tolerance;
186 iso_MaxIteration = MaxIteration;
187 iso_PathMethod = PathMethod;
188 iso_NeighborsAlgorithm = NeighborsAlgorithm;
189 }
190
191 inline void setPCAParameters(const bool Copy,
192 const bool Whiten,
193 const std::string &SVDSolver,
194 const float Tolerance,
195 const std::string &MaxIteration) {
196 pca_Copy = Copy;
197 pca_Whiten = Whiten;
198 pca_SVDSolver = SVDSolver;
199 pca_Tolerance = Tolerance;
200 pca_MaxIteration = MaxIteration;
201 }
202 inline void setTopoParameters(const size_t AngularSampleNb, bool CheckMST) {
203 topomap_AngularSampleNb = AngularSampleNb;
204 topomap_CheckMST = CheckMST;
205 }
206
207 inline void setInputModulePath(const std::string &modulePath) {
208 ModulePath = modulePath;
209 }
210
211 inline void setInputModuleName(const std::string &moduleName) {
212 ModuleName = moduleName;
213 }
214
215 inline void setInputFunctionName(const std::string &functionName) {
216 FunctionName = functionName;
217 }
218
219 inline void setInputMethod(METHOD method) {
220
221 this->Method = method;
222
223#ifndef TTK_ENABLE_SCIKIT_LEARN
224 if(this->Method != METHOD::TOPOMAP) {
225 this->printWrn("TTK has been built without scikit-learn.");
226 this->printWrn("Defaulting to the `TopoMap` backend.");
227 this->Method = METHOD::TOPOMAP;
228 }
229#endif
230
231 std::string methodName;
232 switch(this->Method) {
233 case METHOD::SE:
234 methodName = "Spectral Embedding";
235 break;
236 case METHOD::LLE:
237 methodName = "Locally Linear Embedding";
238 break;
239 case METHOD::MDS:
240 methodName = "Multi-Dimensional Scaling";
241 break;
242 case METHOD::T_SNE:
243 methodName = "t-distributed Stochastic Neighbor Embedding";
244 break;
245 case METHOD::ISOMAP:
246 methodName = "Isomap Embedding";
247 break;
248 case METHOD::PCA:
249 methodName = "Principal Component Analysis";
250 break;
251 case METHOD::TOPOMAP:
252 methodName = "TopoMap (IEEE VIS 2020)";
253 break;
254 case METHOD::AE:
255 methodName = "Autoencoder";
256 break;
257 }
258 this->printMsg("Using backend `" + methodName + "`");
259 }
260
261 inline void setInputNumberOfComponents(const int numberOfComponents) {
262 this->NumberOfComponents = numberOfComponents;
263 }
264
265 inline void setInputNumberOfNeighbors(const int numberOfNeighbors) {
266 this->NumberOfNeighbors = numberOfNeighbors;
267 }
268
269 inline void setInputIsDeterministic(const int isDeterm) {
270 this->IsDeterministic = isDeterm;
271 }
272
273 inline void setIsInputDistanceMatrix(const bool data) {
274 this->IsInputADistanceMatrix = data;
275 if(data) {
276 this->se_Affinity = "precomputed";
277 this->mds_Dissimilarity = "precomputed";
278 this->tsne_Metric = "precomputed";
279 this->iso_Metric = "precomputed";
280 } else {
281 this->se_Affinity = "nearest_neighbors";
282 this->mds_Dissimilarity = "euclidean";
283 this->tsne_Metric = "euclidean";
284 this->iso_Metric = "euclidean";
285 }
286 }
287
288 int execute(std::vector<std::vector<double>> &outputEmbedding,
289 const std::vector<double> &inputMatrix,
290 const int nRows,
291 const int nColumns,
292 int *insertionTimeForTopoMap = nullptr) const;
293
294 protected:
295 // se
296 std::string se_Affinity{"nearest_neighbors"};
297 float se_Gamma{1};
298 std::string se_EigenSolver{"None"};
299
300 // lle
302 std::string lle_EigenSolver{"auto"};
303 float lle_Tolerance{1e-3};
305 std::string lle_Method{"standard"};
308 std::string lle_NeighborsAlgorithm{"auto"};
309
310 // mds
311 bool mds_Metric{true};
312 int mds_Init{4};
315 float mds_Epsilon{0};
316 std::string mds_Dissimilarity{"euclidean"};
317
318 // tsne
325 std::string tsne_Metric{"euclidean"};
326 std::string tsne_Init{"random"};
328 std::string tsne_Method{"barnes_hut"};
329 float tsne_Angle{0.5};
330
331 // iso
332 std::string iso_EigenSolver{"auto"};
333 float iso_Tolerance{1e-3};
335 std::string iso_PathMethod{"auto"};
336 std::string iso_NeighborsAlgorithm{"auto"};
337 std::string iso_Metric{"euclidean"};
338
339 // pca
340 bool pca_Copy{true};
341 bool pca_Whiten{false};
342 std::string pca_SVDSolver{"auto"};
344 std::string pca_MaxIteration{"auto"};
345
346 // TopoMap
350
351 // AutoEncoder
352 bool ae_CUDA{true};
353 bool ae_Deterministic{false};
354 int ae_Seed{0};
355 int ae_Epochs{1000};
356 double ae_LearningRate{1e-2};
360 TopologicalDimensionReduction::REGUL::ASYMMETRIC_CASCADE};
363 std::string ae_Architecture{"32 32"};
364 std::string ae_Activation{"ReLU"};
367 double ae_RegCoefficient{1e-2};
368 bool ae_PreOptimize{false};
370
371 // testing
372 std::string ModulePath{"default"};
373 std::string ModuleName{"dimensionReduction"};
374 std::string FunctionName{"doIt"};
375
377
381 char majorVersion_{'0'};
383 bool IsInputImages{false};
384 };
385} // namespace ttk
int printWrn(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
Definition Debug.h:159
TopologicalDimensionReduction::REGUL ae_Method
void setInputIsDeterministic(const int isDeterm)
void setPCAParameters(const bool Copy, const bool Whiten, const std::string &SVDSolver, const float Tolerance, const std::string &MaxIteration)
TopologicalDimensionReduction::OPTIMIZER ae_Optimizer
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)
TopologicalDimensionReduction::MODEL ae_Model
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)
TTK base package defining the standard types.
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/| (_) |"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)