Public Types | Public Member Functions | Protected Member Functions | Private Attributes | List of all members
ana::ConstrainedFitVarWithPrior Class Reference

Version of FitVarWithPrior for use with constrained FitVar_StanSupports. More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N21-01-16/CAFAna/Core/FitVarWithPrior.h"

Inheritance diagram for ana::ConstrainedFitVarWithPrior:
ana::StanFitSupport< IConstrainedFitVar > ana::IConstrainedFitVar ana::IFitVar

Public Types

typedef std::function< typename stan::math::var(const stan::math::var &, const osc::_IOscCalcAdjustable< stan::math::var > *)> PriorFnType
 

Public Member Functions

 ConstrainedFitVarWithPrior (const StanFitSupport< IConstrainedFitVar > *var, FitVarWithPrior::PriorFnType priorFn, const std::string &priorName)
 
double GetValue (const osc::IOscCalcAdjustable *osc) const override
 
stan::math::var GetValue (const osc::IOscCalcAdjustableStan *osc) const override
 
void SetValue (osc::IOscCalcAdjustable *osc, double val) const override
 
void SetValue (osc::IOscCalcAdjustableStan *osc, stan::math::var val) const override
 
stan::math::var LogPrior (const stan::math::var &val, const osc::_IOscCalcAdjustable< stan::math::var > *calc) const override
 
double LowLimit () const override
 
double HighLimit () const override
 
const std::stringPriorName () const
 
virtual stan::math::var Prior (const stan::math::var &var, const osc::IOscCalcAdjustableStan *calc) const
 
virtual stan::math::var LogPrior (const stan::math::var &var, const osc::IOscCalcAdjustableStan *calc) const
 
double Penalty (double val, osc::IOscCalcAdjustable *) const override
 Override the default implementation with one that pushes back towards the center of the constrained space. More...
 
const std::stringShortName () const
 
const std::stringLatexName () const
 

Protected Member Functions

template<typename T >
T Clamp (T val) const
 

Private Attributes

const StanFitSupport< IConstrainedFitVar > * fVar
 
PriorFnType fPriorFn
 
std::string fPriorFnName
 

Detailed Description

Version of FitVarWithPrior for use with constrained FitVar_StanSupports.

Definition at line 74 of file FitVarWithPrior.h.

Member Typedef Documentation

Definition at line 82 of file FitVarWithPrior.h.

Constructor & Destructor Documentation

ana::ConstrainedFitVarWithPrior::ConstrainedFitVarWithPrior ( const StanFitSupport< IConstrainedFitVar > *  var,
FitVarWithPrior::PriorFnType  priorFn,
const std::string priorName 
)
inline

Definition at line 85 of file FitVarWithPrior.h.

88  : StanFitSupport<IConstrainedFitVar>(dynamic_cast<const IFitVar*>(var)->ShortName() + "_" + priorName,
89  dynamic_cast<const IFitVar*>(var)->LatexName()),
90  fVar(var),
91  fPriorFn(priorFn),
92  fPriorFnName(priorName)
93  {}
const StanFitSupport< IConstrainedFitVar > * fVar
const std::string & LatexName() const
Definition: IFitVar.h:37
IFitVar(std::string shortName, std::string latexName)
Definition: IFitVar.h:19
const std::string & ShortName() const
Definition: IFitVar.h:36

Member Function Documentation

template<typename T >
T ana::IConstrainedFitVar::Clamp ( T  val) const
inlineprotectedinherited
double ana::ConstrainedFitVarWithPrior::GetValue ( const osc::IOscCalcAdjustable osc) const
inlineoverridevirtual
stan::math::var ana::ConstrainedFitVarWithPrior::GetValue ( const osc::IOscCalcAdjustableStan osc) const
inlineoverridevirtual

Implements ana::StanFitSupport< IConstrainedFitVar >.

Definition at line 99 of file FitVarWithPrior.h.

100  {
101  return fVar->GetValue(osc);
102  };
const StanFitSupport< IConstrainedFitVar > * fVar
virtual stan::math::var GetValue(const osc::IOscCalcAdjustableStan *osc) const =0
double ana::ConstrainedFitVarWithPrior::HighLimit ( ) const
inlineoverridevirtual

Implements ana::IConstrainedFitVar.

Definition at line 124 of file FitVarWithPrior.h.

125  {
126  return fVar->HighLimit();
127  };
const StanFitSupport< IConstrainedFitVar > * fVar
virtual double HighLimit() const =0
const std::string& ana::IFitVar::LatexName ( ) const
inlineinherited
virtual stan::math::var ana::StanFitSupport< IConstrainedFitVar >::LogPrior ( const stan::math::var var,
const osc::IOscCalcAdjustableStan calc 
) const
inlinevirtualinherited

Log of the prior probability density. Default implementation just does log(Prior()), but this can be overridden if there optimizations that speed up the calculation.

Definition at line 102 of file IFitVar.h.

102 {return StanLog(Prior(var, calc));}
virtual stan::math::var Prior(const stan::math::var &var, const osc::IOscCalcAdjustableStan *calc) const
Definition: IFitVar.h:98
stan::math::var StanLog(const stan::math::var &x)
Definition: IFitVar.cxx:30
stan::math::var ana::ConstrainedFitVarWithPrior::LogPrior ( const stan::math::var val,
const osc::_IOscCalcAdjustable< stan::math::var > *  calc 
) const
inlineoverride

Definition at line 114 of file FitVarWithPrior.h.

115  {
116  return fPriorFn(val, calc);
117  }
double ana::ConstrainedFitVarWithPrior::LowLimit ( ) const
inlineoverridevirtual

Implements ana::IConstrainedFitVar.

Definition at line 119 of file FitVarWithPrior.h.

120  {
121  return fVar->LowLimit();
122  };
const StanFitSupport< IConstrainedFitVar > * fVar
virtual double LowLimit() const =0
double ana::IConstrainedFitVar::Penalty ( double  val,
osc::IOscCalcAdjustable  
) const
overridevirtualinherited

Override the default implementation with one that pushes back towards the center of the constrained space.

Reimplemented from ana::IFitVar.

Definition at line 8 of file IFitVar.cxx.

References hi(), ana::IConstrainedFitVar::HighLimit(), lo(), ana::IConstrainedFitVar::LowLimit(), extractScale::mean, Munits::rad, and util::sqr().

Referenced by ana::SigmaDelta::SigmaPenalty().

10  {
11  const auto lo = LowLimit();
12  const auto hi = HighLimit();
13 
14  if (val >= lo && val <= hi) return 0;
15 
16  // Try to direct fit back towards centre of the space. Engineer penalty to
17  // be zero at the limits.
18  const auto mean = (lo + hi) / 2;
19  const auto rad = (hi - lo) / 2;
20  return util::sqr((val - mean) / rad) - 1;
21 
22 
23  // if(val < lo) return util::sqr(lo-val);
24  // if(val > hi) return util::sqr(val-hi);
25  // return 0;
26  }
virtual double HighLimit() const =0
TSpline3 lo("lo", xlo, ylo, 12,"0")
virtual double LowLimit() const =0
T sqr(T x)
More efficient square function than pow(x,2)
Definition: MathUtil.h:23
TSpline3 hi("hi", xhi, yhi, 18,"0")
static constexpr Double_t rad
Definition: Munits.h:162
virtual stan::math::var ana::StanFitSupport< IConstrainedFitVar >::Prior ( const stan::math::var var,
const osc::IOscCalcAdjustableStan calc 
) const
inlinevirtualinherited

The prior probability density distribution on this variable (which can depend on others if needed). If there are optimizations that can make log(Prior()) more expensive than a direct implementation, consider implementing LogPrior() directly instead.

Definition at line 98 of file IFitVar.h.

98 {return StanExp(LogPrior(var, calc));}
stan::math::var StanExp(const stan::math::var &x)
Definition: IFitVar.cxx:29
virtual stan::math::var LogPrior(const stan::math::var &var, const osc::IOscCalcAdjustableStan *calc) const
Definition: IFitVar.h:102
const std::string& ana::ConstrainedFitVarWithPrior::PriorName ( ) const
inline

Definition at line 129 of file FitVarWithPrior.h.

130  {
131  return fPriorFnName;
132  };
void ana::ConstrainedFitVarWithPrior::SetValue ( osc::IOscCalcAdjustable osc,
double  val 
) const
inlineoverridevirtual
void ana::ConstrainedFitVarWithPrior::SetValue ( osc::IOscCalcAdjustableStan osc,
stan::math::var  val 
) const
inlineoverridevirtual

Implements ana::StanFitSupport< IConstrainedFitVar >.

Definition at line 108 of file FitVarWithPrior.h.

109  {
110  fVar->SetValue(osc, val);
111  };
const StanFitSupport< IConstrainedFitVar > * fVar
virtual void SetValue(osc::IOscCalcAdjustableStan *osc, stan::math::var val) const =0
const std::string& ana::IFitVar::ShortName ( ) const
inlineinherited

Member Data Documentation

PriorFnType ana::ConstrainedFitVarWithPrior::fPriorFn
private

Definition at line 137 of file FitVarWithPrior.h.

std::string ana::ConstrainedFitVarWithPrior::fPriorFnName
private

Definition at line 139 of file FitVarWithPrior.h.

const StanFitSupport<IConstrainedFitVar>* ana::ConstrainedFitVarWithPrior::fVar
private

Definition at line 132 of file FitVarWithPrior.h.


The documentation for this class was generated from the following file: