tensor_factorizations
tensor_factorizations
¤
cp(shape, rank, *, factor_param=None, weight_param=None)
¤
Constructs a circuit encoding a CP factorization of an n-dimensional tensor.
Formally, given the shape of a tensor \(\mathcal{T}\in\mathbb{R}^{I_1\times \ldots\times I_n}\), this method returns a circuit \(c\) over \(n\) discrete random variables \(\{X_j\}_{j=1}^n\), each taking value between \(0\) and \(I_j\) for \(1\leq j\leq n\), and \(c\) computes a rank-\(R\) CP factorization, i.e.,
where for \(1\leq j\leq n\) we have that \(\mathbf{A}^{(j)}\in\mathbb{R}^{I_j\times R}\) is the \(j\)-th factor.
Furthermore, this method allows you to return a circuit encoding a CP decomposition with additional weights, i.e., a CP factorization of the form
where \(\mathbf{w}\in\mathbb{R}^R\) are additional weights.
This method allows you to specify different types of parameterizations for the factors and
possibly the additional weights. For example, if the arguments factor_param and
weight_param are both equal to a
parameterization
Parameterization(activation="softmax", initialization="normal"),
then the returned circuit encodes a probabilistic model that is a mixture of fully-factorized
models. That is, the returned circuit \(c\) encodes the factorization of a non-negative tensor
\(\mathcal{T}\in\mathbb{R}_+^{I_1\times \ldots\times I_n}\) as the distribution
where \(Z\) is a discrete latent variable modelled by \(p(Z)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, ...]
|
The shape of the tensor to encode the CP factorization of. |
required |
rank
|
int
|
The rank of the CP factorization. Defaults to 1. |
required |
factor_param
|
Parameterization | None
|
The parameterization to use for the factor matrices. If None, then it defaults to no activation and uses an initialization based on independently sampling from a standard Gaussian distribution. |
None
|
weight_param
|
Parameterization | None
|
The parameterization to use for the weight coefficients. If None, then it defaults to fixed weights set all to one. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Circuit |
Circuit
|
A circuit encoding a (possibly weighted) CP factorization. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the given tensor shape is not valid. |
ValueError
|
If the rank is not a positive number. |
Source code in cirkit/templates/tensor_factorizations.py
8 9 10 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 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 | |