34 void Aprod1(
unsigned int m,
unsigned int n,
const double * x,
double * y )
const override 51 void Aprod2(
unsigned int m,
unsigned int n,
double * x,
const double * y )
const override 83 int vnl_lsqr::aprod_(
const long* mode,
const long*
m,
const long* n,
double* x,
double* y,
long* ,
long* ,
long* ,
double* rw,
void* userdata)
90 auto*
self = static_cast<vnl_lsqr*>(userdata);
100 self->ls_->multiply(x_ref, tmp);
105 self->ls_->transpose_multiply(y_ref, tmp);
120 std::vector<double>
v(n);
121 std::vector<double> se(n);
125 #ifdef THIS_CODE_IS_DISABLED_BECAUSE_THE_LSQR_CODE_FROM_NETLIB_WAS_COPYRIGHTED_BY_ACM 128 double acond, rnorm, xnorm;
130 double anorm, arnorm;
137 solver.SetDamp( damp );
140 solver.SetMaximumNumberOfIterations(
max_iter_ );
141 solver.SetStandardErrorEstimates( se.data() );
142 solver.SetToleranceA( atol );
143 solver.SetToleranceB( btol );
147 #ifdef THIS_CODE_IS_DISABLED_BECAUSE_THE_LSQR_CODE_FROM_NETLIB_WAS_COPYRIGHTED_BY_ACM 149 &
m, &n,
aprod_, &damp, &leniw, &lenrw, iw, &rw[0],
152 &
num_iter_, &anorm, &acond, &rnorm, &arnorm, &xnorm,
160 num_iter_ = solver.GetNumberOfIterationsPerformed();
161 anorm = solver.GetFrobeniusNormEstimateOfAbar();
162 arnorm = solver.GetFinalEstimateOfNormOfResiduals();
164 #ifdef THIS_CODE_IS_DISABLED_BECAUSE_THE_LSQR_CODE_FROM_NETLIB_WAS_COPYRIGHTED_BY_ACM 165 std::cerr <<
"A Fro norm estimate = " << anorm << std::endl
166 <<
"A condition estimate = " << acond << std::endl
167 <<
"Residual norm estimate = " << rnorm << std::endl
168 <<
"A'(Ax - b) norm estimate = " << arnorm << std::endl
169 <<
"x norm estimate = " << xnorm << std::endl;
184 << __FILE__
" : iterations = " <<
num_iter_ << std::endl;
189 const char* vnl_lsqr_reasons[] = {
190 "x = 0 is the exact solution. No iterations were performed.",
191 "The equations A*x = b are probably compatible. " 192 "Norm(A*x - b) is sufficiently small, given the " 193 "values of ATOL and BTOL.",
194 "The system A*x = b is probably not compatible. " 195 "A least-squares solution has been obtained that is " 196 "sufficiently accurate, given the value of ATOL.",
197 "An estimate of cond(Abar) has exceeded CONLIM. " 198 "The system A*x = b appears to be ill-conditioned. " 199 "Otherwise, there could be an error in subroutine APROD.",
200 "The equations A*x = b are probably compatible. " 201 "Norm(A*x - b) is as small as seems reasonable on this machine.",
202 "The system A*x = b is probably not compatible. A least-squares " 203 "solution has been obtained that is as accurate as seems " 204 "reasonable on this machine.",
205 "Cond(Abar) seems to be so large that there is no point in doing further " 206 "iterations, given the precision of this machine. " 207 "There could be an error in subroutine APROD.",
208 "The iteration limit ITNLIM was reached." 212 (rc < 0 || rc > 7) os << __FILE__
" : Illegal return code : " << rc << std::endl;
214 os << __FILE__
" : " << vnl_lsqr_reasons[rc] << std::endl;
static int aprod_(const long *mode, const long *m, const long *n, double *x, double *y, long *leniw, long *lenrw, long *iw, double *rw, void *userdata)
virtual void multiply(vnl_vector< double > const &x, vnl_vector< double > &y) const =0
Compute A*x, putting result in y.
virtual void get_rhs(vnl_vector< double > &b) const =0
void Aprod1(unsigned int m, unsigned int n, const double *x, double *y) const override
computes y = y + A*x without altering x, where A is a matrix of dimensions A[m][n].
double resid_norm_estimate_
double A_condition_estimate_
vnl_vector using user-supplied storage
vnl_vector using user-supplied storage.
static void translate_return_code(std::ostream &os, int return_code)
T const * data_block() const
Access the contiguous block storing the elements in the vector. O(1).
void SetWorkingSpace(double *inrw)
Abstraction for a linear system of equations.
unsigned int get_number_of_residuals() const
Return the number of residuals.
virtual void transpose_multiply(vnl_vector< double > const &y, vnl_vector< double > &x) const =0
Compute A_transpose * y, putting result in x.
double result_norm_estimate_
vnl_decnum max(vnl_decnum const &x, vnl_decnum const &y)
unsigned int get_number_of_unknowns() const
Return the number of unknowns.
void diagnose_outcome(std::ostream &os) const
Pontificate about the outcome of the last minimization.
~lsqrVNL() override=default
void Aprod2(unsigned int m, unsigned int n, double *x, const double *y) const override
computes x = x + A'*y without altering y, where A is a matrix of dimensions A[m][n].
void SetLinearSystem(vnl_linear_system *inls)
Set the linear system to be solved A*x = b.
int minimize(vnl_vector< double > &x)
Perform the minimization starting from x=0 and putting the result into x.