Logo ROOT  
Reference Guide
SequentialProposal.cxx
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Authors: Giovanni Petrucciani 4/21/2011
3/*************************************************************************
4 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11/** \class RooStats::SequentialProposal
12 \ingroup Roostats
13
14Class implementing a proposal function that samples the parameter space
15by moving only in one coordinate (chosen randomly) at each step
16*/
17
19#include <RooArgSet.h>
20#include <iostream>
21#include <memory>
22#include <TIterator.h>
23#include <RooRandom.h>
25
26using namespace std;
27
29
30namespace RooStats {
31
32////////////////////////////////////////////////////////////////////////////////
33
36 fDivisor(1./divisor)
37{
38}
39
40////////////////////////////////////////////////////////////////////////////////
41/// Populate xPrime with a new proposed point
42
44{
45 RooStats::SetParameters(&x, &xPrime);
46 RooLinkedListIter it(xPrime.iterator());
47 RooRealVar* var;
48 int n = xPrime.getSize();
49 int j = int( floor(RooRandom::uniform()*n) );
50 for (int i = 0; (var = (RooRealVar*)it.Next()) != NULL; ++i) {
51 if (i == j) {
52 double val = var->getVal(), max = var->getMax(), min = var->getMin(), len = max - min;
53 val += RooRandom::gaussian() * len * fDivisor;
54 while (val > max) val -= len;
55 while (val < min) val += len;
56 var->setVal(val);
57 //std::cout << "Proposing a step along " << var->GetName() << std::endl;
58 }
59 }
60}
61
62////////////////////////////////////////////////////////////////////////////////
63/// Return the probability of proposing the point x1 given the starting
64/// point x2
65
67 return true;
68}
69
71 RooArgSet& )
72{
73 return 1.0; // should not be needed
74}
75
76}
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
#define ClassImp(name)
Definition: Rtypes.h:365
double floor(double)
Int_t getSize() const
RooLinkedListIter iterator(Bool_t dir=kIterForward) const R__SUGGEST_ALTERNATIVE("begin()
TIterator-style iteration over contained elements.
virtual Double_t getMax(const char *name=0) const
Get maximum of currently defined range.
virtual Double_t getMin(const char *name=0) const
Get miniminum of currently defined range.
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:87
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
A wrapper around TIterator derivatives.
TObject * Next() override
static Double_t uniform(TRandom *generator=randomGenerator())
Return a number uniformly distributed from (0,1)
Definition: RooRandom.cxx:84
static Double_t gaussian(TRandom *generator=randomGenerator())
Return a Gaussian random variable with mean 0 and variance 1.
Definition: RooRandom.cxx:111
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:35
virtual void setVal(Double_t value)
Set value of variable to 'value'.
Definition: RooRealVar.cxx:278
ProposalFunction is an interface for all proposal functions that would be used with a Markov Chain Mo...
Class implementing a proposal function that samples the parameter space by moving only in one coordin...
virtual void Propose(RooArgSet &xPrime, RooArgSet &x)
Populate xPrime with a new proposed point.
virtual Bool_t IsSymmetric(RooArgSet &x1, RooArgSet &x2)
Determine whether or not the proposal density is symmetric for points x1 and x2 - that is,...
virtual Double_t GetProposalDensity(RooArgSet &x1, RooArgSet &x2)
Return the probability of proposing the point x1 given the starting point x2.
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16
Namespace for the RooStats classes.
Definition: Asimov.h:20
void SetParameters(const RooArgSet *desiredVals, RooArgSet *paramsToChange)
Definition: RooStatsUtils.h:64