Loading...
Searching...
No Matches
PL_approximation.h
/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
* See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
* Author(s): Siargey Kachanovich
*
* Copyright (C) 2019 Inria
*
* Modification(s):
* - YYYY/MM Author: Description of the modification
*/
#ifndef FUNCTIONS_PL_APPROXIMATION_H_
#define FUNCTIONS_PL_APPROXIMATION_H_
#include <cstdlib> // for std::size_t
#include <Eigen/Dense>
namespace Gudhi {
namespace coxeter_triangulation {
template <class Function_, class Triangulation_>
struct PL_approximation {
Eigen::VectorXd operator()(const Eigen::VectorXd& p) const {
std::size_t cod_d = this->cod_d();
std::size_t amb_d = this->amb_d();
auto s = tr_.locate_point(p);
Eigen::MatrixXd matrix(cod_d, s.dimension() + 1);
Eigen::MatrixXd vertex_matrix(amb_d + 1, s.dimension() + 1);
for (std::size_t i = 0; i < s.dimension() + 1; ++i) vertex_matrix(0, i) = 1;
std::size_t j = 0;
for (auto v : s.vertex_range()) {
Eigen::VectorXd pt_v = tr_.cartesian_coordinates(v);
Eigen::VectorXd fun_v = fun_(pt_v);
for (std::size_t i = 1; i < amb_d + 1; ++i) vertex_matrix(i, j) = pt_v(i - 1);
for (std::size_t i = 0; i < cod_d; ++i) matrix(i, j) = fun_v(i);
j++;
}
assert(j == s.dimension() + 1);
Eigen::VectorXd z(amb_d + 1);
z(0) = 1;
for (std::size_t i = 1; i < amb_d + 1; ++i) z(i) = p(i - 1);
Eigen::VectorXd lambda = vertex_matrix.colPivHouseholderQr().solve(z);
Eigen::VectorXd result = matrix * lambda;
return result;
}
std::size_t amb_d() const { return fun_.amb_d(); }
std::size_t cod_d() const { return fun_.cod_d(); }
Eigen::VectorXd seed() const {
// TODO: not finished. Should use an oracle.
return Eigen::VectorXd(amb_d());
}
PL_approximation(const Function_& function, const Triangulation_& triangulation)
: fun_(function), tr_(triangulation) {}
private:
Function_ fun_;
Triangulation_ tr_;
};
template <class Function_, class Triangulation_>
PL_approximation<Function_, Triangulation_> make_pl_approximation(const Function_& function,
const Triangulation_& triangulation) {
return PL_approximation<Function_, Triangulation_>(function, triangulation);
}
} // namespace coxeter_triangulation
} // namespace Gudhi
#endif
Gudhi::coxeter_triangulation::make_pl_approximation
PL_approximation< Function_, Triangulation_ > make_pl_approximation(const Function_ &function, const Triangulation_ &triangulation)
Static constructor of the piecewise-linear approximation of a function induced by an ambient triangul...
Definition PL_approximation.h:102
Gudhi
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14
Gudhi::coxeter_triangulation::PL_approximation
Constructs a piecewise-linear approximation of a function induced by an ambient triangulation.
Definition PL_approximation.h:33
Gudhi::coxeter_triangulation::PL_approximation::amb_d
std::size_t amb_d() const
Returns the domain (ambient) dimension.
Definition PL_approximation.h:63
Gudhi::coxeter_triangulation::PL_approximation::seed
Eigen::VectorXd seed() const
Returns a point on the zero-set.
Definition PL_approximation.h:69
Gudhi::coxeter_triangulation::PL_approximation::cod_d
std::size_t cod_d() const
Returns the codomain dimension.
Definition PL_approximation.h:66
Gudhi::coxeter_triangulation::PL_approximation::operator()
Eigen::VectorXd operator()(const Eigen::VectorXd &p) const
Value of the function at a specified point.
Definition PL_approximation.h:38
Gudhi::coxeter_triangulation::PL_approximation::PL_approximation
PL_approximation(const Function_ &function, const Triangulation_ &triangulation)
Constructor of the piecewise-linear approximation of a function induced by an ambient triangulation.
Definition PL_approximation.h:81