Least_squares_solver.cpp
Go to the documentation of this file.
1 // Copyright 2019, University of Maryland and the MANGO development team.
2 //
3 // This file is part of MANGO.
4 //
5 // MANGO is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU Lesser General Public License as
7 // published by the Free Software Foundation, either version 3 of the
8 // License, or (at your option) any later version.
9 //
10 // MANGO is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with MANGO. If not, see
17 // <https://www.gnu.org/licenses/>.
18 
19 #include <stdexcept>
20 #include "mango.hpp"
21 #include "Least_squares_solver.hpp"
23 
24 // Constructor
25 mango::Least_squares_solver::Least_squares_solver(Least_squares_problem* problem_in, int N_parameters_in, int N_terms_in)
26 : Solver(problem_in, N_parameters_in) // Call constructor of the base class
27 {
28  if (N_terms_in < 1) throw std::runtime_error("Error in mango::Least_squares_solver::Least_squares_solver(). N_terms must be at least 1.");
29  N_terms = N_terms_in;
30 
31  // Defaults specific to least_squares problems are set in the following lines
32  targets = NULL;
33  sigmas = NULL;
34  residual_function = NULL;
36  residuals = new double[N_terms_in];
39 
40  recorder = new Recorder_least_squares(this);
41 }
42 
43 // Constructor with no arguments, used only for unit tests.
45  : Solver() // Call constructor of base class
46 {
47 }
48 
49 // Destructor
51  delete[] residuals;
52 }
53 
54 void mango::Least_squares_solver::finite_difference_Jacobian(const double* state_vector_arg, double* base_case_residual, double* Jacobian) {
55  // Call Solver::finite_difference_Jacobian
56  mango::Solver::finite_difference_Jacobian(residual_function, N_terms, state_vector_arg, base_case_residual, Jacobian);
57 }
Least_squares_solver.hpp
mango::Least_squares_solver::N_terms
int N_terms
Definition: Least_squares_solver.hpp:38
mango::Least_squares_solver::sigmas
double * sigmas
Definition: Least_squares_solver.hpp:40
mango::Least_squares_solver::print_residuals_in_output_file
bool print_residuals_in_output_file
Definition: Least_squares_solver.hpp:44
mango::Solver::objective_function
objective_function_type objective_function
Definition: Solver.hpp:44
mango::Least_squares_solver::least_squares_to_single_objective
static void least_squares_to_single_objective(int *, const double *, double *, int *, mango::Problem *, void *)
Definition: optimize_least_squares.cpp:149
mango::Recorder_least_squares
Definition: Recorder_least_squares.hpp:28
Recorder_least_squares.hpp
mango::Solver::finite_difference_Jacobian
void finite_difference_Jacobian(vector_function_type, int, const double *, double *, double *)
Definition: finite_difference_Jacobian.cpp:28
mango::Least_squares_solver::residuals
double * residuals
Definition: Least_squares_solver.hpp:43
mango::Solver::recorder
Recorder * recorder
Definition: Solver.hpp:67
mango::Least_squares_solver::~Least_squares_solver
~Least_squares_solver()
Definition: Least_squares_solver.cpp:50
mango::Least_squares_problem
Definition: mango.hpp:658
mango.hpp
mango::Least_squares_solver::residual_function
vector_function_type residual_function
Definition: Least_squares_solver.hpp:41
mango::Least_squares_solver::finite_difference_Jacobian
void finite_difference_Jacobian(const double *, double *, double *)
Definition: Least_squares_solver.cpp:54
mango::Solver
Definition: Solver.hpp:31
mango::Least_squares_solver::Least_squares_solver
Least_squares_solver()
Definition: Least_squares_solver.cpp:44
mango::Least_squares_solver::best_residual_function
double * best_residual_function
Definition: Least_squares_solver.hpp:42
mango::Least_squares_solver::targets
double * targets
Definition: Least_squares_solver.hpp:39