umappp
A C++ library for UMAP
Loading...
Searching...
No Matches
Status.hpp
Go to the documentation of this file.
1#ifndef UMAPPP_STATUS_HPP
2#define UMAPPP_STATUS_HPP
3
4#include "Options.hpp"
5#include "optimize_layout.hpp"
6
7#include <random>
8#include <cstdint>
9
15namespace umappp {
16
24template<typename Index_, typename Float_>
25class Status {
26public:
30 Status(internal::EpochData<Index_, Float_> epochs, Options options, int num_dim, Float_* embedding) :
31 my_epochs(std::move(epochs)),
32 my_options(std::move(options)),
33 my_engine(my_options.seed),
34 my_num_dim(num_dim),
35 my_embedding(embedding)
36 {}
41private:
42 internal::EpochData<Index_, Float_> my_epochs;
43 Options my_options;
44 std::mt19937_64 my_engine;
45 int my_num_dim;
46 Float_* my_embedding;
47
48public:
52 // Only used for testing, specifically in comparison to uwot:::data2set.
53 const auto& get_epoch_data() const {
54 return my_epochs;
55 }
60public:
64 int num_dimensions() const {
65 return my_num_dim;
66 }
67
72 const Float_* embedding() const {
73 return my_embedding;
74 }
75
87 void set_embedding(Float_* ptr, bool copy = true) {
88 if (copy) {
89 size_t n = static_cast<size_t>(num_dimensions()) * num_observations(); // cast to avoid overflow.
90 std::copy_n(my_embedding, n, ptr);
91 }
92 my_embedding = ptr;
93 }
94
98 int epoch() const {
99 return my_epochs.current_epoch;
100 }
101
106 int num_epochs() const {
107 return my_epochs.total_epochs;
108 }
109
113 size_t num_observations() const {
114 return my_epochs.head.size();
115 }
116
117public:
126 void run(int epoch_limit = 0) {
127 if (epoch_limit == 0) {
128 epoch_limit = my_epochs.total_epochs;
129 }
130
131 if (my_options.num_threads == 1 || !my_options.parallel_optimization) {
132 internal::optimize_layout<Index_, Float_>(
133 my_num_dim,
134 my_embedding,
135 my_epochs,
136 my_options.a,
137 my_options.b,
138 my_options.repulsion_strength,
139 my_options.learning_rate,
140 my_engine,
142 );
143 } else {
144 internal::optimize_layout_parallel<Index_, Float_>(
145 my_num_dim,
146 my_embedding,
147 my_epochs,
148 my_options.a,
149 my_options.b,
150 my_options.repulsion_strength,
151 my_options.learning_rate,
152 my_engine,
154 my_options.num_threads
155 );
156 }
157 return;
158 }
159};
160
161}
162
163#endif
Options for the UMAP algorithm.
Status of the UMAP optimization iterations.
Definition Status.hpp:25
const Float_ * embedding() const
Definition Status.hpp:72
size_t num_observations() const
Definition Status.hpp:113
int epoch() const
Definition Status.hpp:98
void set_embedding(Float_ *ptr, bool copy=true)
Definition Status.hpp:87
int num_epochs() const
Definition Status.hpp:106
int num_dimensions() const
Definition Status.hpp:64
void run(int epoch_limit=0)
Definition Status.hpp:126
Methods for UMAP.
Definition initialize.hpp:21
Options for initialize().
Definition Options.hpp:28
double repulsion_strength
Definition Options.hpp:82
int parallel_optimization
Definition Options.hpp:149
double learning_rate
Definition Options.hpp:106
double b
Definition Options.hpp:76
double a
Definition Options.hpp:68
int num_threads
Definition Options.hpp:134