File: MinimizerInfo.cpp

package info (click to toggle)
bornagain 23.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,936 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 318; ruby: 173; xml: 130; makefile: 51; ansic: 24
file content (145 lines) | stat: -rw-r--r-- 4,877 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Fit/Minimizer/MinimizerInfo.cpp
//! @brief     Implements class MinimizerInfo.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#include "Fit/Minimizer/MinimizerInfo.h"
#include <sstream>
#include <stdexcept>

void MinimizerInfo::setAlgorithmName(const std::string& algorithmName)
{
    for (const AlgorithmInfo& algo : m_algorithms) {
        if (algo.name() == algorithmName) {
            m_current_algorithm = algorithmName;
            return;
        }
    }

    std::ostringstream msg;
    msg << "MinimizerInfo::setAlgorithmName -> Error. Algorithm name '" << algorithmName
        << "' is not in the list of defined algorithms (";
    for (const AlgorithmInfo& algo : m_algorithms)
        msg << algo.name() << " ";
    msg << ")";
    throw std::runtime_error(msg.str());
}

//! Return list of defined algorithm names.

std::vector<std::string> MinimizerInfo::algorithmNames() const
{
    std::vector<std::string> result;
    for (const AlgorithmInfo& algo : m_algorithms)
        result.push_back(algo.name());
    return result;
}

//! Returns list of string with description of all available algorithms.

std::vector<std::string> MinimizerInfo::algorithmDescriptions() const
{
    std::vector<std::string> result;
    for (const AlgorithmInfo& algo : m_algorithms)
        result.push_back(algo.description());
    return result;
}

//! Creates information for Minuit2Minimizer.

MinimizerInfo MinimizerInfo::buildMinuit2Info(const std::string& defaultAlgo)
{
    MinimizerInfo result("Minuit2", "Minuit2 minimizer from ROOT library");

    result.addAlgorithm(
        "Migrad",
        "Variable-metric method with inexact line search, best minimizer according to ROOT.");

    result.addAlgorithm("Simplex", "Simplex method of Nelder and Mead, robust "
                                   "against big fluctuations in objective function.");

    result.addAlgorithm("Combined", "Combination of Migrad and Simplex (if Migrad fails).");

    result.addAlgorithm("Scan", "Simple objective function scan, one parameter at a time.");

    result.addAlgorithm("Fumili", "Gradient descent minimizer similar to "
                                  "Levenberg-Marquardt, sometimes can be better "
                                  "than all others.");

    if (defaultAlgo.empty())
        result.setAlgorithmName("Migrad");
    else
        result.setAlgorithmName(defaultAlgo);

    return result;
}

//! Creates information for GSLMultiMinMinimizer.

MinimizerInfo MinimizerInfo::buildGSLMultiMinInfo(const std::string& defaultAlgo)
{
    MinimizerInfo result("GSLMultiMin", "MultiMin minimizer from GSL library");

    result.addAlgorithm("SteepestDescent", "Steepest descent");
    result.addAlgorithm("ConjugateFR", "Fletcher-Reeves conjugate gradient");
    result.addAlgorithm("ConjugatePR", "Polak-Ribiere conjugate gradient");
    result.addAlgorithm("BFGS", "BFGS conjugate gradient");
    result.addAlgorithm("BFGS2", "BFGS conjugate gradient (Version 2)");

    if (defaultAlgo.empty())
        result.setAlgorithmName("ConjugateFR");
    else
        result.setAlgorithmName(defaultAlgo);

    return result;
}

//! Creates information for GSL's Levenberg-Marquardt.

MinimizerInfo MinimizerInfo::buildGSLLMAInfo()
{
    MinimizerInfo result("GSLLMA", "Levenberg-Marquardt from GSL library");
    result.addAlgorithm("Levenberg-Marquardt", "Levenberg-Marquardt");
    return result;
}

//! Creates information for GSL's simmulated annealing algorithm.

MinimizerInfo MinimizerInfo::buildGSLSimAnInfo()
{
    MinimizerInfo result("GSLSimAn", "Simulated annealing minimizer from GSL library");
    result.addAlgorithm("Simulated annealing", "Simulated annealing");
    return result;
}

//! Creates information for TMVA genetic minimizer

MinimizerInfo MinimizerInfo::buildGeneticInfo()
{
    MinimizerInfo result("Genetic", "Genetic minimizer from TMVA library");
    result.addAlgorithm("Genetic", "Genetic algorithm");
    return result;
}

//! Adds minimizer algorithm to the list of defined algorithms.

void MinimizerInfo::addAlgorithm(const AlgorithmInfo& algorithm)
{
    m_current_algorithm = algorithm.name();
    m_algorithms.push_back(algorithm);
}

void MinimizerInfo::addAlgorithm(const std::string& algorithmName,
                                 const std::string& algorithmDescription)
{
    addAlgorithm(AlgorithmInfo(algorithmName, algorithmDescription));
}