26#include <Eigen/SparseCore>
41template <num_collect::base::concepts::sparse_matrix Matrix>
44 using scalar_type =
typename Matrix::value_type;
45 using storage_index_type =
typename Matrix::StorageIndex;
47 std::vector<Eigen::Triplet<scalar_type, storage_index_type>> triplets;
50 static constexpr auto factor =
static_cast<scalar_type
>(100.0);
51 static constexpr auto thresh =
static_cast<scalar_type
>(0.1);
52 const scalar_type sol_rate =
53 static_cast<scalar_type
>(j) /
static_cast<scalar_type
>(cols);
54 const scalar_type data_rate =
55 static_cast<scalar_type
>(i) /
static_cast<scalar_type
>(rows);
56 const scalar_type diff = sol_rate - data_rate;
57 const scalar_type coeff =
58 std::max(std::exp(-factor * diff * diff) - thresh,
59 static_cast<scalar_type
>(0));
60 if (coeff >
static_cast<scalar_type
>(0)) {
61 triplets.emplace_back(
static_cast<storage_index_type
>(i),
62 static_cast<storage_index_type
>(j), coeff);
67 mat.resize(rows, cols);
68 mat.setFromTriplets(triplets.begin(), triplets.end());
Definition of index_type type.
std::ptrdiff_t index_type
Type of indices in this library.
Namespace of regularization.
void sparse_blur_matrix(Matrix &mat, num_collect::index_type rows, num_collect::index_type cols)
Create a sparse blur matrix.
Definition of sparse_matrix concept.