Public Types | Public Member Functions | Private Attributes | List of all members
ana::FitVarWithPrior Class Referenceabstract

A convenience FitVar_StanSupport that wraps a pre-existing FitVar_StanSupport with a function you specify (enables re-use of functions) More...

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

Inheritance diagram for ana::FitVarWithPrior:
ana::StanFitSupport< IFitVar > ana::IFitVar

Public Types

typedef std::function< typename stan::math::var(stan::math::var, const osc::_IOscCalcAdjustable< stan::math::var > *)> PriorFnType
 Function that will return the log of the value of the prior density for a given parameter. More...
 

Public Member Functions

 FitVarWithPrior (const StanFitSupport< IFitVar > *var, PriorFnType priorFn, const std::string &priorName)
 Constructor. Ensure that var doesn't go out of scope before this object does! More...
 
double GetValue (const osc::IOscCalcAdjustable *osc) const override
 Forward to wrapped Var's GetValue() More...
 
stan::math::var GetValue (const osc::_IOscCalcAdjustable< stan::math::var > *osc) const override
 
void SetValue (osc::IOscCalcAdjustable *osc, double val) const override
 Forward to wrapped Var's SetValue() More...
 
void SetValue (osc::_IOscCalcAdjustable< stan::math::var > *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
 Implement calculation of log-prior by forwarding to stored function. More...
 
virtual stan::math::var GetValue (const osc::IOscCalcAdjustableStan *osc) const =0
 
virtual void SetValue (osc::IOscCalcAdjustableStan *osc, stan::math::var val) const =0
 
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
 
virtual double Penalty (double, osc::IOscCalcAdjustable *) const
 
const std::stringShortName () const
 
const std::stringLatexName () const
 

Private Attributes

const StanFitSupport< IFitVar > * fVar
 
PriorFnType fPriorFn
 

Detailed Description

A convenience FitVar_StanSupport that wraps a pre-existing FitVar_StanSupport with a function you specify (enables re-use of functions)

Warning: the function you pass as a prior must be normalizable (i.e., finite integral) when multiplied by the likelihood over the domain of your Var. This class can't check for you (the MCMC is going to explore that space); if your prior*likelihood isn't normalizable, you are likely to get unexpected results.

Definition at line 20 of file FitVarWithPrior.h.

Member Typedef Documentation

Function that will return the log of the value of the prior density for a given parameter.

Definition at line 28 of file FitVarWithPrior.h.

Constructor & Destructor Documentation

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

Constructor. Ensure that var doesn't go out of scope before this object does!

Definition at line 32 of file FitVarWithPrior.h.

35  : StanFitSupport<IFitVar>(dynamic_cast<const IFitVar*>(var)->ShortName() + "_" + priorName,
36  dynamic_cast<const IFitVar*>(var)->LatexName()),
37  fVar(var), fPriorFn(priorFn)
38  {}
const std::string & LatexName() const
Definition: IFitVar.h:38
IFitVar(std::string shortName, std::string latexName)
Definition: IFitVar.h:20
var_value< double > var
Definition: StanTypedefs.h:14
const StanFitSupport< IFitVar > * fVar
const std::string & ShortName() const
Definition: IFitVar.h:37

Member Function Documentation

double ana::FitVarWithPrior::GetValue ( const osc::IOscCalcAdjustable osc) const
inlineoverridevirtual
stan::math::var ana::FitVarWithPrior::GetValue ( const osc::_IOscCalcAdjustable< stan::math::var > *  osc) const
inlineoverride

Definition at line 45 of file FitVarWithPrior.h.

46  {
47  return fVar->GetValue(osc);
48  };
virtual stan::math::var GetValue(const osc::IOscCalcAdjustableStan *osc) const =0
const StanFitSupport< IFitVar > * fVar
virtual stan::math::var ana::StanFitSupport< IFitVar >::GetValue ( const osc::IOscCalcAdjustableStan osc) const
pure virtualinherited

Implemented in ana::FitDeltaInPiUnits.

const std::string& ana::IFitVar::LatexName ( ) const
inlineinherited
stan::math::var ana::FitVarWithPrior::LogPrior ( const stan::math::var val,
const osc::_IOscCalcAdjustable< stan::math::var > *  calc 
) const
inlineoverride

Implement calculation of log-prior by forwarding to stored function.

Definition at line 62 of file FitVarWithPrior.h.

63  {
64  return fPriorFn(val, calc);
65  }
virtual stan::math::var ana::StanFitSupport< IFitVar >::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 103 of file IFitVar.h.

103 {return StanLog(Prior(var, calc));}
var_value< double > var
Definition: StanTypedefs.h:14
virtual stan::math::var Prior(const stan::math::var &var, const osc::IOscCalcAdjustableStan *calc) const
Definition: IFitVar.h:99
stan::math::var StanLog(const stan::math::var &x)
Definition: IFitVar.cxx:30
virtual double ana::IFitVar::Penalty ( double  ,
osc::IOscCalcAdjustable  
) const
inlinevirtualinherited

Reimplemented in ana::FitDeltaCPT, ana::FitSigmaCPT, and ana::IConstrainedFitVar.

Definition at line 35 of file IFitVar.h.

Referenced by ana::FrequentistSurface::FillSurface().

35 {return 0;}
virtual stan::math::var ana::StanFitSupport< IFitVar >::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 99 of file IFitVar.h.

99 {return StanExp(LogPrior(var, calc));}
var_value< double > var
Definition: StanTypedefs.h:14
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:103
void ana::FitVarWithPrior::SetValue ( osc::IOscCalcAdjustable osc,
double  val 
) const
inlineoverridevirtual
void ana::FitVarWithPrior::SetValue ( osc::_IOscCalcAdjustable< stan::math::var > *  osc,
stan::math::var  val 
) const
inlineoverride

Definition at line 55 of file FitVarWithPrior.h.

56  {
57  fVar->SetValue(osc, val);
58  };
virtual void SetValue(osc::IOscCalcAdjustableStan *osc, stan::math::var val) const =0
const StanFitSupport< IFitVar > * fVar
virtual void ana::StanFitSupport< IFitVar >::SetValue ( osc::IOscCalcAdjustableStan osc,
stan::math::var  val 
) const
pure virtualinherited

Implemented in ana::FitDeltaInPiUnits.

const std::string& ana::IFitVar::ShortName ( ) const
inlineinherited

Member Data Documentation

PriorFnType ana::FitVarWithPrior::fPriorFn
private

Definition at line 70 of file FitVarWithPrior.h.

const StanFitSupport<IFitVar>* ana::FitVarWithPrior::fVar
private

Definition at line 68 of file FitVarWithPrior.h.


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