Logo ROOT   6.08/07
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 
13 #include <RooArgSet.h>
14 #include <iostream>
15 #include <memory>
16 #include <TIterator.h>
17 #include <RooRandom.h>
18 #include <RooStats/RooStatsUtils.h>
19 
20 using namespace std;
21 
23 
24 namespace RooStats {
25 
26 SequentialProposal::SequentialProposal(double divisor) :
28  fDivisor(1./divisor)
29 {
30 }
31 
32 
33 // Populate xPrime with a new proposed point
35 {
36  RooStats::SetParameters(&x, &xPrime);
37  RooLinkedListIter it(xPrime.iterator());
38  RooRealVar* var;
39  int n = xPrime.getSize();
40  int j = int( floor(RooRandom::uniform()*n) );
41  for (int i = 0; (var = (RooRealVar*)it.Next()) != NULL; ++i) {
42  if (i == j) {
43  double val = var->getVal(), max = var->getMax(), min = var->getMin(), len = max - min;
44  val += RooRandom::gaussian() * len * fDivisor;
45  while (val > max) val -= len;
46  while (val < min) val += len;
47  var->setVal(val);
48  //std::cout << "Proposing a step along " << var->GetName() << std::endl;
49  }
50  }
51 }
52 
54  return true;
55 }
56 
57 // Return the probability of proposing the point x1 given the starting
58 // point x2
60  RooArgSet& )
61 {
62  return 1.0; // should not be needed
63 }
64 
65 }
66 
ProposalFunction is an interface for all proposal functions that would be used with a Markov Chain Mo...
static Double_t gaussian(TRandom *generator=randomGenerator())
Return a Gaussian random variable with mean 0 and variance 1.
Definition: RooRandom.cxx:111
virtual Double_t GetProposalDensity(RooArgSet &x1, RooArgSet &x2)
Return the probability of proposing the point x1 given the starting point x2.
void SetParameters(const RooArgSet *desiredVals, RooArgSet *paramsToChange)
Definition: RooStatsUtils.h:69
bool Bool_t
Definition: RtypesCore.h:59
STL namespace.
Double_t x[n]
Definition: legend1.C:17
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
Int_t getSize() const
Class implementing a proposal function that samples the parameter space by moving only in one coordin...
double floor(double)
Namespace for the RooStats classes.
Definition: Asimov.h:20
#define ClassImp(name)
Definition: Rtypes.h:279
static Double_t uniform(TRandom *generator=randomGenerator())
Return a number uniformly distributed from (0,1)
Definition: RooRandom.cxx:84
double Double_t
Definition: RtypesCore.h:55
virtual void Propose(RooArgSet &xPrime, RooArgSet &x)
Populate xPrime with a new proposed point.
RooLinkedListIter iterator(Bool_t dir=kIterForward) const
#define NULL
Definition: Rtypes.h:82
const Int_t n
Definition: legend1.C:16
RooLinkedListIter is the TIterator implementation for RooLinkedList.
virtual Bool_t IsSymmetric(RooArgSet &x1, RooArgSet &x2)
Determine whether or not the proposal density is symmetric for points x1 and x2 - that is...