ATLAS Offline Software
Loading...
Searching...
No Matches
python.samplers.DisjointUniformSampler Class Reference
Inheritance diagram for python.samplers.DisjointUniformSampler:
Collaboration diagram for python.samplers.DisjointUniformSampler:

Public Types

typedef HLT::TypeInformation::for_each_type_c< typenameEDMLIST::map, my_functor, my_result<>, my_arg< HLT::TypeInformation::get_cont, CONTAINER > >::type result

Public Member Functions

 __init__ (self, ranges)
 shoot (self)
 __call__ (self)

Protected Member Functions

 _getRanges (self)
 _setRanges (self, ranges)
 _map_unit_to_val (self, x)

Protected Attributes

 _ranges = ranges
 _totalwidth = sum(r[1] - r[0] for r in ranges)
list _divisions = [0.0]

Properties

 ranges = property(_getRanges, _setRanges)

Detailed Description

Definition at line 73 of file samplers.py.

Member Typedef Documentation

◆ result

Definition at line 90 of file EDM_MasterSearch.h.

Constructor & Destructor Documentation

◆ __init__()

python.samplers.DisjointUniformSampler.__init__ ( self,
ranges )
The ranges variable can either be a list of increasing numbers or a
list of pairs of numbers.

The former case will be treated as
defining alternating on/off ranges for sampling, starting with an active
one (i.e. it's a list of bin edges). The latter way specifically lists
the 'on' regions only, with their start and end values in the pairs.

The behaviour is undefined if the numbers are not ordered or overlap --
i.e. it might work but hasn't been designed that way and might change in
future. Don't rely on this behaviour!

Definition at line 76 of file samplers.py.

76 def __init__(self, ranges):
77 """
78 The ranges variable can either be a list of increasing numbers or a
79 list of pairs of numbers.
80
81 The former case will be treated as
82 defining alternating on/off ranges for sampling, starting with an active
83 one (i.e. it's a list of bin edges). The latter way specifically lists
84 the 'on' regions only, with their start and end values in the pairs.
85
86 The behaviour is undefined if the numbers are not ordered or overlap --
87 i.e. it might work but hasn't been designed that way and might change in
88 future. Don't rely on this behaviour!
89 """
90 if not ranges:
91 raise Exception("You must supply at least one non-null sampling range")
92 if hasattr(ranges[0], "__len__"):
93 assert all(len(x) == 2 for x in ranges)
94 self.ranges = ranges
95 else:
96 assert len(ranges) > 1
97 lows = [x for x in ranges[:-1]]
98 highs = [x for x in ranges[1:]]
99 myranges = []
100 for i, pair in enumerate(zip(lows, highs)):
101 if i % 2 == 0:
102 myranges.append(pair)
103 assert len(myranges) == len(ranges) // 2
104 self.ranges = myranges
105

Member Function Documentation

◆ __call__()

python.samplers.Sampler.__call__ ( self)
inherited
This is the call method that will actually be used (so that normal
functions can also be passed in as samplers).

Definition at line 17 of file samplers.py.

17 def __call__(self):
18 """This is the call method that will actually be used (so that normal
19 functions can also be passed in as samplers)."""
20 return self.shoot()
21

◆ _getRanges()

python.samplers.DisjointUniformSampler._getRanges ( self)
protected

Definition at line 106 of file samplers.py.

106 def _getRanges(self):
107 return self._ranges
108

◆ _map_unit_to_val()

python.samplers.DisjointUniformSampler._map_unit_to_val ( self,
x )
protected

Definition at line 126 of file samplers.py.

126 def _map_unit_to_val(self, x):
127 assert(x >= 0 and x <= 1)
128 idx = None
129 rem = None
130 for i in range(len(self._divisions) - 1):
131 if x >= self._divisions[i] and x < self._divisions[i+1]:
132 idx = i
133 rem = x - self._divisions[i]
134 break
135 if idx is None:
136 raise ValueError("No matching division found in unit interval! How?")
137 val = self.ranges[idx][0] + self._totalwidth * rem
138 return val
139

◆ _setRanges()

python.samplers.DisjointUniformSampler._setRanges ( self,
ranges )
protected

Definition at line 109 of file samplers.py.

109 def _setRanges(self, ranges):
110 # TODO: Check that ranges don't overlap
111 self._ranges = ranges
112 self._totalwidth = sum(r[1] - r[0] for r in ranges)
113
114 runningwidth = 0.0
115 self._divisions = [0.0]
116 for r in ranges:
117 assert(r[1] >= r[0])
118 runningwidth += float(r[1] - r[0])
119 self._divisions.append(runningwidth)
120 self._totalwidth = runningwidth
121 for i in range(len(self._divisions)):
122 self._divisions[i] = float(self._divisions[i]) / float(self._totalwidth)
123

◆ shoot()

python.samplers.DisjointUniformSampler.shoot ( self)

Reimplemented from python.samplers.Sampler.

Definition at line 140 of file samplers.py.

140 def shoot(self):
141 rand = random.random()
142 val = self._map_unit_to_val(rand)
143 return val
144
145

Member Data Documentation

◆ _divisions

python.samplers.DisjointUniformSampler._divisions = [0.0]
protected

Definition at line 115 of file samplers.py.

◆ _ranges

python.samplers.DisjointUniformSampler._ranges = ranges
protected

Definition at line 111 of file samplers.py.

◆ _totalwidth

python.samplers.DisjointUniformSampler._totalwidth = sum(r[1] - r[0] for r in ranges)
protected

Definition at line 112 of file samplers.py.

Property Documentation

◆ ranges

python.samplers.DisjointUniformSampler.ranges = property(_getRanges, _setRanges)
static

Definition at line 124 of file samplers.py.


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