Program Listing for File Isomap.hpp
↰ Return to documentation for file (include\DimRedTools\Isomap.hpp
)
#ifndef DIMREDTOOLS_INCLUDE_DIMREDTOOLS_ISOMAP_HPP_
#define DIMREDTOOLS_INCLUDE_DIMREDTOOLS_ISOMAP_HPP_
#include "DimRedTools.hpp"
#include <optional>
#include <unordered_set>
namespace dim_red {
class Isomap {
public:
Isomap(std::optional<int> n_neighbors = 5, std::optional<double> radius = std::nullopt,
int n_components = 2, int max_iter = 100, double eps = 1e-4, double learning_rate = 0.2,
int random_state = 0, const std::string &neighbors_algorithm = "auto",
const std::string &metric = "euclidean");
~Isomap();
Matrix fitTransform(const Eigen::Ref<const Matrix> &x);
NearestNeighbors *nbrs_;
Matrix dist_matrix_;
private:
using Graph = std::vector<std::unordered_set<int>>;
Graph buildGraph(Eigen::Ref<const Matrix> x);
void dijkstra(const Graph &graph, int start, Eigen::Ref<Vector> distances) const;
void dijkstra(const Graph &graph);
int connectedComponents(const Graph &graph, Eigen::Ref<IntVector> labels) const;
void fixConnectedComponents(Eigen::Ref<const Matrix> x, int components,
Eigen::Ref<IntVector> labels, Graph *graph) const;
std::optional<int> n_neighbors_;
std::optional<double> radius_;
int n_components_;
int max_iter_;
double eps_;
double learning_rate_;
int random_state_;
std::string neighbors_algorithm_;
std::string metric_;
};
} // namespace dim_red
#endif // DIMREDTOOLS_INCLUDE_DIMREDTOOLS_ISOMAP_HPP_