Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • f99a844
  • /
  • lib
  • /
  • OxFitterAmoebaVnl.h
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:25e00ef17a1ee0563e3e48b4fa71a7404dd86d6a
directory badge Iframe embedding
swh:1:dir:7f21c9a4b7dfafd29925be862d8bd559b684364d
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
OxFitterAmoebaVnl.h
/*!
 * \file OxFitterAmoebaVnl.h
 * \author Konrad Werys
 * \date 2018/07/30
 */

#ifndef Tomato_OXFITTERAMOEBAVNL_H
#define Tomato_OXFITTERAMOEBAVNL_H

#include "OxFitter.h"
#include "OxFunctionsT1AdapterVnlCost.h"
#include <vnl/algo/vnl_amoeba.h>

namespace Ox {
    template<typename MeasureType>
    class FitterAmoebaVnl : public Fitter<MeasureType> {

    public:

        typedef vnl_amoeba VnlFitterType; // !!! this is the most important configuration part !!!
        typedef FunctionsT1AdapterVnlCost FunctionsAdaptedToVnlType;

        /**
         * the most important function of this class
         * @return success/failure
         */
        virtual int performFitting(){

            configureMinimizer();

            vnl_vector<MeasureType> temp(this->getParameters(), this->_FunctionsT1->getNDims());

            _VnlFitter->minimize(temp);

            if (temp.size() != 0) {
                temp.copy_out(this->getParameters());
            }
            if (this->getVerbose()) {
                std::cout << "Results: " << temp << " Cost: " << this->_FunctionsT1->calcCostValue(this->getParameters()) << std::endl;
            }

            return 0; //EXIT_SUCCESS;
        };

        // getters
        FunctionsAdaptedToVnlType *getFunctionsAdaptedToVnl() const {
            return _FunctionsAdaptedToVnl;
        }

        /**
         * \brief show me your Fitter
         */
        virtual void disp(){
            std::cout << "\nYou called disp() on a FitterAmoebaVnl object " << this << "\n";
            std::cout << "It has VnlFitter " << _VnlFitter << std::endl;
            std::cout << "It has FunctionsAdaptedToVnl " << _FunctionsAdaptedToVnl << std::endl;
            std::cout << "It's base class is as follows: ";

            Fitter<MeasureType>::disp();
        }

        /**
         * \brief constructor
         */
        FitterAmoebaVnl() {
            // I cannot initialise _FunctionsAdaptedToVnl here, as I do not know nDims yet
            _FunctionsAdaptedToVnl = 0;
            _VnlFitter = 0;
        };

        /**
         * cloning
         * @return
         */
        virtual Fitter<MeasureType> *newByCloning() { return new FitterAmoebaVnl<MeasureType>(*this); }

        /**
         * \brief destructor
         */
        virtual ~FitterAmoebaVnl() {
            delete _FunctionsAdaptedToVnl; _FunctionsAdaptedToVnl = 0;
            delete _VnlFitter; _VnlFitter = 0;
        };

    protected:

        virtual void configureMinimizer() {
            if (!_VnlFitter) {
                if (!this->_FunctionsT1) {
                    throw std::runtime_error("Set the FunctionsT1 object");
                } else {
                    delete _FunctionsAdaptedToVnl; _FunctionsAdaptedToVnl = 0;
                    delete _VnlFitter; _VnlFitter = 0;
                    int nDims = this->_FunctionsT1->getNDims();
                    _FunctionsAdaptedToVnl = new FunctionsAdaptedToVnlType(nDims);
                    _FunctionsAdaptedToVnl->setFunctionsT1(this->_FunctionsT1);
                    _VnlFitter = new VnlFitterType(*_FunctionsAdaptedToVnl);
                }
                _FunctionsAdaptedToVnl->setFunctionsT1(this->_FunctionsT1);
                _VnlFitter->set_x_tolerance(this->getXTolerance());
                _VnlFitter->set_f_tolerance(this->getFTolerance());
                //m_LocalFitter->set_g_tolerance(this->GetGTolerance());
                _VnlFitter->set_max_iterations(this->getMaxFunctionEvals());
            }
        };

    private:

        VnlFitterType *_VnlFitter; // not meant to be see outside
        FunctionsAdaptedToVnlType *_FunctionsAdaptedToVnl; // not meant to be see outside

    };

} // namespace Ox

#endif //Tomato_OXFITTERAMOEBAVNL_H

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top