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