25#ifndef __BROYDEN2_MIXER_HPP__
26#define __BROYDEN2_MIXER_HPP__
98template <
typename... FUNCS>
102 Broyden2(std::size_t max_history,
double beta,
double beta0,
double beta_scaling_factor,
double linear_mix_rmse_tol)
103 :
Mixer<FUNCS...>(max_history)
106 , beta_scaling_factor_(beta_scaling_factor)
107 , linear_mix_rmse_tol_(linear_mix_rmse_tol)
108 , S_(max_history, max_history)
109 , gamma_(max_history)
113 void mix_impl()
override
115 const auto idx_step = this->idx_hist(this->step_);
116 const auto idx_next_step = this->idx_hist(this->step_ + 1);
118 const auto n =
static_cast<int>(std::min(this->step_, this->max_history_ - 1));
120 const bool normalize =
false;
122 for (
int i = 0; i <= n; ++i) {
123 int j = this->idx_hist(this->step_ - i);
124 this->S_(n - i, n) = this->S_(n, n - i) = this->
template inner_product<normalize>(
125 this->residual_history_[j],
126 this->residual_history_[idx_step]
133 for (
int i = 1; i <= n; ++i) {
136 this->gamma_(n - i) = this->S_(n - i, n) - this->S_(n - i + 1, n);
138 for (
int j = 1; j < i; ++j) {
142 this->gamma_(n - i) += (-this->S_(n - i + 1, n - j + 1) + this->S_(n - i + 1, n - j) + this->S_(n - i, n - j + 1) - this->S_(n - i, n - j)) * this->gamma_(n - j);
145 this->gamma_(n - i) /= this->S_(n - i + 1, n - i + 1) - this->S_(n - i + 1, n - i) - this->S_(n - i, n - i + 1) + this->S_(n - i, n - i);
148 this->copy(this->output_history_[idx_step], this->input_);
153 int j = this->idx_hist(this->step_ - n);
154 this->axpy(-this->beta_ * this->gamma_(0), this->residual_history_[j], this->input_);
155 this->axpy(-this->gamma_(0), this->output_history_[j], this->input_);
158 for (
int i = 1; i < n; ++i) {
159 auto coeff = this->gamma_(n - i - 1) - this->gamma_(n - i);
160 int j = this->idx_hist(this->step_ - i);
161 this->axpy(this->beta_ * coeff, this->residual_history_[j], this->input_);
162 this->axpy(coeff, this->output_history_[j], this->input_);
167 int j = this->idx_hist(this->step_);
168 this->axpy(this->beta_ * (this->gamma_(n - 1) + 1), this->residual_history_[j], this->input_);
169 this->axpy(this->gamma_(n - 1), this->output_history_[j], this->input_);
173 this->axpy(this->beta_, this->residual_history_[idx_step], this->input_);
176 this->copy(this->input_, this->output_history_[idx_next_step]);
178 if (n ==
static_cast<int>(this->max_history_) - 1) {
179 for (
int col = 0; col < n; ++col) {
180 for (
int row = 0; row < n; ++row) {
181 this->S_(row, col) = this->S_(row + 1, col + 1);
190 double beta_scaling_factor_;
191 double linear_mix_rmse_tol_;
Abstract mixer for variadic number of Function objects, which are described by FunctionProperties.
Memory management functions and classes.
Contains definition and implementation of sirius::Mixer base class.
Namespace of the SIRIUS library.