23const double EPSILON_MCH = std::numeric_limits<double>::epsilon();
46 Eigen::BDCSVD<Eigen::MatrixXd> svd(J.
inspector());
47 auto S = svd.singularValues();
124 switch (options.
model) {
150 auto actual_reduction = (0.5 * pow(normf, 2)) - (0.5 * pow(normfnew, 2));
151 auto predicted_reduction = ((0.5 * pow(normf, 2)) - md);
158 rho = actual_reduction / predicted_reduction;
183 alpha = std::min(ONE, alpha);
209 if (!std::isfinite(
rho)) {
232 if (!std::isfinite(
rho)) {
248 throw std::runtime_error(
"Bad strategy.");
284 if (scale.
len() !=
n) {
288 switch (options.
scale) {
291 for (
int ii = 1; ii <=
n; ++ii) {
293 if (options.
scale == 1) {
296 for (
int jj = 1; jj <=
m; ++jj) {
298 temp = temp + pow(J(jj, ii), 2);
300 }
else if (options.
scale == 2) {
302 for (
int jj = 1; jj <=
n; ++jj) {
303 temp = temp + pow(A(ii, jj), 2);
321 scale(ii) = std::max(temp, scale(ii));
328 throw std::runtime_error(
"Scaling error.");
333 for (
int ii = 1; ii <=
n; ++ii) {
334 double temp = scale(ii);
335 v(ii) = v(ii) / temp;
336 for (
int jj = 1; jj <=
n; ++jj) {
337 A(ii, jj) = A(ii, jj) / temp;
338 A(jj, ii) = A(jj, ii) / temp;
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
void eigenSystem(EigenVector &eigenValues, EigenMatrix &eigenVectors)
Calculate the eigensystem of a symmetric matrix.
map_type & mutator()
Get the map to Eigen matrix.
const map_type inspector() const
Get a const copy of the Eigen matrix.
vec_map_type & mutator()
Get the map of the eigen vector.
double norm() const
Get vector norm (length)
size_t size() const
Size of the vector.
void allocate(const int iFrom, const int iTo, const int jFrom, const int jTo)
Resize the matrix.
int len2() const
Get the size along the second dimension as an int.
int len1() const
Get the size along the first dimension as an int.
void allocate(int firstIndex, int lastIndex)
Resize the vector.
int len() const
Get the length of the vector as an int.
void rankOneUpdate(DoubleFortranMatrix &hf, NLLS_workspace &w)
Update the Hessian matrix without actually evaluating it (quasi-Newton?)
double calculateRho(double normf, double normfnew, double md, const nlls_options &options)
Calculate the quantity 0.5||f||^2 - 0.5||fnew||^2 actual_reduction rho = -----------------------— = -...
double evaluateModel(const DoubleFortranVector &f, const DoubleFortranMatrix &J, const DoubleFortranMatrix &hf, const DoubleFortranVector &d, const nlls_options &options, evaluate_model_work &w)
Input: f = f(x_k), J = J(x_k), hf = \sum_{i=1}^m f_i(x_k) \nabla^2 f_i(x_k) (or an approx)
void MANTID_CURVEFITTING_DLL matmultInner(const DoubleFortranMatrix &J, DoubleFortranMatrix &A)
Takes an m x n matrix J and forms the n x n matrix A given by A = J' * J.
double MANTID_CURVEFITTING_DLL norm2(const DoubleFortranVector &v)
Compute the 2-norm of a vector which is a square root of the sum of squares of its elements.
void testConvergence(double normF, double normJF, double normF0, double normJF0, const nlls_options &options, nlls_inform &inform)
Test the convergence.
void updateTrustRegionRadius(double &rho, const nlls_options &options, NLLS_workspace &w)
Update the trust region radius which is hidden in NLLS_workspace w (w.Delta).
void allEigSymm(const DoubleFortranMatrix &A, DoubleFortranVector &ew, DoubleFortranMatrix &ev)
Calculate all the eigenvalues of a symmetric matrix.
void MANTID_CURVEFITTING_DLL multJ(const DoubleFortranMatrix &J, const DoubleFortranVector &x, DoubleFortranVector &Jx)
Multiply a matrix by a vector.
void MANTID_CURVEFITTING_DLL multJt(const DoubleFortranMatrix &J, const DoubleFortranVector &x, DoubleFortranVector &Jtx)
Multiply a transposed matrix by a vector.
double dotProduct(const DoubleFortranVector &x, const DoubleFortranVector &y)
Dot product of two vectors.
void MANTID_CURVEFITTING_DLL getSvdJ(const DoubleFortranMatrix &J, double &s1, double &sn)
Given an (m x n) matrix J held by columns as a vector, this routine returns the largest and smallest ...
const double EPSILON_MCH
Too small values don't work well with numerical derivatives.
void applyScaling(const DoubleFortranMatrix &J, DoubleFortranMatrix &A, DoubleFortranVector &v, DoubleFortranVector &scale, const nlls_options &options)
Apply_scaling input Jacobian matrix, J ouput scaled Hessisan, H, and J^Tf, v.
all workspaces called from the top level
DoubleFortranVector ysharpSks
DoubleFortranVector y_sharp
workspace for subroutine evaluateModel
double eta_successful
a potential iterate will only be accepted if the actual decrease f - f(x_new) is larger than ....
int model
specify the model used.
int scale
scale the variables? 0 - no scaling 1 - use the scaling in GSL (W s.t.
double eta_too_successful
double eta_success_but_reduce
double eta_very_successful
int tr_update_strategy
Trust region update strategy 1 - usual step function 2 - continuous method of Hans Bruun Nielsen (IMM...
bool scale_require_increase
double stop_g_absolute
overall convergence tolerances.
double maximum_radius
maximum permitted trust-region radius
double radius_increase
on very successful iterations, the trust-region radius will be increased by the factor ....