geometric_compression
Bases: transformation
The geometric patch based compression function.
It performs the data compression based on geometric patch shapes and provided compression metric. This class inherits from the base data transformation class, and also implements the abstract methods in that class.
...
Notes
Formally, given a data instance \(\mathbf{x}\) and its underlying grid structure, we can extract a set of patches denoted as \(\mathcal{P} = \{{p}_1, {p}_2, \cdots {p}_{|\mathcal{P}|}\}\). For simplicity, we use the notation \(\mathbf{p}_i = \mathbf{x}(p_i) \in {R}^p\) to represent the attribute elements covered by patch \({p}_i \in \mathcal{P}\) from the input data instance vector \(\mathbf{x}\).
The geometric compression function proposes to compress the patch vector \(\mathbf{p}_i\) using a mapping \(\phi: {R}^p \to {R}^{d_{\phi}}\), which transforms it into a dense representation of length \(d_{\phi}\) as follows:
\[ \begin{equation} \kappa(\mathbf{x}) = \left[ \phi(\mathbf{p}_1), \phi(\mathbf{p}_2), \cdots, \phi(\mathbf{p}_{|\mathcal{P}|}) \right] \in {R}^{d}, \end{equation} \]
where the compression output vector dimension is \(d = |\mathcal{P}| \times d_{\phi}\). The dimension parameter \(d_{\phi}\) must be manually specified when defining the patch vector compression mapping \(\phi\). For the majority of mappings \(\phi\) studied in this project, the output is typically a scalar, i.e., the dimension \(d_{\phi} = 1\).
The patches in set \(\mathcal{P}\) can have different shapes, such as cuboid, cylinder and sphere. The compression metric \(\phi\) can also have different definitions, such as max, min and mean.
Attributes:
Name | Type | Description |
---|---|---|
metric |
Callable[[Tensor], Tensor]
|
The geometric compression metric. |
name |
str, default = 'geometric_compression'
|
Name of the compression function. |
grid |
grid, default = None
|
The input data instance underlying grid structure. |
grid_configs |
dict, default = None
|
The grid detailed configurations. |
h |
int, default = None
|
The height of the grid structure. |
w |
int, default = None
|
The width of the grid structure. |
d |
int, default = None
|
The depth of the grid structure. |
patch |
Union[cuboid, cylinder, sphere], default = None
|
The patch shape of the data segments to be compressed. |
patch_configs |
dict, default = None
|
The patch detailed configurations. |
packing_strategy |
str, default = None
|
The packing strategy to be used. |
cd_h |
int, default = None
|
The patch center distance along the height dimension. |
cd_w |
int, default = None
|
The patch center distance along the width dimension. |
cd_d |
int, default = None
|
The patch center distance along the depth dimension. |
Methods:
Name | Description |
---|---|
__init__ |
It performs the initialization of the compression function. |
get_grid_shape |
It returns the shape of the grid structure. |
get_grid_size |
It returns the size of the grid structure. |
get_patch_size |
It returns the size of the patch structure. |
get_patch_num |
It returns the number of patches in the input data vector. |
get_grid_shape_after_packing |
It returns the shape of the grid structure after packing, i.e., the patch center coordinates. |
calculate_D |
It calculates the compression space dimension d based on the input dimension parameter m. |
forward |
It implements the abstract forward method declared in the base transformation class. |
Source code in tinybig/compression/geometric_compression.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
__init__(metric, name='geometric_compression', grid=None, grid_configs=None, h=None, w=None, d=None, patch=None, patch_configs=None, packing_strategy=None, cd_h=None, cd_w=None, cd_d=None, *args, **kwargs)
The initialization method of the geometric compression function.
It initializes the geometric compression function based on the provided geometric grid (or its configuration or its size) and the patch shape (or the patch configuration) of the data segments to be compressed, and the packing strategy (or the patch center distances).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metric
|
Callable[[Tensor], Tensor]
|
The geometric compression metric. |
required |
name
|
str
|
Name of the compression function. |
'geometric_compression'
|
grid
|
grid
|
The input data instance underlying grid structure. |
None
|
grid_configs
|
dict
|
The grid detailed configurations. |
None
|
h
|
int
|
The height of the grid structure. |
None
|
w
|
int
|
The width of the grid structure. |
None
|
d
|
int
|
The depth of the grid structure. |
None
|
patch
|
Union[cuboid, cylinder, sphere]
|
The patch shape of the data segments to be compressed. |
None
|
patch_configs
|
dict
|
The patch detailed configurations. |
None
|
packing_strategy
|
str
|
The packing strategy to be used. |
None
|
cd_h
|
int
|
The patch center distance along the height dimension. |
None
|
cd_w
|
int
|
The patch center distance along the width dimension. |
None
|
cd_d
|
int
|
The patch center distance along the depth dimension. |
None
|
Returns:
Type | Description |
---|---|
transformation
|
The geometric compression function. |
Source code in tinybig/compression/geometric_compression.py
calculate_D(m)
The compression dimension calculation method.
It calculates the intermediate compression space dimension based on the input dimension parameter m. For the geometric compression function, the compression space dimension is determined by the grid shape, patch shape and packing strategy.
The compression output vector dimension is \(d = |\mathcal{P}| \times d_{\phi}\), where \(\mathcal{P}\) is the patch set in the input and \(d_{\phi}\) denotes the compression output dimension of the metric \(\phi\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
int
|
The dimension of the input space. |
required |
Returns:
Type | Description |
---|---|
int
|
The dimension of the compression space. |
Source code in tinybig/compression/geometric_compression.py
forward(x, device='cpu', *args, **kwargs)
The forward method of the geometric compression function.
It performs the geometric data compression of the input data and returns the compression result.
Formally, given a data instance \(\mathbf{x}\) and its underlying grid structure, we can extract a set of patches denoted as \(\mathcal{P} = \{{p}_1, {p}_2, \cdots {p}_{|\mathcal{P}|}\}\). For simplicity, we use the notation \(\mathbf{p}_i = \mathbf{x}(p_i) \in {R}^p\) to represent the attribute elements covered by patch \({p}_i \in \mathcal{P}\) from the input data instance vector \(\mathbf{x}\).
The geometric compression function proposes to compress the patch vector \(\mathbf{p}_i\) using a mapping \(\phi: {R}^p \to {R}^{d_{\phi}}\), which transforms it into a dense representation of length \(d_{\phi}\) as follows:
\[ \begin{equation} \kappa(\mathbf{x}) = \left[ \phi(\mathbf{p}_1), \phi(\mathbf{p}_2), \cdots, \phi(\mathbf{p}_{|\mathcal{P}|}) \right] \in {R}^{d}, \end{equation} \]
where the compression output vector dimension is \(d = |\mathcal{P}| \times d_{\phi}\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
The input data vector. |
required |
device
|
str
|
The device of the input data vector. |
'cpu'
|
Returns:
Type | Description |
---|---|
Tensor
|
The compression result. |
Source code in tinybig/compression/geometric_compression.py
get_grid_shape()
The grid shape retrieval function.
It returns the shape of the grid structure.
Returns:
Type | Description |
---|---|
tuple | list
|
The shape of the grid structure. |
Source code in tinybig/compression/geometric_compression.py
get_grid_shape_after_packing()
The shape of the grid structure after packing.
It returns the shape of the grid structure after packing.
Returns:
Type | Description |
---|---|
tuple | list
|
The shape of the grid structure after packing. |
Source code in tinybig/compression/geometric_compression.py
get_grid_size(across_universe=False)
The grid shape retrieval function.
It returns the size of the grid structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
across_universe
|
bool
|
The boolean tag indicating the grid size across universe or not. |
False
|
Returns:
Type | Description |
---|---|
int
|
The size of the grid structure. |
Source code in tinybig/compression/geometric_compression.py
get_patch_num(across_universe=False)
The patch shape number function.
It returns the number of patches existing in the input data vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
across_universe
|
bool
|
The boolean tag indicating the patch size across universe or not. |
False
|
Returns:
Type | Description |
---|---|
int
|
The number of patches existing in the input data vector. |
Source code in tinybig/compression/geometric_compression.py
get_patch_size()
The patch shape retrieval function.
It returns the size of the patch structure.
Returns:
Type | Description |
---|---|
int
|
The size of the patch structure. |