mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2024-11-10 00:45:36 +00:00
composite minimizer
This commit is contained in:
parent
3bf3e15def
commit
79803007ff
71
lib/LatAnalyze/Numerical/CompositeMinimizer.cpp
Normal file
71
lib/LatAnalyze/Numerical/CompositeMinimizer.cpp
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* CompositeMinimizer.cpp, part of LatAnalyze 3
|
||||||
|
*
|
||||||
|
* Copyright (C) 2013 - 2024 Antonin Portelli
|
||||||
|
*
|
||||||
|
* LatAnalyze 3 is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* LatAnalyze 3 is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LatAnalyze/Numerical/CompositeMinimizer.hpp>
|
||||||
|
#include <LatAnalyze/includes.hpp>
|
||||||
|
#include "CompositeMinimizer.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Latan;
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* CompositeMinimizer implementation *
|
||||||
|
******************************************************************************/
|
||||||
|
// constructor ////////////////////////////////////////////////////////////////
|
||||||
|
CompositeMinimizer::CompositeMinimizer(const std::vector<Minimizer *> &minimizer)
|
||||||
|
: minVec_(minimizer)
|
||||||
|
{
|
||||||
|
if (minVec_.size() == 0)
|
||||||
|
{
|
||||||
|
LATAN_ERROR(Size, "minimizer vector has size 0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// access /////////////////////////////////////////////////////////////////////
|
||||||
|
bool CompositeMinimizer::supportLimits(void) const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// minimization ///////////////////////////////////////////////////////////////
|
||||||
|
const DVec &CompositeMinimizer::operator()(const DoubleFunction &f)
|
||||||
|
{
|
||||||
|
DVec &x = getState();
|
||||||
|
DVec tmp;
|
||||||
|
unsigned int i = 1, nMin = minVec_.size();
|
||||||
|
|
||||||
|
// resize minimizer state to match function number of arguments
|
||||||
|
if (f.getNArg() != x.size())
|
||||||
|
{
|
||||||
|
resize(f.getNArg());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &m: minVec_)
|
||||||
|
{
|
||||||
|
if (getVerbosity() >= Verbosity::Normal)
|
||||||
|
{
|
||||||
|
cout << "********** Composite minimizer step " << i << "/" << nMin << endl;
|
||||||
|
}
|
||||||
|
m->setInit(x);
|
||||||
|
x = (*m)(f);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}
|
68
lib/LatAnalyze/Numerical/CompositeMinimizer.hpp
Normal file
68
lib/LatAnalyze/Numerical/CompositeMinimizer.hpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* CompositeMinimizer.hpp, part of LatAnalyze 3
|
||||||
|
*
|
||||||
|
* Copyright (C) 2013 - 2024 Antonin Portelli
|
||||||
|
*
|
||||||
|
* LatAnalyze 3 is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* LatAnalyze 3 is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Latan_CompositeMinimizer_hpp_
|
||||||
|
#define Latan_CompositeMinimizer_hpp_
|
||||||
|
|
||||||
|
#include <LatAnalyze/Global.hpp>
|
||||||
|
#include <LatAnalyze/Functional/Function.hpp>
|
||||||
|
#include <LatAnalyze/Numerical/Minimizer.hpp>
|
||||||
|
|
||||||
|
BEGIN_LATAN_NAMESPACE
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* Class for chaining minimizers *
|
||||||
|
******************************************************************************/
|
||||||
|
class CompositeMinimizer: public Minimizer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructors
|
||||||
|
explicit CompositeMinimizer(const std::vector<Minimizer *> &minimizer);
|
||||||
|
template <typename... Ts>
|
||||||
|
CompositeMinimizer(Minimizer &min, Ts & ... minimisers);
|
||||||
|
// destructor
|
||||||
|
virtual ~CompositeMinimizer(void) = default;
|
||||||
|
// access
|
||||||
|
virtual bool supportLimits(void) const;
|
||||||
|
// minimization
|
||||||
|
virtual const DVec & operator()(const DoubleFunction &f);
|
||||||
|
private:
|
||||||
|
std::vector<Minimizer *> minVec_;
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* CompositeMinimizer template implementation *
|
||||||
|
******************************************************************************/
|
||||||
|
template <typename... Ts>
|
||||||
|
CompositeMinimizer::CompositeMinimizer(Minimizer &min, Ts & ... minimisers)
|
||||||
|
{
|
||||||
|
static_assert(static_or<std::is_assignable<Minimizer &, Ts>::value...>::value,
|
||||||
|
"model arguments are not compatible with Minimizer");
|
||||||
|
|
||||||
|
|
||||||
|
minVec_ = {&min, &minimisers...};
|
||||||
|
if (minVec_.size() == 0)
|
||||||
|
{
|
||||||
|
LATAN_ERROR(Size, "minimizer vector has size 0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
END_LATAN_NAMESPACE
|
||||||
|
|
||||||
|
#endif // Latan_CompositeMinimizer_hpp_
|
@ -25,6 +25,7 @@ set(LATAN_HEADERS
|
|||||||
LatAnalyze/Io/IoObject.hpp
|
LatAnalyze/Io/IoObject.hpp
|
||||||
LatAnalyze/Io/Xml/tinyxml2.hpp
|
LatAnalyze/Io/Xml/tinyxml2.hpp
|
||||||
LatAnalyze/Io/XmlReader.hpp
|
LatAnalyze/Io/XmlReader.hpp
|
||||||
|
LatAnalyze/Numerical/CompositeMinimizer.hpp
|
||||||
LatAnalyze/Numerical/DWT.hpp
|
LatAnalyze/Numerical/DWT.hpp
|
||||||
LatAnalyze/Numerical/DWTFilters.hpp
|
LatAnalyze/Numerical/DWTFilters.hpp
|
||||||
LatAnalyze/Numerical/Derivative.hpp
|
LatAnalyze/Numerical/Derivative.hpp
|
||||||
@ -77,6 +78,7 @@ set(LATAN_SOURCES
|
|||||||
LatAnalyze/Io/Hdf5File.cpp
|
LatAnalyze/Io/Hdf5File.cpp
|
||||||
LatAnalyze/Io/Io.cpp
|
LatAnalyze/Io/Io.cpp
|
||||||
LatAnalyze/Io/XmlReader.cpp
|
LatAnalyze/Io/XmlReader.cpp
|
||||||
|
LatAnalyze/Numerical/CompositeMinimizer.cpp
|
||||||
LatAnalyze/Numerical/DWT.cpp
|
LatAnalyze/Numerical/DWT.cpp
|
||||||
LatAnalyze/Numerical/DWTFilters.cpp
|
LatAnalyze/Numerical/DWTFilters.cpp
|
||||||
LatAnalyze/Numerical/Derivative.cpp
|
LatAnalyze/Numerical/Derivative.cpp
|
||||||
|
Loading…
Reference in New Issue
Block a user