Belle II Software development
Transform Class Reference
Inheritance diagram for Transform:
ProTool CDF ToFlat

Public Member Functions

def __init__ (self, name="Original", n_bins=None)
 
def fit (self, x, y=None)
 
def __call__ (self, x)
 
def transform (self, x, set_limits=False)
 
def set_n_bins (self, n)
 
def set_limits (self, x)
 

Public Attributes

 n_bins
 Binning in x, will be set automatically.
 
 max
 Maximum of the fitted distribution.
 
 min
 Minimum of the fitted distribution.
 
 is_processed
 Status flag.
 
 name
 Name of the transformation.
 

Protected Member Functions

def _initialise (self, x)
 
def _fit (self, x, y=None)
 
def _transform (self, x)
 

Detailed Description

Base Class for the transformations.
The function _fit() is overwritten by the sub classes.

Attributes
----------
n_bins : int, optional
    Binning in x, will be set automatically
max : float
    Maximum of the fitted distribution
min : float
    Minimum of the fitted distribution
is_processed : bool
    Status flag
name : str
    Name of the transformation

Definition at line 27 of file transform.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  name = "Original",
  n_bins = None 
)
 Init function

:param name:    Name
:param n_bins:  Binning for the transformations

Reimplemented from ProTool.

Reimplemented in CDF, and ToFlat.

Definition at line 48 of file transform.py.

48 def __init__(self, name="Original", n_bins=None):
49 """ Init function
50
51 :param name: Name
52 :param n_bins: Binning for the transformations
53 """
54
55 self.n_bins = n_bins
56
57
58 self.max = 0
59
60
61 self.min = 0
62
63
64 self.is_processed = False
65
66
67 self.name = name
68
69 ProTool.__init__(self, "Transform." + self.name)
70

Member Function Documentation

◆ __call__()

def __call__ (   self,
  x 
)
 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()

def _fit (   self,
  x,
  y = None 
)
protected
This is defined in the children and overwritten.
:param x:   array x values
:param y:   class variable [1,0]

Reimplemented in CDF, and ToFlat.

Definition at line 102 of file transform.py.

102 def _fit(self, x, y=None):
103 """
104 This is defined in the children and overwritten.
105 :param x: array x values
106 :param y: class variable [1,0]
107
108 """
109

◆ _initialise()

def _initialise (   self,
  x 
)
protected
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()

def _transform (   self,
  x 
)
protected
This is defined in the children and overwritten.
In the base class it does nothing and returns the original distribution.

:param x:   Distribution to transform, array type
:return:    Transformed data

Reimplemented in CDF, and ToFlat.

Definition at line 121 of file transform.py.

121 def _transform(self, x):
122 """
123 This is defined in the children and overwritten.
124 In the base class it does nothing and returns the original distribution.
125
126 :param x: Distribution to transform, array type
127 :return: Transformed data
128 """
129 return x
130

◆ fit()

def fit (   self,
  x,
  y = None 
)
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

◆ set_limits()

def set_limits (   self,
  x 
)
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) # to catch exception
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()

def set_n_bins (   self,
  n 
)
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()

def transform (   self,
  x,
  set_limits = False 
)
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

Member Data Documentation

◆ is_processed

is_processed

Status flag.

Definition at line 64 of file transform.py.

◆ max

max

Maximum of the fitted distribution.

Definition at line 58 of file transform.py.

◆ min

min

Minimum of the fitted distribution.

Definition at line 61 of file transform.py.

◆ n_bins

n_bins

Binning in x, will be set automatically.

Definition at line 55 of file transform.py.

◆ name

name

Name of the transformation.

Definition at line 67 of file transform.py.


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