Least_squares_problem.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 <iostream>
20 #include <string>
21 #include <stdexcept>
22 #include "mango.hpp"
23 #include "Solver.hpp"
24 #include "Least_squares_solver.hpp"
25 
26 // Constructor for least-squares problems
27 mango::Least_squares_problem::Least_squares_problem(int N_parameters_in, double* state_vector_in, int N_terms_in, double* targets_in, double* sigmas_in,
28  double* best_residual_function_in, vector_function_type residual_function_in, int argc_in, char* argv_in[])
29  : Problem(N_parameters_in, state_vector_in, NULL, argc_in, argv_in) // Call constructor of base class.
30 {
31  // Replace Solver with a Least_squares_solver
32  delete solver;
33  least_squares_solver = new Least_squares_solver(this,N_parameters_in, N_terms_in);
34  solver = least_squares_solver;
35  // Note that least_squares_solver and solver point to the same object.
36 
37  solver->argc = argc_in;
38  solver->argv = argv_in;
39  solver->N_parameters = N_parameters_in;
40  //solver->objective_function = NULL; // Should this be least_squares_to_single_objective?
41  solver->state_vector = state_vector_in;
42 
43  /*
44  least_squares_data = new Least_squares_data(solver, N_terms_in);// I'm not sure "this" is correct? Does it need to be a Problem* instead of a Least_squares_problem* ?
45  */
46  least_squares_solver->N_terms = N_terms_in;
47  least_squares_solver->targets = targets_in;
48  least_squares_solver->sigmas = sigmas_in;
49  least_squares_solver->residual_function = residual_function_in;
50  least_squares_solver->best_residual_function = best_residual_function_in;
51 
52 }
53 
54 // Destructor
56  if (solver->verbose > 0) std::cout << "Mango least squares problem is being destroyed." << std::endl;
57  //delete data; // This is handled by the destructor of the parent class (Problem).
58  //delete solver; // This is handled by the destructor of the parent class (Problem).
59 }
60 
62  least_squares_solver->print_residuals_in_output_file = new_bool;
63 }
64 
66  return least_squares_solver->N_terms;
67 }
68 
69 /*
70 double mango::Least_squares_problem::optimize() {
71  // Delegate this work to Least_squares_data so we don't need to put "least_squares_data->" in front of everything.
72  return least_squares_data->optimize(&mpi_partition);
73 }
74 */
Least_squares_solver.hpp
mango::Least_squares_solver::N_terms
int N_terms
Definition: Least_squares_solver.hpp:38
mango::Problem::solver
Solver * solver
Definition: mango.hpp:446
mango::Least_squares_solver::sigmas
double * sigmas
Definition: Least_squares_solver.hpp:40
mango::Least_squares_problem::set_print_residuals_in_output_file
void set_print_residuals_in_output_file(bool print)
Determine whether or not to print each individual residual in the MANGO output file.
Definition: Least_squares_problem.cpp:61
mango::Solver::argc
int argc
Definition: Solver.hpp:46
mango::Least_squares_solver
Definition: Least_squares_solver.hpp:28
Solver.hpp
mango::Solver::state_vector
double * state_vector
Definition: Solver.hpp:58
mango::vector_function_type
void(* vector_function_type)(int *N_parameters, const double *state_vector, int *N_terms, double *residuals, int *failed, mango::Problem *problem, void *user_data)
Format for the user-supplied subroutine that computes the residuals for a least-squares optimization ...
Definition: mango.hpp:439
mango::Least_squares_problem::Least_squares_problem
Least_squares_problem(int N_parameters, double *state_vector, int N_terms, double *targets, double *sigmas, double *best_residual_function, vector_function_type residual_function, int argc, char **argv)
Constructor for a least-squares optimization problem.
Definition: Least_squares_problem.cpp:27
mango::Solver::argv
char ** argv
Definition: Solver.hpp:47
mango.hpp
mango::Least_squares_solver::residual_function
vector_function_type residual_function
Definition: Least_squares_solver.hpp:41
mango::Solver::N_parameters
int N_parameters
Definition: Solver.hpp:43
mango::Least_squares_problem::~Least_squares_problem
~Least_squares_problem()
Destructor.
Definition: Least_squares_problem.cpp:55
mango::Least_squares_problem::get_N_terms
int get_N_terms()
Return the number of least-squares terms that are summed to form the objective function.
Definition: Least_squares_problem.cpp:65
mango::Least_squares_solver::best_residual_function
double * best_residual_function
Definition: Least_squares_solver.hpp:42
mango::Problem
Definition: mango.hpp:442
mango::Least_squares_solver::targets
double * targets
Definition: Least_squares_solver.hpp:39