Program Listing for File MDS.hpp
↰ Return to documentation for file (include\DimRedTools\MDS.hpp
)
#ifndef DIMREDTOOLS_INCLUDE_DIMREDTOOLS_MDS_HPP_
#define DIMREDTOOLS_INCLUDE_DIMREDTOOLS_MDS_HPP_
#include "DimRedTools.hpp"
#include <random>
#include <optional>
namespace dim_red {
class MDS {
public:
MDS(int n_components = 2, int max_iter = 100, double eps = 1e-4, double learning_rate = 0.2,
int random_state = 0, const std::string &dissimilarity = "euclidean");
Matrix fitTransform(const Eigen::Ref<const Matrix> &x,
std::optional<const Eigen::Ref<const Matrix>> init = std::nullopt);
Matrix dissimilarity_matrix_;
double stress_;
int n_iter_;
private:
struct Result {
double stress;
int n_iter;
friend bool operator<(const Result &lhs, const Result &rhs) {
return lhs.stress < rhs.stress;
}
};
Matrix euclideanDistances(const Eigen::Ref<const Matrix> &x) const;
void validate(const Eigen::Ref<const Matrix> &x,
std::optional<const Eigen::Ref<const Matrix>> init);
Result run(Eigen::Ref<Matrix> x);
void addGradient(Eigen::Ref<Matrix> x, double step, Matrix *x_new) const;
double getStress(Eigen::Ref<Matrix> x) const;
int n_components_;
int max_iter_;
double eps_;
double learning_rate_;
std::mt19937 random_;
std::string dissimilarity_;
double normalizer_;
};
} // namespace dim_red
#endif // DIMREDTOOLS_INCLUDE_DIMREDTOOLS_MDS_HPP_