pic
pic
¤
FourierLayer
¤
Bases: Module
Source code in cirkit/backend/torch/parameters/pic.py
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 | |
coeff = nn.Parameter(coeff)
instance-attribute
¤
in_features = in_features
instance-attribute
¤
out_features = out_features
instance-attribute
¤
sigma = sigma
instance-attribute
¤
__init__(in_features, out_features, sigma=1.0, learnable=False)
¤
Source code in cirkit/backend/torch/parameters/pic.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
extra_repr()
¤
Source code in cirkit/backend/torch/parameters/pic.py
73 74 | |
forward(z)
¤
Source code in cirkit/backend/torch/parameters/pic.py
69 70 71 | |
PICInnerNet
¤
Bases: Module
Source code in cirkit/backend/torch/parameters/pic.py
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 | |
eps = np.sqrt(torch.finfo(torch.get_default_dtype()).tiny)
instance-attribute
¤
net = nn.Sequential(FourierLayer(num_dim, ff_dim, sigma=ff_sigma, learnable=learn_ff), nn.Conv1d(inner_conv_groups * ff_dim, inner_conv_groups * net_dim, 1, groups=inner_conv_groups, bias=bias), nn.Tanh(), nn.Conv1d(inner_conv_groups * net_dim, inner_conv_groups * net_dim, 1, groups=inner_conv_groups, bias=bias), nn.Tanh(), nn.Conv1d(last_conv_groups * net_dim, last_conv_groups, 1, groups=last_conv_groups, bias=bias), nn.Softplus(beta=1.0))
instance-attribute
¤
norm_dim = tuple(range(1, num_dim + 1)) if norm_dim is None else norm_dim
instance-attribute
¤
num_dim = num_dim
instance-attribute
¤
num_funcs = num_funcs
instance-attribute
¤
perm_dim = (0,) + tuple(range(1, num_dim + 1)) if perm_dim is None else perm_dim
instance-attribute
¤
sharing = sharing
instance-attribute
¤
tensor_parameter = tensor_parameter
instance-attribute
¤
__init__(num_dim, num_funcs, perm_dim=None, norm_dim=None, net_dim=64, bias=False, sharing='none', ff_dim=None, ff_sigma=1.0, learn_ff=False, z_quad=None, w_quad=None, tensor_parameter=None)
¤
Source code in cirkit/backend/torch/parameters/pic.py
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 | |
__repr__()
¤
Source code in cirkit/backend/torch/parameters/pic.py
274 275 276 277 | |
forward(z_quad=None, w_quad=None, n_chunks=1)
¤
Source code in cirkit/backend/torch/parameters/pic.py
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 | |
PICInputNet
¤
Bases: Module
Source code in cirkit/backend/torch/parameters/pic.py
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 | |
net = nn.Sequential(FourierLayer(1, ff_dim, sigma=ff_sigma, learnable=learn_ff), nn.Conv1d(ff_dim * inner_conv_groups, net_dim * inner_conv_groups, 1, groups=inner_conv_groups, bias=bias), nn.Tanh(), nn.Conv1d(net_dim * last_conv_groups, num_param * last_conv_groups, 1, groups=last_conv_groups, bias=bias))
instance-attribute
¤
num_channels = num_channels
instance-attribute
¤
num_param = num_param
instance-attribute
¤
num_variables = num_variables
instance-attribute
¤
reparam = reparam
instance-attribute
¤
sharing = sharing
instance-attribute
¤
tensor_parameter = tensor_parameter
instance-attribute
¤
__init__(num_variables, num_param, num_channels=1, net_dim=64, bias=False, sharing='none', ff_dim=None, ff_sigma=1.0, learn_ff=False, z_quad=None, tensor_parameter=None, reparam=None)
¤
Source code in cirkit/backend/torch/parameters/pic.py
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 | |
__repr__()
¤
Source code in cirkit/backend/torch/parameters/pic.py
162 163 164 165 | |
forward(z_quad=None, n_chunks=1)
¤
Source code in cirkit/backend/torch/parameters/pic.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
TorchCPTLayer
¤
Bases: TorchInnerLayer
The Candecomp transposed (CP-T) layer, which is the fusion of a sum layer and a Hadamard layer.
Source code in cirkit/backend/torch/layers/optimized.py
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 | |
_weight_shape
property
¤
config
property
¤
params
property
¤
weight = weight
instance-attribute
¤
__init__(num_input_units, num_output_units, arity=2, *, weight, semiring=None, num_folds=1)
¤
Initialize a CP-T layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_input_units
|
int
|
The number of input units. |
required |
num_output_units
|
int
|
The number of output units. |
required |
arity
|
int
|
The arity of the layer, must be 2. Defaults to 2. |
2
|
weight
|
TorchParameter
|
The weight parameter, which must have shape \((F, K_o, K_i)\), where \(F\) is the number of folds, \(K_o\) is the number output units, and \(K_i\) is the number of input units. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of input and output units are incompatible with the shape of the weight parameter. |
Source code in cirkit/backend/torch/layers/optimized.py
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 | |
_valid_weight_shape(w)
¤
Source code in cirkit/backend/torch/layers/optimized.py
135 136 137 138 | |
forward(x)
¤
Source code in cirkit/backend/torch/layers/optimized.py
156 157 158 159 160 161 162 163 | |
sample(x)
¤
Source code in cirkit/backend/torch/layers/optimized.py
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 | |
TorchCategoricalLayer
¤
Bases: TorchExpFamilyLayer
The Categorical distribution layer, parameterized by either probabilities or logits.
Source code in cirkit/backend/torch/layers/input.py
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 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 | |
_probs_logits_shape
property
¤
config
property
¤
logits = logits
instance-attribute
¤
num_categories = num_categories
instance-attribute
¤
params
property
¤
probs = probs
instance-attribute
¤
__init__(scope_idx, num_output_units, num_channels=1, *, num_categories=2, probs=None, logits=None, semiring=None)
¤
Initialize a Categorical layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope_idx
|
Tensor
|
A tensor of shape \((F, D)\), where \(F\) is the number of folds, and \(D\) is the number of variables on which the input layers in each fold are defined on. Alternatively, a tensor of shape \((D,)\) can be specified, which will be interpreted as a tensor of shape \((1, D)\), i.e., with \(F = 1\). |
required |
num_output_units
|
int
|
The number of output units. |
required |
num_channels
|
int
|
The number of channels. |
1
|
num_categories
|
int
|
The number of categories for Categorical distribution. |
2
|
probs
|
TorchParameter | None
|
The probabilities parameter of shape \((F, K, C, V)\), where \(K\) is the number of output units, \(C\) is the number of channels, and \(V\) is the number of categories. |
None
|
logits
|
TorchParameter | None
|
The logits parameter of shape \((F, K, C, V)\), where \(K\) is the number of output units, \(C\) is the number of channels, and \(V\) is the number of categories. |
None
|
semiring
|
Semiring | None
|
The evaluation semiring. Defaults to SumProductSemiring. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the scope contains more than one variable. |
ValueError
|
If the number of categories is negative. |
ValueError
|
If both the probs and logits parameters are provided, or none of them. |
ValueError
|
If the parameter's shape is incorrect. |
Source code in cirkit/backend/torch/layers/input.py
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 | |
_valid_parameter_shape(p)
¤
Source code in cirkit/backend/torch/layers/input.py
406 407 408 409 | |
log_partition_function()
¤
Source code in cirkit/backend/torch/layers/input.py
445 446 447 448 449 450 451 | |
log_unnormalized_likelihood(x)
¤
Source code in cirkit/backend/torch/layers/input.py
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 | |
sample(num_samples=1)
¤
Source code in cirkit/backend/torch/layers/input.py
453 454 455 456 457 458 | |
TorchExpFamilyLayer
¤
Bases: TorchInputFunctionLayer, ABC
The abstract base class for exponential family distribution layers.
An input layer that is an exponential family distribution must define two methods.
The first one is the log_unnormalized_likelihood, used to compute the
possibly-unnormalized log-likelihood. The second one is the log_partition_function,
used to compute the logarithm of the partition function.
Source code in cirkit/backend/torch/layers/input.py
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 | |
forward(x)
¤
Source code in cirkit/backend/torch/layers/input.py
303 304 305 | |
integrate()
¤
Source code in cirkit/backend/torch/layers/input.py
307 308 309 | |
log_partition_function()
abstractmethod
¤
Compute the logarithm of the partition function of the layer.
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The logarithm of the partition function as a tensor of shape \((F, K)\), where \(F\) is the number of folds and \(K\) is the number of output units. Note that it will be a tensor of zeros if the layer encodes already normalized exponential family distributions. |
Source code in cirkit/backend/torch/layers/input.py
323 324 325 326 327 328 329 330 331 332 | |
log_unnormalized_likelihood(x)
abstractmethod
¤
Compute the (possibly unnormalized) log-likelihood of the given inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
The input tensor. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The (possibly unnormalized) log-likelihood as a tensor of shape \((F, K)\), where \(F\) is the number of folds and \(K\) is the number of output units. |
Source code in cirkit/backend/torch/layers/input.py
311 312 313 314 315 316 317 318 319 320 321 | |
TorchGaussianLayer
¤
Bases: TorchExpFamilyLayer
The Gaussian distribution layer. Optionally, this layer can encode unnormalized Gaussian distributions with the spefication of a log-partition function parameter.
Source code in cirkit/backend/torch/layers/input.py
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 | |
_log_partition_shape
property
¤
_mean_stddev_shape
property
¤
config
property
¤
log_partition = log_partition
instance-attribute
¤
mean = mean
instance-attribute
¤
params
property
¤
stddev = stddev
instance-attribute
¤
__init__(scope_idx, num_output_units, num_channels=1, *, mean, stddev, log_partition=None, semiring=None)
¤
Initialize a Gaussian layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope_idx
|
Tensor
|
A tensor of shape \((F, D)\), where \(F\) is the number of folds, and \(D\) is the number of variables on which the input layers in each fold are defined on. Alternatively, a tensor of shape \((D,)\) can be specified, which will be interpreted as a tensor of shape \((1, D)\), i.e., with \(F = 1\). |
required |
num_output_units
|
int
|
The number of output units. |
required |
num_channels
|
int
|
The number of channels. |
1
|
mean
|
TorchParameter
|
The mean parameter, having shape \((F, K, C)\), where \(K\) is the number of output units and \(C\) is the number of channels. |
required |
stddev
|
TorchParameter
|
The standard deviation parameter, having shape \((F, K, C)\), where \(K\) is the number of output units and \(C\) is the number of channels. |
required |
log_partition
|
TorchParameter | None
|
An optional parameter of shape \((F, K, C)\), encoding the log-partition. function. If this is not None, then the Gaussian layer encodes unnormalized Gaussian likelihoods, which are then normalized with the given log-partition function. |
None
|
semiring
|
Semiring | None
|
The evaluation semiring. Defaults to SumProductSemiring. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the scope contains more than one variable. |
ValueError
|
If the mean and standard deviation parameter shapes are incorrect. |
ValueError
|
If the log-partition function parameter shape is incorrect. |
Source code in cirkit/backend/torch/layers/input.py
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 | |
_valid_log_partition_shape(log_partition)
¤
Source code in cirkit/backend/torch/layers/input.py
659 660 661 662 | |
_valid_mean_stddev_shape(p)
¤
Source code in cirkit/backend/torch/layers/input.py
654 655 656 657 | |
log_partition_function()
¤
Source code in cirkit/backend/torch/layers/input.py
694 695 696 697 698 699 700 | |
log_unnormalized_likelihood(x)
¤
Source code in cirkit/backend/torch/layers/input.py
683 684 685 686 687 688 689 690 691 692 | |
sample(num_samples=1)
¤
Source code in cirkit/backend/torch/layers/input.py
702 703 704 705 706 | |
TorchHadamardLayer
¤
Bases: TorchInnerLayer
The Hadamard product layer, which computes an element-wise (or Hadamard) product of the input vectors it receives as inputs. See the symbolic HadamardLayer for more details.
Source code in cirkit/backend/torch/layers/inner.py
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 | |
config
property
¤
__init__(num_input_units, arity=2, *, semiring=None, num_folds=1)
¤
Initialize a Hadamard product layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_input_units
|
int
|
The number of input units, which is equal to the number of output units. |
required |
arity
|
int
|
The arity of the layer. |
2
|
semiring
|
Semiring | None
|
The evaluation semiring. Defaults to SumProductSemiring. |
None
|
num_folds
|
int
|
The number of channels. |
1
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the arity is not at least 2. |
ValueError
|
If the number of input units is not the same as the number of output units. |
Source code in cirkit/backend/torch/layers/inner.py
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 | |
forward(x)
¤
Source code in cirkit/backend/torch/layers/inner.py
123 124 | |
sample(x)
¤
Source code in cirkit/backend/torch/layers/inner.py
126 127 128 129 130 | |
TorchInnerLayer
¤
Bases: TorchLayer, ABC
The abstract base class for inner layers, i.e., either sum or product layers.
Source code in cirkit/backend/torch/layers/inner.py
14 15 16 17 18 19 20 21 22 23 24 25 26 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 | |
fold_settings
property
¤
__call__(x)
¤
Source code in cirkit/backend/torch/layers/inner.py
45 46 47 | |
__init__(num_input_units, num_output_units, arity=2, *, semiring=None, num_folds=1)
¤
Initialize an inner layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_input_units
|
int
|
The number of input units. |
required |
num_output_units
|
int
|
The number of output units. |
required |
arity
|
int
|
The arity of the layer. |
2
|
semiring
|
Semiring | None
|
The evaluation semiring. Defaults to SumProductSemiring. |
None
|
num_folds
|
int
|
The number of channels. |
1
|
Source code in cirkit/backend/torch/layers/inner.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
forward(x)
abstractmethod
¤
Invoke the forward function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
The tensor input to this layer, having shape \((F, H, B, K_i)\), where \(F\) is the number of folds, \(H\) is the arity, \(B\) is the batch size, and \(K_i\) is the number of input units. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The tensor output of this layer, having shape \((F, B, K_o)\), where \(K_o\) is the number of output units. |
Source code in cirkit/backend/torch/layers/inner.py
49 50 51 52 53 54 55 56 57 58 59 60 61 | |
sample(x)
¤
Perform a forward sampling step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
A tensor representing the input variable assignments, having shape \((F, H, C, K, N, D)\), where \(F\) is the number of folds, \(H\) is the arity, \(C\) is the number of channels, \(K\) is the numbe rof input units, \(N\) is the number of samples, \(D\) is the number of variables. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
tuple[Tensor, Tensor | None]
|
A new tensor representing the new variable assignements the layers gives as output. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If sampling is not supported by the layer. |
Source code in cirkit/backend/torch/layers/inner.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
TorchInputLayer
¤
Bases: TorchLayer, ABC
The abstract base class for torch input layers.
Source code in cirkit/backend/torch/layers/input.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 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 | |
config
abstractmethod
property
¤
fold_settings
property
¤
num_channels
property
¤
num_variables
property
¤
The number of variables the input layer is defined on.
Returns:
| Type | Description |
|---|---|
int
|
The number of variables. |
params
property
¤
scope_idx
property
¤
__init__(scope_idx, num_output_units, *, num_channels=1, semiring=None)
¤
Initialize a torch input layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope_idx
|
Tensor
|
A tensor of shape \((F, D)\), where \(F\) is the number of folds, and \(D\) is the number of variables on which the input layers in each fold are defined on. Alternatively, a tensor of shape \((D,)\) can be specified, which will be interpreted as a tensor of shape \((1, D)\), i.e., with \(F = 1\). |
required |
num_output_units
|
int
|
The number of output units. |
required |
num_channels
|
int
|
The number of channels. |
1
|
semiring
|
Semiring | None
|
The evaluation semiring. Defaults to SumProductSemiring. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the scope index is not a vector or a matrix. |
Source code in cirkit/backend/torch/layers/input.py
16 17 18 19 20 21 22 23 24 25 26 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 | |
extra_repr()
¤
Source code in cirkit/backend/torch/layers/input.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
integrate()
¤
Integrate an input layer over all its variables' domain.
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The tensor result of the integration, having shape \((F, K)\), where \(F\) is the number of folds and \(K\) is the number of output units. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If integration is not supported by the layer. |
Source code in cirkit/backend/torch/layers/input.py
94 95 96 97 98 99 100 101 102 103 104 | |
sample(num_samples=1)
¤
If the input layer encodes a probability distribution, then sample from it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_samples
|
int
|
The number of data points to sample. |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The tensorized sample, having shape \((F, C, K, N)\), where \(F\) is the number of folds, \(K\) is the number of output units, \(C\) is the number of channels, and \(N\) is the number of samples. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If sampling is not supported by the layer. |
Source code in cirkit/backend/torch/layers/input.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
TorchKroneckerLayer
¤
Bases: TorchInnerLayer
The Kronecker product layer, which computes the Kronecker product of the input vectors it receives as input. See the symbolic KroneckerLayer for more details.
Source code in cirkit/backend/torch/layers/inner.py
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 | |
config
property
¤
__init__(num_input_units, arity=2, *, semiring=None, num_folds=1)
¤
Initialize a Kronecker product layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_input_units
|
int
|
The number of input units. The number of output units is the power of the number of input units to the arity. |
required |
arity
|
int
|
The arity of the layer. Defaults to 2 (which is the only supported arity). |
2
|
semiring
|
Semiring | None
|
The evaluation semiring. Defaults to SumProductSemiring. |
None
|
num_folds
|
int
|
The number of channels. |
1
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the arity is not 2. |
ValueError
|
If the number of input units is not the same as the number of output units. |
Source code in cirkit/backend/torch/layers/inner.py
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 | |
forward(x)
¤
Source code in cirkit/backend/torch/layers/inner.py
179 180 181 182 183 | |
sample(x)
¤
Source code in cirkit/backend/torch/layers/inner.py
185 186 187 188 189 190 191 | |
TorchLayer
¤
Bases: AbstractTorchModule, ABC
The abstract base class for all layers implemented in torch.
Source code in cirkit/backend/torch/layers/base.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 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 | |
arity = arity
instance-attribute
¤
config
abstractmethod
property
¤
Retrieves the configuration of the layer, i.e., a dictionary mapping hyperparameters
of the layer to their values. The hyperparameter names must match the argument names in
the __init__ method.
Returns:
| Type | Description |
|---|---|
Mapping[str, Any]
|
Mapping[str, Any]: A dictionary from hyperparameter names to their value. |
num_buffers
cached
property
¤
Retrieve the number of scalar buffers. Note that if a buffer is complex-valued, this will double count them.
Returns:
| Type | Description |
|---|---|
int
|
The number of scalar buffers. |
num_input_units = num_input_units
instance-attribute
¤
num_output_units = num_output_units
instance-attribute
¤
num_parameters
cached
property
¤
Retrieve the number of scalar parameters. Note that if a parameter is complex-valued, this will double count them.
Returns:
| Type | Description |
|---|---|
int
|
The number of scalar parameters. |
params
property
¤
Retrieve the torch parameters of the layer, i.e., a dictionary mapping the names of
the torch parameters to the actual torch parameter instance. The parameter names must
match the argument names in the__init__ method.
Returns:
| Type | Description |
|---|---|
Mapping[str, TorchParameter]
|
Mapping[str, TorchParameter]: A dictionary from parameter names to the corresponding torch parameter instance. |
semiring = semiring if semiring is not None else SumProductSemiring
instance-attribute
¤
sub_modules
property
¤
Retrieve a dictionary mapping string identifiers to torch sub-module layers.,
that must be passed to the __init__ method of the top-level layer
Returns:
| Type | Description |
|---|---|
Mapping[str, TorchLayer]
|
A dictionary of torch modules. |
__init__(num_input_units, num_output_units, arity=1, *, semiring=None, num_folds=1)
¤
Initialize a layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_input_units
|
int
|
The number of input units. |
required |
num_output_units
|
int
|
The number of output units. |
required |
arity
|
int
|
The arity of the layer. |
1
|
semiring
|
Semiring | None
|
The evaluation semiring. Defaults to SumProductSemiring. |
None
|
num_folds
|
int
|
The number of folds. |
1
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of input units is negative. |
ValueError
|
If the number of output units is not positive. |
VAlueError
|
If the arity is not positive. |
Source code in cirkit/backend/torch/layers/base.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
extra_repr()
¤
Source code in cirkit/backend/torch/layers/base.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
TorchLogPartitionLayer
¤
Bases: TorchConstantLayer
An input layer having empty scope and computing a constant value.
Source code in cirkit/backend/torch/layers/input.py
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 | |
_source_semiring = LSESumSemiring if log_space else SumProductSemiring
instance-attribute
¤
config
property
¤
log_space = log_space
instance-attribute
¤
params
property
¤
value = value
instance-attribute
¤
__init__(num_output_units, *, log_space=False, value, semiring=None)
¤
Initialize a constant value input layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_output_units
|
int
|
The number of output units. |
required |
log_space
|
bool
|
Whether the given value is in the log-space, i.e., this constant layer should encode functions \(\exp(x)\) rather than just x. |
False
|
value
|
TorchParameter
|
The tensor value encoded by the layer, given by a parameter of shape \((F, K)\), where \(F\) is the number of folds and \(K\) is the numer of output units. |
required |
semiring
|
Semiring | None
|
The evaluation semiring. Defaults to SumProductSemiring. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of folds of the shape of the given value is incorrect. |
Source code in cirkit/backend/torch/layers/input.py
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 | |
forward(batch_size)
¤
Source code in cirkit/backend/torch/layers/input.py
760 761 762 763 764 | |
TorchPolynomialLayer
¤
Bases: TorchInputFunctionLayer
The polynomial input layer, evaluating a vector of parameterized polynomials.
Source code in cirkit/backend/torch/layers/input.py
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 | |
_coeff_shape
property
¤
coeff = coeff
instance-attribute
¤
config
property
¤
degree = degree
instance-attribute
¤
params
property
¤
__init__(scope_idx, num_output_units, num_channels=1, *, degree, coeff, semiring=None)
¤
Initialize a polynomial layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope_idx
|
Tensor
|
A tensor of shape \((F, D)\), where \(F\) is the number of folds, and \(D\) is the number of variables on which the input layers in each fold are defined on. Alternatively, a tensor of shape \((D,)\) can be specified, which will be interpreted as a tensor of shape \((1, D)\), i.e., with \(F = 1\). |
required |
num_output_units
|
int
|
The number of output units. |
required |
num_channels
|
int
|
The number of channels. |
1
|
degree
|
int
|
The degree of polynomial. |
required |
coeff
|
TorchParameter
|
The coefficient parameter, having shape \((F, K, \mathsf{degree} + 1)\), where \(K\) is the number of output units. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the scope contains more than one variable. |
ValueError
|
If the coefficients is not correct. |
Source code in cirkit/backend/torch/layers/input.py
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 | |
_polyval(coeff, x)
staticmethod
¤
Evaluate polynomial given coefficients and point, with the shape for PolynomialLayer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coeff
|
Tensor
|
The coefficients of the polynomial, shape \((F, K_o, \mathsf{degree} + 1)\). |
required |
x
|
Tensor
|
The point of the variable, shape \((F, H, B, K_i)\), where \(H=K_i=1\). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The value of the polymonial, shape \((F, B, K_o)\). |
Source code in cirkit/backend/torch/layers/input.py
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 | |
_valid_parameters_shape(p)
¤
Source code in cirkit/backend/torch/layers/input.py
894 895 896 897 | |
forward(x)
¤
Source code in cirkit/backend/torch/layers/input.py
937 938 939 | |
TorchSumLayer
¤
Bases: TorchInnerLayer
The sum layer torch implementation. See the symbolic SumLayer for more details.
Source code in cirkit/backend/torch/layers/inner.py
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 | |
_weight_shape
property
¤
config
property
¤
params
property
¤
weight = weight
instance-attribute
¤
__init__(num_input_units, num_output_units, arity=1, *, weight, semiring=None, num_folds=1)
¤
Initialize a sum layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_input_units
|
int
|
The number of input units. |
required |
num_output_units
|
int
|
The number of output units. |
required |
arity
|
int
|
The arity of the layer. |
1
|
weight
|
TorchParameter
|
The weight parameter, which must have shape \((F, K_o, K_i\cdot H)\), where \(F\) is the number of folds, \(K_o\) is the number of output units, \(K_i\) is the number of input units, and \(H\) is the arity. |
required |
semiring
|
Semiring | None
|
The evaluation semiring. Defaults to SumProductSemiring. |
None
|
num_folds
|
int
|
The number of channels. |
1
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the arity is not a positive integer. |
ValueError
|
If the arity, the number of input and output units are incompatible with the shape of the weight parameter. |
Source code in cirkit/backend/torch/layers/inner.py
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 | |
_valid_weight_shape(w)
¤
Source code in cirkit/backend/torch/layers/inner.py
239 240 241 242 | |
forward(x)
¤
Source code in cirkit/backend/torch/layers/inner.py
260 261 262 263 264 265 266 267 | |
sample(x)
¤
Source code in cirkit/backend/torch/layers/inner.py
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 | |
pc2qpc(pc, integration_method, net_dim=128, bias=True, input_sharing='f', inner_sharing='c', ff_dim=None, ff_sigma=1.0, learn_ff=False, freeze_mixing_layers=True)
¤
Source code in cirkit/backend/torch/parameters/pic.py
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 417 418 419 420 421 422 | |
zw_quadrature(integration_method, nip, a=-1, b=1, return_log_weight=False, dtype=torch.float32)
¤
Source code in cirkit/backend/torch/parameters/pic.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |