|
| cdf = CDF(*args) |
| Transformation with the CDF.
|
|
| n_bins = n_bins |
| Binning in x, will be set automatically.
|
|
int | max = 0 |
| Maximum of the fitted distribution.
|
|
int | min = 0 |
| Minimum of the fitted distribution.
|
|
bool | is_processed = False |
| Status flag.
|
|
| name = name |
| Name of the class.
|
|
This transformation uses the CDF to transform input data to a
flat transformation.
Attributes
----------
cdf : Transform.CDF
Transformation with the CDF
Definition at line 235 of file transform.py.
◆ __init__()
__init__ |
( |
| self, |
|
|
* | args ) |
Init function
:param args: None
Definition at line 248 of file transform.py.
248 def __init__(self, *args):
249 """ Init function
250
251 :param args: None
252 """
253 Transform.__init__(self, "Flat", *args)
254
255
256 self.cdf = CDF(*args)
257
◆ __call__()
Call function calls transform
:param x: Input data
:return: Transformed data
Definition at line 95 of file transform.py.
95 def __call__(self, x):
96 """ Call function calls transform
97 :param x: Input data
98 :return: Transformed data
99 """
100 return self.transform(x)
101
◆ _fit()
_fit |
( |
| self, |
|
|
| x, |
|
|
| y = None ) |
|
protected |
Fit function calculates the cumulative distribution with numpy percentile.
:param x: Input distribution
:param y: Will not be used in this transformation
Reimplemented from Transform.
Definition at line 258 of file transform.py.
258 def _fit(self, x, y=None):
259 """
260 Fit function calculates the cumulative distribution with numpy percentile.
261
262 :param x: Input distribution
263 :param y: Will not be used in this transformation
264 """
265 self.io.debug("Fitting Flat")
266 self.cdf.fit(x)
267
◆ _initialise()
Sets limits for the data.
Not called by the user.
:param x: array type
Definition at line 71 of file transform.py.
71 def _initialise(self, x):
72 """
73 Sets limits for the data.
74 Not called by the user.
75
76 :param x: array type
77 """
78 self.io.debug("Initiating " + self.name)
79 if self.n_bins is None:
80 self.set_n_bins(len(x))
81 self.max = np.max(x)
82 self.min = np.min(x)
83
◆ _transform()
Transforms the input data according to the cdf.
:param x: Input data
:return: Transformed data
Reimplemented from Transform.
Definition at line 268 of file transform.py.
268 def _transform(self, x):
269 """
270 Transforms the input data according to the cdf.
271 :param x: Input data
272 :return: Transformed data
273 """
274 if not self.is_processed:
275 self.fit(x)
276 return self.cdf.transform(x)
277
◆ fit()
fit |
( |
| self, |
|
|
| x, |
|
|
| y = None ) |
|
inherited |
The fit function is calls the individual _fit() functions.
:param x: Distribution to fit, array type
:param y: optional for some transformations, sets signal class
Definition at line 84 of file transform.py.
84 def fit(self, x, y=None):
85 """
86 The fit function is calls the individual _fit() functions.
87
88 :param x: Distribution to fit, array type
89 :param y: optional for some transformations, sets signal class
90 """
91 self._initialise(x)
92 self._fit(x, y)
93 self.is_processed = True
94
◆ get_flat_bins()
Returns the binning of the CDF
:return: Binning for a flat distribution
Definition at line 278 of file transform.py.
278 def get_flat_bins(self):
279 """
280 Returns the binning of the CDF
281 :return: Binning for a flat distribution
282 """
283 return self.cdf.x
284
◆ get_x()
Dirty version for getting the original x value out of a flat x value.
:param x_flat: x value in the flat distribution
:return: x value on the original axis (approx)
Definition at line 285 of file transform.py.
285 def get_x(self, x_flat):
286 """
287 Dirty version for getting the original x value out of a flat x value.
288 :param x_flat: x value in the flat distribution
289 :return: x value on the original axis (approx)
290 """
291 x_cumul = np.linspace(self.min, self.max, self.n_bins * 50)
292 for xx in x_cumul:
293 if self.cdf.spline(xx) > x_flat:
294 return xx
◆ io()
Logging function
:return: logger
Definition at line 49 of file settings.py.
49 def io(self):
50 """
51 Logging function
52 :return: logger
53 """
54 return logging.getLogger(self.name)
55
56
◆ set_limits()
Limits the data to the fitted range.
:param x: Input data
:return: Limited data
Definition at line 139 of file transform.py.
139 def set_limits(self, x):
140 """
141 Limits the data to the fitted range.
142 :param x: Input data
143 :return: Limited data
144 """
145 try:
146 _ = len(x)
147 x[x > self.max] = self.max
148 x[x < self.min] = self.min
149 except TypeError:
150 if x < self.min:
151 x = self.min
152 if x > self.max:
153 x = self.max
154 return x
155
156
◆ set_n_bins()
Calculates the optimal size for the binning.
:param n: Length of the input data
Definition at line 131 of file transform.py.
131 def set_n_bins(self, n):
132 """
133 Calculates the optimal size for the binning.
134 :param n: Length of the input data
135 """
136 self.n_bins = get_optimal_bin_size(n)
137 self.io.debug("Bins are set to " + str(self.n_bins) + "\t " + str(n / float(self.n_bins)) + "per bin")
138
◆ transform()
transform |
( |
| self, |
|
|
| x, |
|
|
| set_limits = False ) |
|
inherited |
This is defined in the children and overwritten.
:param x: Distribution to transform, array type
:param set_limits: Limits the range of the data to the fitted range
:return: Transformed data
Definition at line 110 of file transform.py.
110 def transform(self, x, set_limits=False):
111 """
112 This is defined in the children and overwritten.
113 :param x: Distribution to transform, array type
114 :param set_limits: Limits the range of the data to the fitted range
115 :return: Transformed data
116 """
117 if set_limits:
118 self.set_limits(x)
119 return self._transform(x)
120
◆ cdf
◆ is_processed
bool is_processed = False |
|
inherited |
◆ max
Maximum of the fitted distribution.
Definition at line 58 of file transform.py.
◆ min
Minimum of the fitted distribution.
Definition at line 61 of file transform.py.
◆ n_bins
Binning in x, will be set automatically.
Definition at line 55 of file transform.py.
◆ name
The documentation for this class was generated from the following file: