56template <
typename Coeff,
typename DerivativeMatrix,
63 tv_admm<Coeff, DerivativeMatrix, Data>, Data> {
84 this->configure_child_algorithm_logger_if_exists(conjugate_gradient_);
98 void compute(
const Coeff& coeff,
const DerivativeMatrix& derivative_matrix,
101 derivative_matrix_ = &derivative_matrix;
111 "Coefficient matrix and data vector must have the same number of "
115 "The number of columns in the coefficient matrix must match the "
116 "number of rows in solution vector.");
119 "Data and solution must have the same number of columns.");
122 "The number of columns in the derivative matrix must match the "
123 "number of rows in solution vector.");
126 derivative_ = (*derivative_matrix_) * solution;
127 lagrange_multiplier_ = data_type::Zero(derivative_matrix_->rows());
128 temp_solution_ = solution;
129 residual_ = (*coeff_) * solution - (*data_);
130 update_rate_ = std::numeric_limits<scalar_type>::infinity();
132 const scalar_type conjugate_gradient_tolerance_rate =
133 rate_of_cg_tol_rate_to_tol_update_rate_ * tol_update_rate_;
134 conjugate_gradient_.tolerance_rate(conjugate_gradient_tolerance_rate);
141 static_cast<scalar_type>(2) * (*coeff_).transpose() * (*data_) -
142 (*derivative_matrix_).transpose() * lagrange_multiplier_ +
143 derivative_constraint_coeff_ * (*derivative_matrix_).transpose() *
145 previous_solution_ = solution;
146 conjugate_gradient_.solve(
148 result =
static_cast<scalar_type>(2) * (*coeff_).transpose() *
150 result += derivative_constraint_coeff_ *
151 (*derivative_matrix_).transpose() * (*derivative_matrix_) *
154 temp_solution_, solution);
155 update_rate_ = (solution - previous_solution_).
norm() /
156 (solution.norm() + std::numeric_limits<scalar_type>::epsilon());
157 residual_ = (*coeff_) * solution - (*data_);
160 previous_derivative_ = derivative_;
161 derivative_ = (*derivative_matrix_) * solution +
162 lagrange_multiplier_ / derivative_constraint_coeff_;
164 param / derivative_constraint_coeff_;
166 derivative_, derivative_shrinkage_threshold);
167 update_rate_ += (derivative_ - previous_derivative_).
norm() /
168 (derivative_.norm() + std::numeric_limits<scalar_type>::epsilon());
171 lagrange_multiplier_update_ = derivative_constraint_coeff_ *
172 ((*derivative_matrix_) * solution - derivative_);
173 lagrange_multiplier_ += lagrange_multiplier_update_;
174 update_rate_ += lagrange_multiplier_update_.norm() /
175 (lagrange_multiplier_.norm() +
176 std::numeric_limits<scalar_type>::epsilon());
183 const data_type& solution)
const ->
bool {
185 return (iterations() > max_iterations()) ||
186 (update_rate() < tol_update_rate());
193 iteration_logger.template append<index_type>(
194 "Iter.", &this_type::iterations);
195 iteration_logger.template append<scalar_type>(
196 "UpdateRate", &this_type::update_rate);
197 iteration_logger.template append<scalar_type>(
198 "Res.Rate", &this_type::residual_norm_rate);
204 return ((*coeff_) * solution - (*data_)).squaredNorm();
210 return (*derivative_matrix_ * solution).template lpNorm<1>();
218 data = (*coeff_) * solution;
227 const data_type approx_order_of_solution = coeff_->transpose() *
230 (*derivative_matrix_ * approx_order_of_solution)
234 this->logger(),
"approx_order_of_param={}", approx_order_of_param);
235 constexpr auto tol_update_coeff_multiplier =
237 return {approx_order_of_param *
239 tol_update_coeff_multiplier * tol_update_rate_),
268 return residual_.squaredNorm() / data_->squaredNorm();
277 return max_iterations_;
288 "Maximum number of iterations must be a positive integer.");
289 max_iterations_ = value;
299 return tol_update_rate_;
310 "Tolerance of update rate of the solution must be a positive "
312 tol_update_rate_ = value;
357 static constexpr auto default_derivative_constraint_coeff =
362 default_derivative_constraint_coeff};
371 static constexpr auto default_tol_update_rate =
378 static constexpr auto default_rate_of_cg_tol_rate_to_tol_update_rate =
383 default_rate_of_cg_tol_rate_to_tol_update_rate};
Definition of apply_shrinkage_operator function.
Definition of max_eigen_aat function.
Class to perform conjugate gradient (CG) method golub2013 for linear operators.
Class to write logs of iterations.
Class of tags of logs without memory management.
Base class of solvers using iterative formulas for regularization.
typename Eigen::NumTraits< typename data_type::Scalar >::Real scalar_type
Type of scalars.
Data data_type
Type of data.
Class to solve linear equations with total variation (TV) regularization using the alternating direct...
auto param_search_region() const -> std::pair< scalar_type, scalar_type >
Get the default region to search for the optimal regularization parameter.
void iterate(const scalar_type ¶m, data_type &solution)
Iterate the algorithm once.
auto update_rate() const noexcept -> scalar_type
Get the rate of the norm of the update of the solution in the last iteration.
auto residual_norm_rate() const -> scalar_type
Get the rate of the last residual norm.
auto residual_norm(const data_type &solution) const -> scalar_type
Calculate the squared norm of the residual.
auto data_size() const -> index_type
Get the size of data.
auto max_iterations() const -> index_type
Get the maximum number of iterations.
Coeff coeff_type
Type of coefficient matrices.
void calculate_data_for(const data_type &solution, data_type &data) const
Calculate data for a solution.
auto tol_update_rate(scalar_type value) -> tv_admm &
Set the tolerance of update rate of the solution.
auto iterations() const noexcept -> index_type
Get the number of iterations.
auto tol_update_rate() const -> scalar_type
Get the tolerance of update rate of the solution.
auto max_iterations(index_type value) -> tv_admm &
Set the maximum number of iterations.
void configure_iteration_logger(logging::iterations::iteration_logger< this_type > &iteration_logger) const
Configure an iteration logger.
DerivativeMatrix derivative_matrix_type
Type of matrices to compute derivatives.
void compute(const Coeff &coeff, const DerivativeMatrix &derivative_matrix, const Data &data)
Compute internal parameters.
void init(const scalar_type ¶m, data_type &solution)
Initialize.
auto is_stop_criteria_satisfied(const data_type &solution) const -> bool
Determine if stopping criteria of the algorithm are satisfied.
auto regularization_term(const data_type &solution) const -> scalar_type
Calculate the regularization term.
void change_data(const data_type &data)
Change data.
Concept of Eigen's dense matrices.
Concept of Eigen's dense vectors.
Concept of sparse matrices.
Definition of dense_matrix concept.
Definition of dense_vector concept.
Definition of exceptions.
Definition of index_type type.
Definition of iteration_logger class.
Definition of iterative_regularized_solver_base class.
Definition of log_tag_view class.
Definition of macros for logging.
#define NUM_COLLECT_LOG_TRACE(LOGGER,...)
Write a trace log.
std::ptrdiff_t index_type
Type of indices in this library.
auto norm(const Matrix &matrix)
Calculate norm of a matrix.
constexpr auto weak_coeff_min_param
Coefficient (minimum parameter to be searched) / (maximum singular value or eigen value).
auto approximate_max_eigen_aat(const Matrix &matrix) -> typename Matrix::Scalar
Approximate the maximum eigenvalue of for a matrix .
void apply_shrinkage_operator(Vector &target, typename Vector::Scalar threshold)
Apply shrinkage operator to a vector.
constexpr auto weak_coeff_max_param
Coefficient (maximum parameter to be searched) / (maximum singular value or eigen value).
Namespace of regularization algorithms.
constexpr auto tv_admm_tag
Tag of tv_admm.
Definition of operator_conjugate_gradient class.
Definition of NUM_COLLECT_PRECONDITION macro.
#define NUM_COLLECT_PRECONDITION(CONDITION,...)
Check whether a precondition is satisfied and throw an exception if not.
Definition of sparse_matrix concept.
Definition of coefficients for regularization parameters.