Skip to content

Commit ec754e0

Browse files
committed
[topoAEpp] unwrap TCDR class name
1 parent 2ae27cd commit ec754e0

File tree

5 files changed

+96
-72
lines changed

5 files changed

+96
-72
lines changed

core/base/dimensionReduction/DimensionReduction.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ int DimensionReduction::execute(
7777

7878
if(this->Method == METHOD::AE) {
7979
#ifdef TTK_ENABLE_TORCH
80-
TCDR tcdr(ae_CUDA, ae_Deterministic, ae_Seed, NumberOfComponents, ae_Epochs,
81-
ae_LearningRate, ae_Optimizer, ae_Method, ae_Model,
82-
ae_Architecture, ae_Activation, ae_BatchSize,
83-
ae_BatchNormalization, ae_RegCoefficient, IsInputImages);
80+
TopologicallyConstrainedDimensionalityReduction tcdr(
81+
ae_CUDA, ae_Deterministic, ae_Seed, NumberOfComponents, ae_Epochs,
82+
ae_LearningRate, ae_Optimizer, ae_Method, ae_Model, ae_Architecture,
83+
ae_Activation, ae_BatchSize, ae_BatchNormalization, ae_RegCoefficient,
84+
IsInputImages);
8485
tcdr.setDebugLevel(debugLevel_);
8586
tcdr.setThreadNumber(threadNumber_);
8687

core/base/dimensionReduction/DimensionReduction.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/// href="https://topology-tool-kit.github.io/examples/persistentGenerators_periodicPicture/">Persistent
4141
/// Generators Periodic Picture example</a> \n
4242
/// - <a
43-
/// href="https://topology-tool-kit.github.io/examples/topoAEppTeaser/">Topological
43+
/// href="https://topology-tool-kit.github.io/examples/topoAEppTeaser/">Topological
4444
/// Autoencoders++ Teaser example</a> \n
4545
/// - <a
4646
/// href="https://topology-tool-kit.github.io/examples/topoMapTeaser/">TopoMap
@@ -353,9 +353,13 @@ namespace ttk {
353353
int ae_Seed{0};
354354
int ae_Epochs{1000};
355355
double ae_LearningRate{1e-2};
356-
TCDR::OPTIMIZER ae_Optimizer{TCDR::OPTIMIZER::ADAM};
357-
TCDR::REGUL ae_Method{TCDR::REGUL::ASYMMETRIC_CASCADE};
358-
TCDR::MODEL ae_Model{TCDR::MODEL::AUTOENCODER};
356+
TopologicallyConstrainedDimensionalityReduction::OPTIMIZER ae_Optimizer{
357+
TopologicallyConstrainedDimensionalityReduction::OPTIMIZER::ADAM};
358+
TopologicallyConstrainedDimensionalityReduction::REGUL ae_Method{
359+
TopologicallyConstrainedDimensionalityReduction::REGUL::
360+
ASYMMETRIC_CASCADE};
361+
TopologicallyConstrainedDimensionalityReduction::MODEL ae_Model{
362+
TopologicallyConstrainedDimensionalityReduction::MODEL::AUTOENCODER};
359363
std::string ae_Architecture{"32 32"};
360364
std::string ae_Activation{"ReLU"};
361365
int ae_BatchSize{0};

core/base/topologicallyConstrainedDimensionReduction/TopologicallyConstrainedDimensionReduction.cpp

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,30 @@
44

55
using namespace torch::indexing;
66

7-
ttk::TCDR::TCDR(bool useCUDA,
8-
bool deterministic,
9-
int seed,
10-
int numberOfComponents,
11-
int epochs,
12-
double learningRate,
13-
OPTIMIZER optimizer,
14-
REGUL method,
15-
MODEL modelType,
16-
const std::string &architecture,
17-
const std::string &activation,
18-
int batchSize,
19-
bool batchNormalization,
20-
double regCoefficient,
21-
bool inputIsImages)
7+
ttk::TopologicallyConstrainedDimensionalityReduction::
8+
TopologicallyConstrainedDimensionalityReduction(
9+
bool useCUDA,
10+
bool deterministic,
11+
int seed,
12+
int numberOfComponents,
13+
int epochs,
14+
double learningRate,
15+
OPTIMIZER optimizer,
16+
REGUL method,
17+
MODEL modelType,
18+
const std::string &architecture,
19+
const std::string &activation,
20+
int batchSize,
21+
bool batchNormalization,
22+
double regCoefficient,
23+
bool inputIsImages)
2224
: NumberOfComponents(numberOfComponents), Epochs(epochs),
2325
LearningRate(learningRate), Optimizer(optimizer), Method(method),
2426
ModelType(modelType), InputIsImages(inputIsImages),
2527
Architecture(architecture), Activation(activation), BatchSize(batchSize),
2628
BatchNormalization(batchNormalization), RegCoefficient(regCoefficient) {
2729
// inherited from Debug: prefix will be printed at the beginning of every msg
28-
this->setDebugMsgPrefix("TCDR");
30+
this->setDebugMsgPrefix("TopologicallyConstrainedDimensionalityReduction");
2931

3032
if(torch::cuda::is_available() && useCUDA && !deterministic)
3133
device = torch::kCUDA;
@@ -40,7 +42,8 @@ ttk::TCDR::TCDR(bool useCUDA,
4042
}
4143
}
4244

43-
int ttk::TCDR::initializeModel(int inputSize, int inputDimension) {
45+
int ttk::TopologicallyConstrainedDimensionalityReduction::initializeModel(
46+
int inputSize, int inputDimension) {
4447
if((!InputIsImages && !AutoEncoder::isStringValid(Architecture))
4548
|| (InputIsImages
4649
&& !ConvolutionalAutoEncoder::isStringValid(Architecture))) {
@@ -66,7 +69,8 @@ int ttk::TCDR::initializeModel(int inputSize, int inputDimension) {
6669
return 0;
6770
}
6871

69-
void ttk::TCDR::initializeOptimizer() {
72+
void ttk::TopologicallyConstrainedDimensionalityReduction::
73+
initializeOptimizer() {
7074
if(Optimizer == OPTIMIZER::ADAM)
7175
torchOptimizer = std::make_unique<torch::optim::Adam>(
7276
model->parameters(), /*lr=*/LearningRate);
@@ -78,9 +82,10 @@ void ttk::TCDR::initializeOptimizer() {
7882
model->parameters(), /*lr=*/LearningRate);
7983
}
8084

81-
int ttk::TCDR::execute(std::vector<std::vector<double>> &outputEmbedding,
82-
const std::vector<double> &inputMatrix,
83-
size_t n) {
85+
int ttk::TopologicallyConstrainedDimensionalityReduction::execute(
86+
std::vector<std::vector<double>> &outputEmbedding,
87+
const std::vector<double> &inputMatrix,
88+
size_t n) {
8489
Timer tm{};
8590
printMsg("Initialization", 0., tm.getElapsedTime());
8691

@@ -145,8 +150,9 @@ int ttk::TCDR::execute(std::vector<std::vector<double>> &outputEmbedding,
145150
return 0;
146151
}
147152

148-
void ttk::TCDR::setLatentInitialization(
149-
std::vector<std::vector<double>> const &latentInitialization) {
153+
void ttk::TopologicallyConstrainedDimensionalityReduction::
154+
setLatentInitialization(
155+
std::vector<std::vector<double>> const &latentInitialization) {
150156
std::vector<torch::Tensor> tensors;
151157
for(auto const &column : latentInitialization)
152158
tensors.push_back(torch::from_blob(const_cast<double *>(column.data()),
@@ -157,7 +163,8 @@ void ttk::TCDR::setLatentInitialization(
157163
latentInitialization_ = torch::stack(tensors).transpose(0, 1);
158164
}
159165

160-
void ttk::TCDR::optimizeSimple(const torch::Tensor &input) const {
166+
void ttk::TopologicallyConstrainedDimensionalityReduction::optimizeSimple(
167+
const torch::Tensor &input) const {
161168
int epoch = 0;
162169

163170
auto closure = [&] {
@@ -185,7 +192,8 @@ void ttk::TCDR::optimizeSimple(const torch::Tensor &input) const {
185192
torchOptimizer->step(closure);
186193
}
187194

188-
void ttk::TCDR::optimize(const torch::Tensor &input) const {
195+
void ttk::TopologicallyConstrainedDimensionalityReduction::optimize(
196+
const torch::Tensor &input) const {
189197
int epoch = 0;
190198

191199
auto closure = [&] {
@@ -211,8 +219,8 @@ void ttk::TCDR::optimize(const torch::Tensor &input) const {
211219
torchOptimizer->step(closure);
212220
}
213221

214-
void ttk::TCDR::preOptimize(const torch::Tensor &input,
215-
const torch::Tensor &target) const {
222+
void ttk::TopologicallyConstrainedDimensionalityReduction::preOptimize(
223+
const torch::Tensor &input, const torch::Tensor &target) const {
216224
int epoch = 0;
217225

218226
auto closure = [&] {
@@ -236,11 +244,12 @@ void ttk::TCDR::preOptimize(const torch::Tensor &input,
236244
torchOptimizer->step(closure);
237245
}
238246

239-
void ttk::TCDR::printLoss(int epoch, double loss) const {
247+
void ttk::TopologicallyConstrainedDimensionalityReduction::printLoss(
248+
int epoch, double loss) const {
240249
if(epoch % std::max(1, Epochs / 10) == 0)
241250
printMsg(
242251
"Loss at epoch " + std::to_string(epoch) + " : " + std::to_string(loss),
243252
double(epoch) / Epochs, -1, -1, debug::LineMode::REPLACE);
244253
}
245254

246-
#endif
255+
#endif

core/base/topologicallyConstrainedDimensionReduction/TopologicallyConstrainedDimensionReduction.h

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
/// \ingroup base
2-
/// \class ttk::TCDR
2+
/// \class ttk::TopologicallyConstrainedDimensionalityReduction
33
/// \author Mattéo Clémot <[email protected]>
44
/// \date 2024.
55
///
66
/// \brief TTK base class that embeds points into 2D, under topological
77
/// constraints
88
///
9-
/// This module defines the %TCDR class that serves as a backend for the
10-
/// DimensionReduction module. It embeds high-dimensional point clouds into 2D,
11-
/// under topological constraints, with an autoencoder-based approach.
9+
/// This module defines the %TopologicallyConstrainedDimensionalityReduction
10+
/// class that serves as a backend for the DimensionReduction module. It embeds
11+
/// high-dimensional point clouds into 2D, under topological constraints, with
12+
/// an autoencoder-based approach.
1213
///
1314
/// \b Online \b examples: \n
1415
/// - <a
15-
/// href="https://topology-tool-kit.github.io/examples/topoAEppTeaser/">Topological
16+
/// href="https://topology-tool-kit.github.io/examples/topoAEppTeaser/">Topological
1617
/// Autoencoders++ Teaser example</a> \n
1718
///
1819
/// \b Related \b publications \n
@@ -45,12 +46,12 @@
4546
namespace ttk {
4647

4748
/**
48-
* The TCDR class provides a backend for dimension reduction using
49-
* autoencoders, with possible constraints on the preservation of the
50-
* topology of the input high dimensional point cloud when projecting in low
51-
* dimension
49+
* The TopologicallyConstrainedDimensionalityReduction class provides a
50+
* backend for dimension reduction using autoencoders, with possible
51+
* constraints on the preservation of the topology of the input high
52+
* dimensional point cloud when projecting in low dimension
5253
*/
53-
class TCDR : virtual public Debug {
54+
class TopologicallyConstrainedDimensionalityReduction : virtual public Debug {
5455

5556
public:
5657
enum class OPTIMIZER : std::uint8_t {
@@ -75,21 +76,22 @@ namespace ttk {
7576

7677
#ifdef TTK_ENABLE_TORCH
7778

78-
TCDR(bool useCUDA,
79-
bool deterministic,
80-
int seed,
81-
int numberOfComponents,
82-
int epochs,
83-
double learningRate,
84-
OPTIMIZER optimizer,
85-
REGUL method,
86-
MODEL modelType,
87-
const std::string &architecture,
88-
const std::string &activation,
89-
int batchSize,
90-
bool batchNormalization,
91-
double regCoefficient,
92-
bool inputIsImages);
79+
TopologicallyConstrainedDimensionalityReduction(
80+
bool useCUDA,
81+
bool deterministic,
82+
int seed,
83+
int numberOfComponents,
84+
int epochs,
85+
double learningRate,
86+
OPTIMIZER optimizer,
87+
REGUL method,
88+
MODEL modelType,
89+
const std::string &architecture,
90+
const std::string &activation,
91+
int batchSize,
92+
bool batchNormalization,
93+
double regCoefficient,
94+
bool inputIsImages);
9395

9496
/**
9597
* @brief Computes the projection with an AutoEncoder
@@ -143,6 +145,6 @@ namespace ttk {
143145

144146
#endif
145147

146-
}; // TCDR class
148+
}; // TopologicallyConstrainedDimensionalityReduction class
147149

148150
} // namespace ttk

core/vtk/ttkDimensionReduction/ttkDimensionReduction.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
/// href="https://topology-tool-kit.github.io/examples/persistentGenerators_periodicPicture/">Persistent
4646
/// Generators Periodic Picture example</a> \n
4747
/// - <a
48-
/// href="https://topology-tool-kit.github.io/examples/topoAEppTeaser/">Topological
48+
/// href="https://topology-tool-kit.github.io/examples/topoAEppTeaser/">Topological
4949
/// Autoencoders++ Teaser example</a> \n
5050
/// - <a
5151
/// href="https://topology-tool-kit.github.io/examples/topoMapTeaser/">TopoMap
@@ -280,14 +280,22 @@ class TTKDIMENSIONREDUCTION_EXPORT ttkDimensionReduction
280280
vtkSetMacro(ae_LearningRate, double);
281281
vtkGetMacro(ae_LearningRate, double);
282282

283-
ttkSetEnumMacro(ae_Method, ttk::TCDR::REGUL);
284-
vtkGetEnumMacro(ae_Method, ttk::TCDR::REGUL);
285-
286-
ttkSetEnumMacro(ae_Optimizer, ttk::TCDR::OPTIMIZER);
287-
vtkGetEnumMacro(ae_Optimizer, ttk::TCDR::OPTIMIZER);
288-
289-
ttkSetEnumMacro(ae_Model, ttk::TCDR::MODEL);
290-
vtkGetEnumMacro(ae_Model, ttk::TCDR::MODEL);
283+
ttkSetEnumMacro(ae_Method,
284+
ttk::TopologicallyConstrainedDimensionalityReduction::REGUL);
285+
vtkGetEnumMacro(ae_Method,
286+
ttk::TopologicallyConstrainedDimensionalityReduction::REGUL);
287+
288+
ttkSetEnumMacro(
289+
ae_Optimizer,
290+
ttk::TopologicallyConstrainedDimensionalityReduction::OPTIMIZER);
291+
vtkGetEnumMacro(
292+
ae_Optimizer,
293+
ttk::TopologicallyConstrainedDimensionalityReduction::OPTIMIZER);
294+
295+
ttkSetEnumMacro(ae_Model,
296+
ttk::TopologicallyConstrainedDimensionalityReduction::MODEL);
297+
vtkGetEnumMacro(ae_Model,
298+
ttk::TopologicallyConstrainedDimensionalityReduction::MODEL);
291299

292300
vtkSetMacro(ae_Architecture, const std::string &);
293301
vtkGetMacro(ae_Architecture, std::string);

0 commit comments

Comments
 (0)