71 MetropolisHastings::MetropolisHastings()
87 fFunction = &
function;
89 SetProposalFunction(proposalFunction);
100 if (fParameters.getSize() == 0 || !fPropFunc || !fFunction) {
101 coutE(
Eval) <<
"Critical members unintialized: parameters, proposal " <<
102 " function, or (log) likelihood function" << endl;
105 if (fSign == kSignUnset ||
fType == kTypeUnset) {
106 coutE(
Eval) <<
"Please set type and sign of your function using " 107 <<
"MetropolisHastings::SetType() and MetropolisHastings::SetSign()" <<
112 if (fChainParams.getSize() == 0) fChainParams.add(fParameters);
126 Double_t xL = 0.0, xPrimeL = 0.0,
a = 0.0;
143 bool hadEvalError =
true;
153 while (i < 1000 && hadEvalError) {
156 xL = fFunction->getVal();
163 hadEvalError =
false;
164 }
else if (
fType == kRegular) {
168 hadEvalError =
false;
171 hadEvalError =
false;
175 coutE(
Eval) <<
"Problem finding a good starting point in " <<
176 "MetropolisHastings::ConstructChain() " << endl;
183 for (i = 0; i < fNumIters; i++) {
185 hadEvalError =
false;
190 fPropFunc->Propose(xPrime, x);
193 xPrimeL = fFunction->getVal();
196 if (fFunction->numEvalErrors() > 0 &&
fType == kLog) {
198 fFunction->clearEvalErrorLog();
208 if (fSign == kPositive)
217 if (!hadEvalError && !fPropFunc->IsSymmetric(xPrime, x)) {
218 Double_t xPrimePD = fPropFunc->GetProposalDensity(xPrime, x);
219 Double_t xPD = fPropFunc->GetProposalDensity(x, xPrime);
220 if (
fType == kRegular)
226 if (!hadEvalError && ShouldTakeStep(
a)) {
251 coutI(
Eval) <<
"Proposal acceptance rate: " <<
252 numAccepted/(
Float_t)fNumIters * 100 <<
"%" << endl;
253 coutI(
Eval) <<
"Number of steps in chain: " << numAccepted << endl;
266 if ((
fType == kLog && a <= 0.0) || (
fType == kRegular && a >= 1.0)) {
280 if (-1.0 * rand >= a)
302 if (fSign == kNegative)
307 if (fSign == kPositive)
ProposalFunction is an interface for all proposal functions that would be used with a Markov Chain Mo...
void SetParameters(const RooArgSet *desiredVals, RooArgSet *paramsToChange)
RooFit::MsgLevel globalKillBelow() const
static void clearEvalErrorLog()
Clear the stack of evaluation error messages.
virtual Int_t Size() const
get the number of steps in the chain
static RooMsgService & instance()
Return reference to singleton instance.
This class uses the Metropolis-Hastings algorithm to construct a Markov Chain of data points using Mo...
static void setEvalErrorLoggingMode(ErrorLoggingMode m)
Set evaluation error logging mode.
void SetParameters(TFitEditor::FuncParams_t &pars, TF1 *func)
Restore the parameters from pars into the function.
virtual void Add(RooArgSet &entry, Double_t nllValue, Double_t weight=1.0)
safely add an entry to the chain
virtual void addClone(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling addOwned() for each element in the source...
static Int_t numEvalErrors()
Return the number of logged evaluation errors since the last clearing.
static Double_t infinity()
Return internal infinity representation.
void setGlobalKillBelow(RooFit::MsgLevel level)
void RandomizeCollection(RooAbsCollection &set, Bool_t randomizeConstants=kTRUE)
Stores the steps in a Markov Chain of points.
Namespace for the RooStats classes.
static Double_t uniform(TRandom *generator=randomGenerator())
Return a number uniformly distributed from (0,1)
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
virtual void SetParameters(RooArgSet ¶meters)
set which of your parameters this chain should store
Mother of all ROOT objects.