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
  • /
  • OxFitter.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:2379e02a78480f9074958557453ac6b1295656cf
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 ...
OxFitter.h
/*!
 * \file OxFitter.h
 * \author Konrad Werys
 * \date 2018/07/29
 */

#ifndef Tomato_OXFITTER_H
#define Tomato_OXFITTER_H

#include "OxFunctionsT1.h"
#include "KWUtil.h"

namespace Ox {

    /**
     * \class Fitter
     * \brief
     * \details
     * @tparam MeasureType
     */
    template< typename MeasureType >
    class Fitter{

    public:

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

        virtual const FunctionsT1<MeasureType>* getFunctionsT1() const { return _FunctionsT1; }
        virtual MeasureType *getParameters() { return _Parameters; }
        virtual const MeasureType getXTolerance() const { return _XTolerance; }
        virtual const MeasureType getFTolerance() const { return _FTolerance; }
        virtual const bool getUseGradient() const { return _UseGradient; }
        virtual const unsigned int getMaxFunctionEvals() const { return _MaxFunctionEvals; }
        virtual const unsigned int getThreadId() const { return _ThreadId; }
        virtual const bool getVerbose() const { return _Verbose; }
        virtual const bool getTrace() const { return _Trace; }

        virtual void setFunctionsT1(FunctionsT1<MeasureType>* _FunctionsT1) { Fitter::_FunctionsT1 = _FunctionsT1; }
        virtual void setParameters( MeasureType *_Parameters) { Fitter::_Parameters = _Parameters; }
        virtual void setXTolerance(const MeasureType _XTolerance) { Fitter::_XTolerance = _XTolerance; }
        virtual void setUseGradient(const bool _UseGradient) { Fitter::_UseGradient = _UseGradient; }
        virtual void setFTolerance(const MeasureType _FTolerance) { Fitter::_FTolerance = _FTolerance; }
        virtual void setMaxFunctionEvals(const unsigned int _MaxFunctionEvals) { Fitter::_MaxFunctionEvals = _MaxFunctionEvals; }
        virtual void setThreadId(const unsigned int _ThreadId) { Fitter::_ThreadId = _ThreadId; }
        virtual void setVerbose(const bool _Verbose) { Fitter::_Verbose = _Verbose; }
        virtual void setTrace(const bool _Trace) { Fitter::_Trace = _Trace; }

        /**
         * copy from ptrFrom to the parameters. Parameters have to be allocated first
         * @param ptrFrom
         */
        virtual void copyToParameters(const MeasureType *ptrFrom){
            if (!Fitter::_FunctionsT1) {
                throw std::runtime_error("_FunctionsT1 equals 0. Set _FunctionsT1");
            }

            if (!_Parameters){
                throw std::runtime_error("_Parameters equals 0. Set _Parameters");
            }

            for (int i = 0; i < Fitter::_FunctionsT1->getNDims(); ++i) {
                _Parameters[i] = ptrFrom[i];
            }
        }

        /**
         * \brief show me your Fitter
         */
        virtual void disp(){
            std::cout << "\nYou called disp() on a Fitter object " << this << "\n";
            KWUtil::printArray((bool)_Parameters, _FunctionsT1->getNDims(), _Parameters,     (char*)"\nParameters:  ");
            std::cout << "XTolerance:       " << getXTolerance() << std::endl;
            std::cout << "FTolerance:       " << getFTolerance() << std::endl;
            std::string temp = getUseGradient() ? "true" : "false";
            std::cout << "UseGradient       " << temp << std::endl;
            std::cout << "MaxFunctionEvals: " << getMaxFunctionEvals() << std::endl;
            std::cout << "ThreadId:         " << getThreadId() << std::endl;
            if(_FunctionsT1) {
                std::cout << "This Fitter contains the following FunctionsT1 object: ";
                _FunctionsT1->disp();
            };
        }

        /**
         * \brief constructor
         */
        Fitter(){
            _FunctionsT1 = 0; //nullpointer
            _Parameters = 0; //nullpointer

            _XTolerance = 1e-12;
            _FTolerance = 1e-12;
            _MaxFunctionEvals = 4000;
            _UseGradient = false;
            _ThreadId = 0;
            _Verbose = false;
            _Trace = false;
        }

        /**
         * copy constructor
         * @param old
         */
        Fitter(const Fitter &old) {
            _FunctionsT1 = 0; //nullpointer

            _XTolerance = old._XTolerance;
            _FTolerance = old._FTolerance;
            _MaxFunctionEvals = old._MaxFunctionEvals;
            _UseGradient = old._UseGradient;
            _ThreadId = old._ThreadId;
            _Verbose = old._Verbose;
            _Trace = old._Trace;
        }

        /**
         * cloning
         * @return
         */
        virtual Fitter<MeasureType> *newByCloning() = 0;

        /**
         * \brief do not forget about the virtual destructor, see
         * https://stackoverflow.com/questions/461203/when-to-use-virtual-destructors
         */
        virtual ~Fitter(){};

    protected:
        FunctionsT1<MeasureType>* _FunctionsT1;
        MeasureType* _Parameters;

        MeasureType _XTolerance;
        MeasureType _FTolerance;
        unsigned int _MaxFunctionEvals;
        bool _UseGradient;
        unsigned int _ThreadId;
        bool _Verbose;
        bool _Trace;

    };
} //namespace Ox

#endif //Tomato_OXFITTER_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