data_modalities
data_modalities
¤
image_data(image_shape, region_graph='quad-graph', *, input_layer, num_input_units, sum_product_layer, num_sum_units, num_classes=1, input_params=None, sum_weight_param=None, use_mixing_weights=True, data=None, num_bins=None, mi_chunk_size=None)
¤
Constructs a symbolic circuit whose structure is tailored for image data sets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_shape
|
tuple[int, int, int]
|
The image shape (C, H, W), where C is the number of channels, H is the height of the images, and W is their width. |
required |
region_graph
|
str
|
The name of the region graph to use. It can be one of the following: 'quad-tree-2' (the Quad-Tree with two splits per region node), 'quad-tree-4' (the Quad-Tree with four splits per region node), 'quad-graph' (the Quad-Graph region graph), 'random-binary-tree' (the random binary tree on flattened image pixels), 'poon-domingos' (the Poon-Domingos architecture), 'chow-liu-tree' (the Chow-Liu tree / HCLT, learned from data; requires the 'data' argument), 'linear-tree' (the linear chain over the flattened image pixels, i.e. the HMM region graph). |
'quad-graph'
|
input_layer
|
str
|
The name of the input layer. It can be one of the following: 'categorical' (encoding a Categorical distribution over pixel channel values), 'binomial' (encoding a Binomial distribution over pixel channel values), 'embedding' (encoding an Embedding vector over pixel channel values), 'gaussian' (encoding a Gaussian distribution over pixel channel values). |
required |
num_input_units
|
int
|
The number of input units per input layer. |
required |
sum_product_layer
|
str
|
The name of the sum-product inner layer. It can be one of the following: 'cp' (the canonical decomposition layer, consisting of dense layers followed by a hadamard product layer), 'cp-t' (the transposed canonical decomposition layer, consisting of a hadamard product layer followed by a single dense layer), 'tucker' (the Tucker decomposition layer, consisting of a kronecker product layer followed by a single dense layer). |
required |
num_classes
|
int
|
The number of output classes (default=1). |
1
|
num_sum_units
|
int
|
The number of sum units in each sum layer, i.e., either dense or mixing layer. |
required |
input_params
|
dict[str, Parameterization] | None
|
A dictionary mapping each name of a parameter of the input layer to its parameterization. If it is None, then the default parameterization of the chosen input layer will be chosen. |
None
|
sum_weight_param
|
Parameterization | None
|
The parameterization to use for sum layers parameters. If it None, then a softmax parameterization of the sum weights will be used. |
None
|
use_mixing_weights
|
bool
|
Whether to parameterize sum layers having arity > 1 in a way such that they compute a linear combinations of the input vectors, instead of computing a matrix-vector product where the vector is the concatenation of input vectors. Sum layers having this semantics are also sometimes referred to as "mixing" layers. Defaults to True. |
True
|
data
|
Tensor | None
|
The data tensor from which the 'chow-liu-tree' region graph is learned. It is required when region_graph is 'chow-liu-tree' and ignored otherwise. It can be of shape (num_samples, C, H, W) matching image_shape, flattened (num_samples, C * H * W), or (num_samples, H, W) for single-channel images (C == 1). When input_layer is 'gaussian' it must be floating-point; otherwise it is treated as discrete pixel values. |
None
|
num_bins
|
int | None
|
Used by the categorical, binomial, and embedding 'chow-liu-tree' region graph. If given, the 256 pixel levels are binned into num_bins bins before learning the tree. Must be in [1, 256]. If None, the raw pixel values are used. |
None
|
mi_chunk_size
|
int | None
|
Only used by the 'chow-liu-tree' region graph. The number of samples per chunk passed to the chunked mutual-information estimators. If None, all samples are processed at once. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Circuit |
Circuit
|
A symbolic circuit. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in cirkit/templates/data_modalities.py
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 | |
tabular_data(region_graph='random-binary-tree', *, num_features=None, data=None, input_layers, num_input_units, sum_product_layer, num_sum_units, num_classes=1, sum_weight_param=None, use_mixing_weights=True)
¤
Constructs a symbolic circuit whose structure is tailored for tabular data sets, supporting either a fixed random-binary-tree or a learned Chow–Liu tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region_graph
|
str
|
Which region graph to use.
- |
'random-binary-tree'
|
num_features
|
int | None
|
Number of features (columns) in the dataset.
Required if |
None
|
data
|
Tensor | None
|
A Torch tensor of shape |
None
|
input_layers
|
dict | list[dict]
|
Which per-feature distribution to use.
The provided dictionaries should be of the following form:
{
'name': |
required |
num_input_units
|
int
|
Number of parallel input units (e.g. mixtures/components) per feature. |
required |
sum_product_layer
|
str
|
Which inner sum/product decomposition to use. E.g. |
required |
num_sum_units
|
int
|
Number of sum (or mixing) units in each sum layer. |
required |
num_classes
|
int
|
Number of output classes (or root-layer mixtures). Often 1 for pure density estimation. |
1
|
sum_weight_param
|
Parameterization | None
|
If provided, a |
None
|
use_mixing_weights
|
bool
|
Whether to use “mixing” sum layers (i.e. learn a linear combination of child outputs) for nodes of arity >1. If False, falls back to a matrix-vector product. |
True
|
Returns:
| Type | Description |
|---|---|
Circuit
|
Circuit A fully-specified sum-product circuit over the given region graph with the chosen input distributions and inner decomposition layer. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in cirkit/templates/data_modalities.py
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 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |