//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Sim/Residual/VarianceFunctions.h
//! @brief     Defines class IVarianceFunctiones.
//!
//! @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)
//
//  ************************************************************************************************

#ifndef BORNAGAIN_SIM_RESIDUAL_VARIANCEFUNCTIONS_H
#define BORNAGAIN_SIM_RESIDUAL_VARIANCEFUNCTIONS_H


//! Variance function interface.

class VarianceFunction {
public:
    VarianceFunction() = default;
    virtual ~VarianceFunction() = default;
    VarianceFunction(const VarianceFunction&) = delete;
    VarianceFunction& operator=(const VarianceFunction&) = delete;

#ifndef SWIG
    virtual VarianceFunction* clone() const = 0;
#endif // SWIG

    virtual double variance(double real_value, double simulated_value) const = 0;
};

//! Returns 1.0 as variance value

class VarianceConstantFunction : public VarianceFunction {
#ifndef SWIG
public:
    VarianceConstantFunction* clone() const override;
#endif // SWIG
    double variance(double, double) const override;
};

//! Returns max(sim, epsilon)

class VarianceSimFunction : public VarianceFunction {
public:
    explicit VarianceSimFunction(double epsilon = 1.0);
    double variance(double exp, double sim) const override;

#ifndef SWIG
    VarianceSimFunction* clone() const override;
#endif // SWIG

private:
    double m_epsilon;
};

#endif // BORNAGAIN_SIM_RESIDUAL_VARIANCEFUNCTIONS_H
