Skip to content

Commit d2c5124

Browse files
committed
doc of normalizer
1 parent acf911f commit d2c5124

1 file changed

Lines changed: 63 additions & 3 deletions

File tree

pclines/accumulator.py

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,79 @@ def _validate_bbox(bbox):
6464

6565
class Normalizer:
6666
"""
67-
Range mapping
67+
Linear mapping of ranges
68+
69+
The class maps values from source range (a,b) to a destination
70+
range (c,d) by scaling and offset.
71+
72+
The `transform` then maps a to c and b to d. The `inverse`
73+
then does inverse transform.
6874
"""
6975
def __init__(self, src_range, dst_range=(0,1)):
76+
"""
77+
Inputs
78+
------
79+
src_range, dst_range: tuple
80+
A tuple with two values [a, b] of source and destination ranges
81+
82+
Example
83+
-------
84+
>> T = Normalizer((0,10), (1,-1))
85+
>> T.transform(10)
86+
-1
87+
>> T.transform(6)
88+
-0.2
89+
>> T.inverse(-1)
90+
10
91+
"""
7092
# TODO: check ranges
7193
self.w, self.b = _linear_transform(src_range, dst_range)
7294
self.wi, self.bi = _linear_transform(dst_range, src_range)
7395

7496
def transform(self, x):
75-
""" src -> dst mapping of x """
97+
""" src -> dst mapping of x
98+
99+
Transforms values of x from source range to destination range.
100+
101+
Inputs
102+
------
103+
x : ndarray
104+
values to transform
105+
106+
Outputs
107+
-------
108+
y : ndarray
109+
Transformed x
110+
111+
Example
112+
-------
113+
>> T = Normalizer((0, 100), (0, 1))
114+
>> T(50)
115+
0.5
116+
"""
76117
return self.w * x + self.b
77118

78119
def inverse(self, x):
79-
""" dst -> src mapping of x """
120+
""" dst -> src mapping of x
121+
122+
Transforms values of x from destination range to the source range.
123+
124+
Inputs
125+
------
126+
x : ndarray
127+
values to transform
128+
129+
Outputs
130+
-------
131+
y : ndarray
132+
Transformed x
133+
134+
Example
135+
-------
136+
>> T = Normalizer((0, 100), (0, 1))
137+
>> T(0.5)
138+
50
139+
"""
80140
return self.wi * x + self.bi
81141

82142
__call__ = transform

0 commit comments

Comments
 (0)