From 8ff836a7f9307ee989f305afefc671ff080c8d28 Mon Sep 17 00:00:00 2001 From: "Documenter.jl" Date: Wed, 29 Nov 2023 13:10:23 +0000 Subject: [PATCH] build based on 4518212 --- dev/index.html | 2 +- dev/man/basic/index.html | 98 +++++----- dev/man/factorization/index.html | 276 ++++++++++++++--------------- dev/man/indexed/index.html | 2 +- dev/man/kroneckerpowers/index.html | 180 +++++++++---------- dev/man/kroneckersums/index.html | 116 ++++++------ dev/man/multiplication/index.html | 118 ++++++------ dev/man/types/index.html | 2 +- dev/search/index.html | 2 +- 9 files changed, 398 insertions(+), 398 deletions(-) diff --git a/dev/index.html b/dev/index.html index bd233ae..97aa9a6 100644 --- a/dev/index.html +++ b/dev/index.html @@ -44,4 +44,4 @@ 174.0 202.0 481.0 - 450.0 + 450.0 diff --git a/dev/man/basic/index.html b/dev/man/basic/index.html index 96d1040..7f59c73 100644 --- a/dev/man/basic/index.html +++ b/dev/man/basic/index.html @@ -1,51 +1,51 @@ Basic use · Kronecker.jl

Basic use

Compute a lazy Kronecker products between two matrices A and B by either

K = kronecker(A, B)

or, by using the binary operator:

K = A ⊗ B

Note, can be formed by typing \otimes<tab>.

The Kronecker product K behaves like a matrix, for which size(K), eltype(K) works as one would expect. Elements can be accessed via K[i,j]; every element is computed on the fly. The function collect can be used to turn K in a regular, dense matrix.

julia> using Kronecker
julia> A = randn(4, 4)4×4 Array{Float64,2}: - -0.898948 0.161742 -0.0672892 -0.548841 - -1.589 -0.168276 0.260843 -0.43636 - -0.35777 -0.661722 0.812772 -0.664344 - -0.594185 -2.12265 0.946309 0.992948
julia> B = rand(1:10, 5, 7)5×7 Array{Int64,2}: - 9 10 3 8 3 3 10 - 1 5 2 7 4 8 1 - 8 8 10 6 9 1 8 - 4 2 5 5 4 7 4 - 10 4 3 6 9 7 8
julia> K = A ⊗ B20×28 Kronecker.KroneckerProduct{Float64,Array{Float64,2},Array{Int64,2}}: - -8.09053 -8.98948 -2.69684 … -1.64652 -1.64652 -5.48841 - -0.898948 -4.49474 -1.7979 -2.19536 -4.39073 -0.548841 - -7.19158 -7.19158 -8.98948 -4.93957 -0.548841 -4.39073 - -3.59579 -1.7979 -4.49474 -2.19536 -3.84189 -2.19536 - -8.98948 -3.59579 -2.69684 -4.93957 -3.84189 -4.39073 - -14.301 -15.89 -4.76699 … -1.30908 -1.30908 -4.3636 - -1.589 -7.94498 -3.17799 -1.74544 -3.49088 -0.43636 - -12.712 -12.712 -15.89 -3.92724 -0.43636 -3.49088 - -6.35598 -3.17799 -7.94498 -1.74544 -3.05452 -1.74544 - -15.89 -6.35598 -4.76699 -3.92724 -3.05452 -3.49088 - -3.21993 -3.5777 -1.07331 … -1.99303 -1.99303 -6.64344 - -0.35777 -1.78885 -0.71554 -2.65738 -5.31475 -0.664344 - -2.86216 -2.86216 -3.5777 -5.9791 -0.664344 -5.31475 - -1.43108 -0.71554 -1.78885 -2.65738 -4.65041 -2.65738 - -3.5777 -1.43108 -1.07331 -5.9791 -4.65041 -5.31475 - -5.34766 -5.94185 -1.78255 … 2.97884 2.97884 9.92948 - -0.594185 -2.97092 -1.18837 3.97179 7.94358 0.992948 - -4.75348 -4.75348 -5.94185 8.93653 0.992948 7.94358 - -2.37674 -1.18837 -2.97092 3.97179 6.95064 3.97179 - -5.94185 -2.37674 -1.78255 8.93653 6.95064 7.94358
julia> K[4, 5]-3.595790755205263
julia> eltype(K) # promotionFloat64
julia> collect(K)20×28 Array{Float64,2}: - -8.09053 -8.98948 -2.69684 … -1.64652 -1.64652 -5.48841 - -0.898948 -4.49474 -1.7979 -2.19536 -4.39073 -0.548841 - -7.19158 -7.19158 -8.98948 -4.93957 -0.548841 -4.39073 - -3.59579 -1.7979 -4.49474 -2.19536 -3.84189 -2.19536 - -8.98948 -3.59579 -2.69684 -4.93957 -3.84189 -4.39073 - -14.301 -15.89 -4.76699 … -1.30908 -1.30908 -4.3636 - -1.589 -7.94498 -3.17799 -1.74544 -3.49088 -0.43636 - -12.712 -12.712 -15.89 -3.92724 -0.43636 -3.49088 - -6.35598 -3.17799 -7.94498 -1.74544 -3.05452 -1.74544 - -15.89 -6.35598 -4.76699 -3.92724 -3.05452 -3.49088 - -3.21993 -3.5777 -1.07331 … -1.99303 -1.99303 -6.64344 - -0.35777 -1.78885 -0.71554 -2.65738 -5.31475 -0.664344 - -2.86216 -2.86216 -3.5777 -5.9791 -0.664344 -5.31475 - -1.43108 -0.71554 -1.78885 -2.65738 -4.65041 -2.65738 - -3.5777 -1.43108 -1.07331 -5.9791 -4.65041 -5.31475 - -5.34766 -5.94185 -1.78255 … 2.97884 2.97884 9.92948 - -0.594185 -2.97092 -1.18837 3.97179 7.94358 0.992948 - -4.75348 -4.75348 -5.94185 8.93653 0.992948 7.94358 - -2.37674 -1.18837 -2.97092 3.97179 6.95064 3.97179 - -5.94185 -2.37674 -1.78255 8.93653 6.95064 7.94358

Constructing Kronecker products

Kronecker.kroneckerFunction
kronecker(A::AbstractMatrix, B::AbstractMatrix)

Construct a Kronecker product object between two arrays. Does not evaluate the Kronecker product explictly.

source
kronecker(A::AbstractMatrix, B::AbstractMatrix)

Higher-order Kronecker lazy kronecker product, e.g.

kronecker(A, B, C, D)
source
kronecker(A::AbstractMatrix, pow::Int)

Kronecker power, computes A ⊗ A ⊗ ... ⊗ A. Returns a lazy KroneckerPower type.

source
Kronecker.:⊗Function
⊗(A::AbstractMatrix, B::AbstractMatrix)

Binary operator for kronecker, computes as Lazy Kronecker product. See kronecker for documentation.

source
⊗(A::AbstractMatrix, pow::Int)

Kronecker power, computes A ⊗ A ⊗ ... ⊗ A. Returns a lazy KroneckerPower type.

source
Base.collectMethod
collect(K::GeneralizedKroneckerProduct)

Collects a lazy instance of the GeneralizedKroneckerProduct type into a dense, native matrix. Falls back to the element-wise case when not specialized method is defined.

source

Basic properties of Kronecker products

Base.getindexFunction
getindex(K::AbstractKroneckerProduct, i1::Integer, i2::Integer)

Computes and returns the (i,j)-th element of an AbstractKroneckerProduct K. Uses recursion if K is of an order greater than two.

source
Missing docstring.

Missing docstring for eltype. Check Documenter's build log for details.

Base.sizeMethod
size(K::AbstractKroneckerProduct)

Returns a the size of an AbstractKroneckerProduct instance.

source
Base.collectFunction
collect(K::GeneralizedKroneckerProduct)

Collects a lazy instance of the GeneralizedKroneckerProduct type into a dense, native matrix. Falls back to the element-wise case when not specialized method is defined.

source
collect(K::AbstractKroneckerSum)

Collects a lazy instance of the AbstractKroneckerSum type into a full, native matrix. Returns the result as a sparse matrix.

source
collect(E::Eigen{<:Number, <:Number, <:AbstractKroneckerProduct})

Collects eigenvalue decomposition of a AbstractKroneckerProduct type into a matrix.

source
Kronecker.collect!Function
collect!(C::AbstractMatrix, K::GeneralizedKroneckerProduct)

In-place collection of K in C. If possible, specialized routines are used to speed up the computation. The fallback is an element-wise iteration. In this case, this function might be slow.

source
collect!(C::AbstractMatrix, K::AbstractKroneckerProduct)

In-place collection of K in C where K is an AbstractKroneckerProduct, i.e., K = A ⊗ B. This is equivalent to the broadcasted assignment C .= K.

collect!(f, C::AbstractMatrix, K1::AbstractKroneckerProduct, Ks::AbstractKroneckerProduct...)

Evaluate f.(K1, Ks...) and assign it in-place to C. This is equivalent to the broadcasted operation C .= f.(K1, Ks...).

source
collect!(C::AbstractMatrix, K::AbstractKroneckerSum)

In-place collection of K in C where K is an AbstractKroneckerSum, i.e., K = A ⊗ B.

source
Kronecker.orderFunction
order(M::AbstractMatrix)

Returns the order of a matrix, i.e. how many matrices are involved in the Kronecker product (default to 1 for general matrices).

source
Kronecker.getmatricesFunction
getmatrices(K::AbstractKroneckerProduct)

Obtain the two matrices of an AbstractKroneckerProduct object.

source
getmatrices(A::AbstractArray)

Returns a matrix itself. Needed for recursion.

source
getmatrices(K::T) where T <: AbstractKroneckerSum

Obtain the two matrices of an AbstractKroneckerSum object.

source
Kronecker.issquareFunction
issquare(A::AbstractMatrix)

Checks if an array is a square matrix.

source
issquare(A::Factorization)

Checks if a Factorization struct represents a square matrix.

source
Missing docstring.

Missing docstring for sum. Check Documenter's build log for details.

Linear algebra

Many functions of the LinearAlgebra module are overloaded to work with subtypes of GeneralizedKroneckerProduct.

LinearAlgebra.logdetMethod
logdet(K::AbstractKroneckerProduct)

Compute the logarithm of the determinant of a Kronecker product.

source
Base.invMethod
inv(K::AbstractKroneckerProduct)

Compute the inverse of a Kronecker product.

source
Base.adjointMethod
adjoint(K::AbstractKroneckerProduct)

Compute the adjoint of a Kronecker product.

source
Base.transposeMethod
transpose(K::AbstractKroneckerProduct)

Compute the transpose of a Kronecker product.

source
Missing docstring.

Missing docstring for conj(K::AbstractKroneckerProduct). Check Documenter's build log for details.

+ 0.284044 -0.278227 -1.58175 -2.68135 + 0.268104 0.627129 -2.36381 -0.64596 + -0.759459 -0.103594 1.29329 0.257264 + -0.397535 -3.69769 -0.335861 1.40882
julia> B = rand(1:10, 5, 7)5×7 Array{Int64,2}: + 1 10 5 2 1 2 2 + 10 4 3 4 1 2 9 + 6 5 7 7 5 7 10 + 10 3 9 9 10 10 5 + 2 10 10 1 10 4 5
julia> K = A ⊗ B20×28 Kronecker.KroneckerProduct{Float64,Array{Float64,2},Array{Int64,2}}: + 0.284044 2.84044 1.42022 … -2.68135 -5.3627 -5.3627 + 2.84044 1.13618 0.852132 -2.68135 -5.3627 -24.1321 + 1.70426 1.42022 1.98831 -13.4067 -18.7694 -26.8135 + 2.84044 0.852132 2.5564 -26.8135 -26.8135 -13.4067 + 0.568088 2.84044 2.84044 -26.8135 -10.7254 -13.4067 + 0.268104 2.68104 1.34052 … -0.64596 -1.29192 -1.29192 + 2.68104 1.07241 0.804311 -0.64596 -1.29192 -5.81364 + 1.60862 1.34052 1.87673 -3.2298 -4.52172 -6.4596 + 2.68104 0.804311 2.41293 -6.4596 -6.4596 -3.2298 + 0.536207 2.68104 2.68104 -6.4596 -2.58384 -3.2298 + -0.759459 -7.59459 -3.79729 … 0.257264 0.514528 0.514528 + -7.59459 -3.03783 -2.27838 0.257264 0.514528 2.31537 + -4.55675 -3.79729 -5.31621 1.28632 1.80085 2.57264 + -7.59459 -2.27838 -6.83513 2.57264 2.57264 1.28632 + -1.51892 -7.59459 -7.59459 2.57264 1.02906 1.28632 + -0.397535 -3.97535 -1.98768 … 1.40882 2.81765 2.81765 + -3.97535 -1.59014 -1.19261 1.40882 2.81765 12.6794 + -2.38521 -1.98768 -2.78275 7.04412 9.86177 14.0882 + -3.97535 -1.19261 -3.57782 14.0882 14.0882 7.04412 + -0.79507 -3.97535 -3.97535 14.0882 5.63529 7.04412
julia> K[4, 5]2.8404404058081347
julia> eltype(K) # promotionFloat64
julia> collect(K)20×28 Array{Float64,2}: + 0.284044 2.84044 1.42022 … -2.68135 -5.3627 -5.3627 + 2.84044 1.13618 0.852132 -2.68135 -5.3627 -24.1321 + 1.70426 1.42022 1.98831 -13.4067 -18.7694 -26.8135 + 2.84044 0.852132 2.5564 -26.8135 -26.8135 -13.4067 + 0.568088 2.84044 2.84044 -26.8135 -10.7254 -13.4067 + 0.268104 2.68104 1.34052 … -0.64596 -1.29192 -1.29192 + 2.68104 1.07241 0.804311 -0.64596 -1.29192 -5.81364 + 1.60862 1.34052 1.87673 -3.2298 -4.52172 -6.4596 + 2.68104 0.804311 2.41293 -6.4596 -6.4596 -3.2298 + 0.536207 2.68104 2.68104 -6.4596 -2.58384 -3.2298 + -0.759459 -7.59459 -3.79729 … 0.257264 0.514528 0.514528 + -7.59459 -3.03783 -2.27838 0.257264 0.514528 2.31537 + -4.55675 -3.79729 -5.31621 1.28632 1.80085 2.57264 + -7.59459 -2.27838 -6.83513 2.57264 2.57264 1.28632 + -1.51892 -7.59459 -7.59459 2.57264 1.02906 1.28632 + -0.397535 -3.97535 -1.98768 … 1.40882 2.81765 2.81765 + -3.97535 -1.59014 -1.19261 1.40882 2.81765 12.6794 + -2.38521 -1.98768 -2.78275 7.04412 9.86177 14.0882 + -3.97535 -1.19261 -3.57782 14.0882 14.0882 7.04412 + -0.79507 -3.97535 -3.97535 14.0882 5.63529 7.04412

Constructing Kronecker products

Kronecker.kroneckerFunction
kronecker(A::AbstractMatrix, B::AbstractMatrix)

Construct a Kronecker product object between two arrays. Does not evaluate the Kronecker product explictly.

source
kronecker(A::AbstractMatrix, B::AbstractMatrix)

Higher-order Kronecker lazy kronecker product, e.g.

kronecker(A, B, C, D)
source
kronecker(A::AbstractMatrix, pow::Int)

Kronecker power, computes A ⊗ A ⊗ ... ⊗ A. Returns a lazy KroneckerPower type.

source
Kronecker.:⊗Function
⊗(A::AbstractMatrix, B::AbstractMatrix)

Binary operator for kronecker, computes as Lazy Kronecker product. See kronecker for documentation.

source
⊗(A::AbstractMatrix, pow::Int)

Kronecker power, computes A ⊗ A ⊗ ... ⊗ A. Returns a lazy KroneckerPower type.

source
Base.collectMethod
collect(K::GeneralizedKroneckerProduct)

Collects a lazy instance of the GeneralizedKroneckerProduct type into a dense, native matrix. Falls back to the element-wise case when not specialized method is defined.

source

Basic properties of Kronecker products

Base.getindexFunction
getindex(K::AbstractKroneckerProduct, i1::Integer, i2::Integer)

Computes and returns the (i,j)-th element of an AbstractKroneckerProduct K. Uses recursion if K is of an order greater than two.

source
Missing docstring.

Missing docstring for eltype. Check Documenter's build log for details.

Base.sizeMethod
size(K::AbstractKroneckerProduct)

Returns a the size of an AbstractKroneckerProduct instance.

source
Base.collectFunction
collect(K::GeneralizedKroneckerProduct)

Collects a lazy instance of the GeneralizedKroneckerProduct type into a dense, native matrix. Falls back to the element-wise case when not specialized method is defined.

source
collect(K::AbstractKroneckerSum)

Collects a lazy instance of the AbstractKroneckerSum type into a full, native matrix. Returns the result as a sparse matrix.

source
collect(E::Eigen{<:Number, <:Number, <:AbstractKroneckerProduct})

Collects eigenvalue decomposition of a AbstractKroneckerProduct type into a matrix.

source
Kronecker.collect!Function
collect!(C::AbstractMatrix, K::GeneralizedKroneckerProduct)

In-place collection of K in C. If possible, specialized routines are used to speed up the computation. The fallback is an element-wise iteration. In this case, this function might be slow.

source
collect!(C::AbstractMatrix, K::AbstractKroneckerProduct)

In-place collection of K in C where K is an AbstractKroneckerProduct, i.e., K = A ⊗ B. This is equivalent to the broadcasted assignment C .= K.

collect!(f, C::AbstractMatrix, K1::AbstractKroneckerProduct, Ks::AbstractKroneckerProduct...)

Evaluate f.(K1, Ks...) and assign it in-place to C. This is equivalent to the broadcasted operation C .= f.(K1, Ks...).

source
collect!(C::AbstractMatrix, K::AbstractKroneckerSum)

In-place collection of K in C where K is an AbstractKroneckerSum, i.e., K = A ⊗ B.

source
Kronecker.orderFunction
order(M::AbstractMatrix)

Returns the order of a matrix, i.e. how many matrices are involved in the Kronecker product (default to 1 for general matrices).

source
Kronecker.getmatricesFunction
getmatrices(K::AbstractKroneckerProduct)

Obtain the two matrices of an AbstractKroneckerProduct object.

source
getmatrices(A::AbstractArray)

Returns a matrix itself. Needed for recursion.

source
getmatrices(K::T) where T <: AbstractKroneckerSum

Obtain the two matrices of an AbstractKroneckerSum object.

source
Kronecker.issquareFunction
issquare(A::AbstractMatrix)

Checks if an array is a square matrix.

source
issquare(A::Factorization)

Checks if a Factorization struct represents a square matrix.

source
LinearAlgebra.issymmetricFunction
issymmetric(K::AbstractKroneckerProduct)

Checks if a Kronecker product is symmetric.

source
Missing docstring.

Missing docstring for sum. Check Documenter's build log for details.

Linear algebra

Many functions of the LinearAlgebra module are overloaded to work with subtypes of GeneralizedKroneckerProduct.

LinearAlgebra.detMethod
det(K::AbstractKroneckerProduct)

Compute the determinant of a Kronecker product.

source
LinearAlgebra.logdetMethod
logdet(K::AbstractKroneckerProduct)

Compute the logarithm of the determinant of a Kronecker product.

source
LinearAlgebra.trMethod
tr(K::AbstractKroneckerProduct)

Compute the trace of a Kronecker product.

source
Base.invMethod
inv(K::AbstractKroneckerProduct)

Compute the inverse of a Kronecker product.

source
Base.adjointMethod
adjoint(K::AbstractKroneckerProduct)

Compute the adjoint of a Kronecker product.

source
Base.transposeMethod
transpose(K::AbstractKroneckerProduct)

Compute the transpose of a Kronecker product.

source
Missing docstring.

Missing docstring for conj(K::AbstractKroneckerProduct). Check Documenter's build log for details.

diff --git a/dev/man/factorization/index.html b/dev/man/factorization/index.html index 4cc4e6c..42164fa 100644 --- a/dev/man/factorization/index.html +++ b/dev/man/factorization/index.html @@ -1,148 +1,148 @@ Factorization methods · Kronecker.jl

Factorization methods

Many forms of matrix factorization such as eigenvalue decomposition, LU factorization, Cholesky factorization etc., can be computed efficiently. The decomposition of the Kronecker product is the Kronecker product of the decompositions. We have overloaded some of the factorization functions from LinearAlgebra to compute the factorization of instances of AbstractKroneckerProduct.

Eigenvalue decomposition

The function eigen of LinearAlgebra is overloaded to compute the decomposition of AbstractKroneckerProducts. The result is a factorization of the Eigen type, containing a vector of the eigenvalues and a matrix with the eigenvectors. Just like long-time users would expect! The eigenvectors are structured as Kronecker products and can be processed accordingly.

The functions det, logdet, inv and \ are overloaded the make use of this decomposition.

The eigenvalue decomposition of matrices can be used to solve large systems of the form:

\[(A \otimes B + c\cdot I) \mathbf{x} = \mathbf{b}\]

The case where $A$ and $B$ are positive semi-definite frequently occurs in machine learning, for example in ridge regression.


julia> A, B = rand(10, 10), randn(4, 4);
julia> As, Bs = (A, B) .|> X -> X * X'; # make positive definite
julia> K = As ⊗ Bs40×40 Kronecker.KroneckerProduct{Float64,Array{Float64,2},Array{Float64,2}}: - 1.8243 1.85439 -1.23101 … 2.1799 -1.44709 0.973795 - 1.85439 10.0647 -6.11606 11.8314 -7.18964 -8.13691 - -1.23101 -6.11606 5.35474 -7.18964 6.29468 2.69786 - 0.828385 -6.92188 2.29501 -8.13691 2.69786 11.5576 - 2.47516 2.51599 -1.67019 3.28515 -2.18079 1.46753 - 2.51599 13.6554 -8.2981 … 17.83 -10.8349 -12.2625 - -1.67019 -8.2981 7.26516 -10.8349 9.48619 4.06572 - 1.12393 -9.39142 3.1138 -12.2625 4.06572 17.4175 - 2.27595 2.31349 -1.53577 2.45512 -1.62979 1.09674 - 2.31349 12.5564 -7.63024 13.3251 -8.09733 -9.1642 - ⋮ ⋱ - 1.0044 -8.39265 2.78265 -12.0736 4.00309 17.1492 - 2.3249 2.36324 -1.5688 3.38463 -2.24683 1.51197 - 2.36324 12.8264 -7.79432 18.37 -11.163 -12.6338 - -1.5688 -7.79432 6.82409 -11.163 9.77346 4.18884 - 1.05569 -8.82126 2.92476 … -12.6338 4.18884 17.945 - 2.14453 2.1799 -1.44709 3.55794 -2.36188 1.58939 - 2.1799 11.8314 -7.18964 19.3106 -11.7346 -13.2807 - -1.44709 -7.18964 6.29468 -11.7346 10.2739 4.40333 - 0.973795 -8.13691 2.69786 -13.2807 4.40333 18.8639
julia> E = eigen(K)Eigen{Float64,Float64,Kronecker.KroneckerProduct{Float64,Array{Float64,2},Array{Float64,2}},Array{Float64,1}} + 31.7798 13.6217 8.46737 … 11.3318 7.04394 0.0576194 + 13.6217 35.7485 13.4123 29.7389 11.1576 -2.68683 + 8.46737 13.4123 6.97464 11.1576 5.80216 -1.25406 + 0.069263 -3.22978 -1.50748 -2.68683 -1.25406 0.996335 + 19.8465 8.50674 5.28787 8.69874 5.40722 0.044231 + 8.50674 22.3249 8.37596 … 22.8288 8.56501 -2.06252 + 5.28787 8.37596 4.35566 8.56501 4.45397 -0.962666 + 0.0432547 -2.017 -0.941418 -2.06252 -0.962666 0.764827 + 33.2291 14.2429 8.85351 13.8031 8.58015 0.0701855 + 14.2429 37.3788 14.0239 36.2246 13.5909 -3.2728 + ⋮ ⋱ + 0.0503263 -2.34675 -1.09533 -2.24453 -1.04762 0.83232 + 23.6713 10.1461 6.30694 10.9539 6.80904 0.0556978 + 10.1461 26.6274 9.99016 28.7472 10.7855 -2.59723 + 6.30694 9.99016 5.19508 10.7855 5.60866 -1.21224 + 0.0515907 -2.40571 -1.12285 … -2.59723 -1.21224 0.963108 + 26.4374 11.3318 7.04394 13.8427 8.60477 0.0703869 + 11.3318 29.7389 11.1576 36.3286 13.6299 -3.28219 + 7.04394 11.1576 5.80216 13.6299 7.08782 -1.53194 + 0.0576194 -2.68683 -1.25406 -3.28219 -1.53194 1.21711
julia> E = eigen(K)Eigen{Float64,Float64,Kronecker.KroneckerProduct{Float64,Array{Float64,2},Array{Float64,2}},Array{Float64,1}} values: 40-element Array{Float64,1}: - 0.0001359220454330783 - 0.006748814478220137 - 0.030819030936338025 - 0.09830101736633068 - 0.0005754105408992727 - 0.028570339542553957 - 0.1304688669491873 - 0.4161461916901357 - 0.001283550634859824 - 0.06373097962490283 + 0.00029123186973506373 + 0.0007509239202255859 + 0.00991653343638598 + 0.025678026641621814 + 0.0015982518672834534 + 0.00412099664360276 + 0.05442096050854867 + 0.1409184855540046 + 0.03478203104502254 + 0.08968338228057506 ⋮ - 18.852747000417697 - 0.03717586503972033 - 1.8458596280023647 - 8.429273787734232 - 26.886185704711036 - 0.4250009927820498 - 21.102190187077667 - 96.36493258169273 - 307.36757851945083 + 22.545207242769884 + 0.4543648145901654 + 1.1715524406549505 + 15.471259654033021 + 40.06152151093757 + 4.487731491804558 + 11.571346665498405 + 152.80861752007698 + 395.68502208166285 vectors: 40×40 Kronecker.KroneckerProduct{Float64,Array{Float64,2},Array{Float64,2}}: - 0.376692 0.534187 0.282126 … -0.163234 -0.0862108 -0.0160693 - -0.445568 0.169202 0.181435 -0.0517039 -0.0554421 -0.152646 - -0.306118 0.441036 -0.372849 -0.13477 0.113934 0.0877039 - -0.274732 -0.033399 0.508019 0.0102059 -0.155238 0.127808 - 0.0695419 0.0986173 0.0520838 -0.294076 -0.155314 -0.0289498 - -0.0822571 0.0312366 0.0334951 … -0.0931475 -0.0998822 -0.275 - -0.056513 0.0814206 -0.0688324 -0.242796 0.205258 0.158004 - -0.0507187 -0.00616585 0.0937864 0.0183865 -0.27967 0.230254 - -0.313225 -0.444184 -0.234592 -0.227169 -0.119977 -0.0223632 - 0.370496 -0.140694 -0.150866 -0.0719548 -0.0771572 -0.212432 - ⋮ ⋱ - 0.0179609 0.0021835 -0.0332123 0.0178727 -0.271854 0.223819 - -0.014638 -0.0207582 -0.0109632 -0.265044 -0.139981 -0.0260919 - 0.0173145 -0.00657507 -0.00705045 -0.0839518 -0.0900216 -0.247851 - 0.0118955 -0.0171384 0.0144887 -0.218826 0.184994 0.142405 - 0.0106759 0.00129786 -0.0197413 … 0.0165714 -0.252061 0.207523 - -0.145603 -0.206479 -0.10905 -0.221272 -0.116863 -0.0217827 - 0.172225 -0.0654014 -0.07013 -0.070087 -0.0751543 -0.206918 - 0.118324 -0.170473 0.144117 -0.182687 0.154442 0.118887 - 0.106192 0.0129097 -0.196364 0.0138346 -0.210432 0.17325
julia> logdet(E)-37.0212260847147
julia> b = randn(40);
julia> (E + 0.1I) \ b # solve a system40-element Array{Float64,1}: - 2.2854663654846212 - 11.79382740512271 - 7.645999723115072 - 2.9602422670726707 - 5.816002651188354 - -4.155514395630833 - -3.528647911721028 - -2.653997968098717 - -1.1963430133065391 - -4.9975717084715185 + -0.00862273 0.00652955 … -0.0263283 -0.266943 0.20141 + -0.00462438 0.0279036 -0.112512 0.199656 0.246693 + 0.0385878 -0.0685141 0.276262 0.0350337 0.109405 + 0.0735536 0.0384637 -0.155093 -0.0371207 -0.0182751 + 0.00162764 -0.00123253 -0.0209617 -0.212531 0.160355 + 0.000872905 -0.00526712 … -0.0895784 0.158959 0.196408 + -0.00728389 0.0129328 0.21995 0.0278926 0.0871044 + -0.0138841 -0.00726047 -0.123479 -0.0295542 -0.01455 + -0.0508861 0.0385334 -0.0324542 -0.329054 0.248272 + -0.0272903 0.16467 -0.138691 0.24611 0.304091 + ⋮ ⋱ + -0.357098 -0.186739 -0.129245 -0.0309341 -0.0152293 + -0.0265994 0.0201423 -0.025839 -0.261982 0.197666 + -0.0142653 0.086077 -0.110421 0.195945 0.242108 + 0.119036 -0.211352 0.271127 0.0343825 0.107372 + 0.226898 0.118653 … -0.15221 -0.0364308 -0.0179354 + -0.0100118 0.00758142 -0.0261347 -0.26498 0.199928 + -0.00536934 0.0323987 -0.111685 0.198188 0.244878 + 0.0448041 -0.0795514 0.27423 0.034776 0.1086 + 0.0854027 0.04466 -0.153952 -0.0368477 -0.0181407
julia> logdet(E)-19.21091336330567
julia> b = randn(40);
julia> (E + 0.1I) \ b # solve a system40-element Array{Float64,1}: + 0.15616820987697325 + 1.406985731197416 + -3.991048341428295 + -6.479042238384197 + 4.76878233395609 + 5.465363034162523 + 0.311479955778969 + -9.043735671076762 + -3.2257428410160234 + 1.8259458626033038 ⋮ - 1.4896777023122063 - -4.26549100506332 - 1.2043487669744182 - 3.9314303072709316 - -2.169097335999905 - -6.449993445841667 - 4.472200292035162 - 2.969360143400582 - 5.9591125934120734
LinearAlgebra.eigenFunction
eigen(K::AbstractKroneckerProduct)

Wrapper around eigen from the LinearAlgebra package. If the matrices of an AbstractKroneckerProduct instance are square, performs Eigenvalue decompositon on them and returns an Eigen type. Otherwise, it collects the instance and runs eigen on the full matrix. The functions, \, inv, and logdet are overloaded to efficiently work with this type.

source
Missing docstring.

Missing docstring for +(E::Eigen, B::UniformScaling). Check Documenter's build log for details.

Missing docstring.

Missing docstring for +(::Eigen, ::UniformScaling). Check Documenter's build log for details.

LinearAlgebra.logdetMethod
logdet(K::Eigen)

Compute the logarithm of the determinant of the eigenvalue decomp of a Kronecker product.

source
Base.invMethod
inv(K::Eigen)

Compute the inverse of the eigenvalue decomp of a Kronecker product. Returns another type of Eigen.

source

Cholesky factorization

Similar to the eigenvalue decomposition, cholesky has been overloaded to allow for efficient Cholesky decomposition of Kronecker products of symmetric and positive definite matrices.


julia> A, B = rand(10, 10), randn(4, 4);
julia> As, Bs = (A, B) .|> X -> X * X'; # make positive definite
julia> K = As ⊗ Bs40×40 Kronecker.KroneckerProduct{Float64,Array{Float64,2},Array{Float64,2}}: - 10.9499 -0.795217 6.60591 … -0.580206 4.81981 -4.81352 - -0.795217 24.836 27.4 18.1208 19.9916 1.22762 - 6.60591 27.4 35.3818 19.9916 25.8153 -1.84573 - -6.59729 1.68255 -2.52971 1.22762 -1.84573 7.06255 - 7.57151 -0.549866 4.56777 -0.438168 3.63989 -3.63514 - -0.549866 17.1733 18.9462 … 13.6847 15.0975 0.927094 - 4.56777 18.9462 24.4654 15.0975 19.4956 -1.39388 - -4.56181 1.16343 -1.74921 0.927094 -1.39388 5.3336 - 9.09556 -0.660547 5.4872 -0.598624 4.9728 -4.96631 - -0.660547 20.63 22.7598 18.6961 20.6262 1.26659 - ⋮ ⋱ - -5.12005 1.3058 -1.96327 1.08633 -1.63329 6.24966 - 4.39351 -0.31907 2.65053 -0.24519 2.03681 -2.03415 - -0.31907 9.9651 10.9939 7.65772 8.44827 0.518784 - 2.65053 10.9939 14.1965 8.44827 10.9093 -0.779991 - -2.64707 0.675101 -1.01501 … 0.518784 -0.779991 2.98458 - 7.98929 -0.580206 4.81981 -0.61918 5.14356 -5.13685 - -0.580206 18.1208 19.9916 19.3381 21.3344 1.31009 - 4.81981 19.9916 25.8153 21.3344 27.5494 -1.96971 - -4.81352 1.22762 -1.84573 1.31009 -1.96971 7.53696
julia> C = cholesky(K)40×40 CholeskyKronecker{Cholesky{Float64,Array{Float64,2}},Cholesky{Float64,Array{Float64,2}}} + -4.4348852139786406 + -2.208750824174579 + 2.153671456071821 + 1.3938419616001683 + 9.190464447632992 + 0.7974636152090406 + 1.621447536821078 + -2.776927987408376 + -5.341729534106016
LinearAlgebra.eigenFunction
eigen(K::AbstractKroneckerProduct)

Wrapper around eigen from the LinearAlgebra package. If the matrices of an AbstractKroneckerProduct instance are square, performs Eigenvalue decompositon on them and returns an Eigen type. Otherwise, it collects the instance and runs eigen on the full matrix. The functions, \, inv, and logdet are overloaded to efficiently work with this type.

source
Missing docstring.

Missing docstring for +(E::Eigen, B::UniformScaling). Check Documenter's build log for details.

Missing docstring.

Missing docstring for +(::Eigen, ::UniformScaling). Check Documenter's build log for details.

LinearAlgebra.logdetMethod
logdet(K::Eigen)

Compute the logarithm of the determinant of the eigenvalue decomp of a Kronecker product.

source
Base.invMethod
inv(K::Eigen)

Compute the inverse of the eigenvalue decomp of a Kronecker product. Returns another type of Eigen.

source

Cholesky factorization

Similar to the eigenvalue decomposition, cholesky has been overloaded to allow for efficient Cholesky decomposition of Kronecker products of symmetric and positive definite matrices.


julia> A, B = rand(10, 10), randn(4, 4);
julia> As, Bs = (A, B) .|> X -> X * X'; # make positive definite
julia> K = As ⊗ Bs40×40 Kronecker.KroneckerProduct{Float64,Array{Float64,2},Array{Float64,2}}: + 31.9113 -13.1507 5.84077 -2.68873 … -8.18535 3.63545 -1.67354 + -13.1507 20.5303 -7.48847 -2.72384 12.7786 -4.66102 -1.69539 + 5.84077 -7.48847 14.8242 5.42263 -4.66102 9.227 3.37519 + -2.68873 -2.72384 5.42263 8.98161 -1.69539 3.37519 5.59039 + 18.4252 -7.59306 3.37239 -1.55244 -7.47186 3.31856 -1.52766 + -7.59306 11.8539 -4.32376 -1.57271 … 11.6647 -4.25474 -1.54761 + 3.37239 -4.32376 8.55933 3.13096 -4.25474 8.42271 3.08099 + -1.55244 -1.57271 3.13096 5.18587 -1.54761 3.08099 5.1031 + 17.3994 -7.1703 3.18462 -1.46601 -7.29688 3.24084 -1.49189 + -7.1703 11.1939 -4.08302 -1.48515 11.3915 -4.1551 -1.51136 + ⋮ ⋱ + -2.36853 -2.39945 4.77684 7.91197 -2.04634 4.07386 6.74762 + 16.3562 -6.74041 2.99369 -1.37811 -5.41211 2.40374 -1.10653 + -6.74041 10.5228 -3.83823 -1.39611 8.44912 -3.08184 -1.12098 + 2.99369 -3.83823 7.59818 2.77938 -3.08184 6.10084 2.23166 + -1.37811 -1.39611 2.77938 4.60354 … -1.12098 2.23166 3.69634 + 19.8625 -8.18535 3.63545 -1.67354 -10.8129 4.80246 -2.21076 + -8.18535 12.7786 -4.66102 -1.69539 16.8806 -6.15726 -2.23962 + 3.63545 -4.66102 9.227 3.37519 -6.15726 12.189 4.45866 + -1.67354 -1.69539 3.37519 5.59039 -2.23962 4.45866 7.38497
julia> C = cholesky(K)40×40 CholeskyKronecker{Cholesky{Float64,Array{Float64,2}},Cholesky{Float64,Array{Float64,2}}} U factor: 40×40 Kronecker.KroneckerProduct{Float64,UpperTriangular{Float64,Array{Float64,2}},UpperTriangular{Float64,Array{Float64,2}}}: - 3.30907 -0.240314 1.99631 -1.9937 2.28811 … 1.45654 -1.45464 - 0.0 4.97777 5.60084 0.241762 0.0 4.08648 0.176395 - 0.0 0.0 0.165071 0.583094 0.0 0.120439 0.425437 - 0.0 0.0 0.0 2.30358 0.0 0.0 1.68074 - 0.0 -0.0 0.0 -0.0 2.44306 0.125724 -0.12556 - 0.0 0.0 0.0 0.0 0.0 … 0.352731 0.0152258 - 0.0 0.0 0.0 0.0 0.0 0.0103959 0.0367223 - 0.0 0.0 0.0 0.0 0.0 0.0 0.145076 - 0.0 -0.0 0.0 -0.0 0.0 0.48356 -0.482929 - 0.0 0.0 0.0 0.0 0.0 1.35668 0.0585614 - ⋮ ⋱ - 0.0 0.0 0.0 0.0 0.0 0.0 0.3243 - 0.0 -0.0 0.0 -0.0 0.0 0.294343 -0.293959 - 0.0 0.0 0.0 0.0 0.0 0.825808 0.0356463 - 0.0 0.0 0.0 0.0 0.0 0.0243387 0.0859735 - 0.0 0.0 0.0 0.0 0.0 … 0.0 0.339648 - 0.0 -0.0 0.0 -0.0 0.0 0.0473704 -0.0473085 - 0.0 0.0 0.0 0.0 0.0 0.132902 0.00573678 - 0.0 0.0 0.0 0.0 0.0 0.00391698 0.0138362 - 0.0 0.0 0.0 0.0 0.0 0.0 0.0546616
julia> logdet(C)-49.05899785842215
julia> inv(C)40×40 Kronecker.KroneckerProduct{Float64,Array{Float64,2},Array{Float64,2}}: - 24212.1 38835.6 -34543.3 … -45705.6 40654.0 -851.855 - 38835.6 62864.4 -55866.1 -73985.0 65748.7 -1107.9 - -34543.3 -55866.1 49687.8 65748.7 -58477.6 996.832 - 723.813 941.371 -846.999 -1107.9 996.832 -282.199 - 12517.5 20077.9 -17858.7 -23803.6 21172.7 -443.647 - 20077.9 32500.6 -28882.5 … -38531.5 34242.0 -576.995 - -17858.7 -28882.5 25688.4 34242.0 -30455.2 519.152 - 374.208 486.685 -437.895 -576.995 519.152 -146.969 - 4303.57 6902.83 -6139.89 -8338.73 7417.09 -155.416 - 6902.83 11173.8 -9929.89 -13498.1 11995.5 -202.13 - ⋮ ⋱ - 770.945 1002.67 -902.152 -1181.84 1063.36 -301.033 - 13681.7 21945.1 -19519.6 -25902.2 23039.3 -482.761 - 21945.1 35523.2 -31568.6 -41928.6 37260.9 -627.865 - -19519.6 -31568.6 28077.4 37260.9 -33140.2 564.922 - 409.01 531.946 -478.619 … -627.865 564.922 -159.927 - -28495.2 -45705.6 40654.0 54206.3 -48215.1 1010.29 - -45705.6 -73985.0 65748.7 87745.2 -77977.1 1313.95 - 40654.0 65748.7 -58477.6 -77977.1 69353.6 -1182.23 - -851.855 -1107.9 996.832 1313.95 -1182.23 334.684
LinearAlgebra.choleskyFunction
cholesky(K::AbstractKroneckerProduct; check = true)

Wrapper around cholesky from the LinearAlgebra package. Performs Cholesky on the matrices of a AbstractKroneckerProduct instances and returns a CholeskyKronecker type. Similar to Cholesky, size, \, inv, det, and logdet are overloaded to efficiently work with this type.

source
+ 5.64901 -2.32797 1.03394 -0.475965 … -1.44899 0.643555 -0.296253 + 0.0 3.88727 -1.30721 -0.985748 2.41954 -0.813645 -0.613556 + 0.0 0.0 3.47079 1.33289 0.0 2.16031 0.829624 + 0.0 0.0 0.0 2.45087 0.0 0.0 1.52549 + 0.0 -0.0 0.0 -0.0 -0.956145 0.424663 -0.195489 + 0.0 0.0 -0.0 -0.0 … 1.59658 -0.536901 -0.404868 + 0.0 0.0 0.0 0.0 0.0 1.42553 0.547445 + 0.0 0.0 0.0 0.0 0.0 0.0 1.00663 + 0.0 -0.0 0.0 -0.0 -0.298975 0.132787 -0.0611271 + 0.0 0.0 -0.0 -0.0 0.499232 -0.167882 -0.126597 + ⋮ ⋱ + 0.0 0.0 0.0 0.0 0.0 0.0 0.214224 + 0.0 -0.0 0.0 -0.0 0.894184 -0.397144 0.182821 + 0.0 0.0 -0.0 -0.0 -1.49312 0.502108 0.378631 + 0.0 0.0 0.0 0.0 -0.0 -1.33315 -0.511969 + 0.0 0.0 0.0 0.0 … -0.0 -0.0 -0.941394 + 0.0 -0.0 0.0 -0.0 -0.163986 0.0728328 -0.0335278 + 0.0 0.0 -0.0 -0.0 0.273825 -0.0920823 -0.0694378 + 0.0 0.0 0.0 0.0 0.0 0.244488 0.0938908 + 0.0 0.0 0.0 0.0 0.0 0.0 0.172644
julia> logdet(C)18.895749218908648
julia> inv(C)40×40 Kronecker.KroneckerProduct{Float64,Array{Float64,2},Array{Float64,2}}: + 0.843202 0.513028 … -0.157144 0.0873973 -0.177741 + 0.513028 1.3233 -0.405336 -0.103532 -0.107461 + -0.285326 0.338002 -0.103532 -0.557947 0.331625 + 0.580271 0.350827 -0.107461 0.331625 -0.863539 + 0.00767366 0.00466887 -0.897839 0.499342 -1.01552 + 0.00466887 0.0120429 … -2.31588 -0.591529 -0.613974 + -0.00259664 0.00307603 -0.591529 -3.18782 1.89473 + 0.00528082 0.00319274 -0.613974 1.89473 -4.93381 + 1.02083 0.6211 -7.76293 4.31744 -8.78042 + 0.6211 1.60206 -20.0236 -5.1145 -5.30857 + ⋮ ⋱ + -0.469413 -0.283803 2.12064 -6.54434 17.0412 + -0.307139 -0.186872 5.53911 -3.08063 6.26512 + -0.186872 -0.482017 14.2875 3.64937 3.78783 + 0.103931 -0.123118 3.64937 19.6668 -11.6893 + -0.211366 -0.12779 … 3.78783 -11.6893 30.4385 + -0.258278 -0.157144 6.10541 -3.39559 6.90565 + -0.157144 -0.405336 15.7482 4.02247 4.17509 + 0.0873973 -0.103532 4.02247 21.6775 -12.8844 + -0.177741 -0.107461 4.17509 -12.8844 33.5505
LinearAlgebra.choleskyFunction
cholesky(K::AbstractKroneckerProduct; check = true)

Wrapper around cholesky from the LinearAlgebra package. Performs Cholesky on the matrices of a AbstractKroneckerProduct instances and returns a CholeskyKronecker type. Similar to Cholesky, size, \, inv, det, and logdet are overloaded to efficiently work with this type.

source
diff --git a/dev/man/indexed/index.html b/dev/man/indexed/index.html index dbbdf92..5d97c44 100644 --- a/dev/man/indexed/index.html +++ b/dev/man/indexed/index.html @@ -1,2 +1,2 @@ -Indexed Kronecker products · Kronecker.jl
+Indexed Kronecker products · Kronecker.jl
diff --git a/dev/man/kroneckerpowers/index.html b/dev/man/kroneckerpowers/index.html index 045b2fe..b3056b7 100644 --- a/dev/man/kroneckerpowers/index.html +++ b/dev/man/kroneckerpowers/index.html @@ -1,94 +1,94 @@ Kronecker powers and graphs · Kronecker.jl

Kronecker powers and graphs

Kronecker powers

Repeated Kronecker multiplications of the same matrix, i.e.

\[A^{\otimes n}=\otimes_{i=1}^n A = \underbrace{A \otimes A \otimes \ldots \otimes A}_{n\text{ times}}\,.\]

Kronecker powers are supported using kronecker(A, n) or, equivalently, ⊗(A, n). These functions yield an instance of KroneckerPower, as struct which holds the matrix and the power. It works just like instances of KroneckerProduct, but more efficient since only a single matrix has to be stored and manipulated. These products work as expected.

julia> using Kronecker
julia> A = rand(2, 2)2×2 Array{Float64,2}: - 0.333313 0.0035049 - 0.803551 0.271053
julia> K2 = A ⊗ 24×4 KroneckerPower{Float64,Array{Float64,2}}: - 0.111097 0.00116823 0.00116823 1.22843e-5 - 0.267834 0.0903455 0.00281637 0.000950015 - 0.267834 0.00281637 0.0903455 0.000950015 - 0.645694 0.217805 0.217805 0.0734699
julia> inv(K2)4×4 KroneckerPower{Float64,Array{Float64,2}}: - 9.58968 -0.124001 -0.124001 0.00160342 - -28.4291 11.7924 0.367607 -0.152483 - -28.4291 0.367607 11.7924 -0.152483 - 84.2794 -34.9591 -34.9591 14.501
julia> K12 = K2 ⊗ 6 # works recursively4096×4096 KroneckerPower{Float64,KroneckerPower{Float64,Array{Float64,2}}}: - 1.88028e-6 1.97718e-8 1.97718e-8 … 3.26802e-28 3.43643e-30 - 4.53298e-6 1.52906e-6 4.76658e-8 7.87854e-28 2.65758e-28 - 4.53298e-6 4.76658e-8 1.52906e-6 2.52734e-26 2.65758e-28 - 1.09281e-5 3.68626e-6 3.68626e-6 6.09291e-26 2.05526e-26 - 4.53298e-6 4.76658e-8 4.76658e-8 2.52734e-26 2.65758e-28 - 1.09281e-5 3.68626e-6 1.14913e-7 … 6.09291e-26 2.05526e-26 - 1.09281e-5 1.14913e-7 3.68626e-6 1.95453e-24 2.05526e-26 - 2.63455e-5 8.88685e-6 8.88685e-6 4.71198e-24 1.58944e-24 - 4.53298e-6 4.76658e-8 4.76658e-8 2.52734e-26 2.65758e-28 - 1.09281e-5 3.68626e-6 1.14913e-7 6.09291e-26 2.05526e-26 + 0.575462 0.556652 + 0.745298 0.310024
julia> K2 = A ⊗ 24×4 KroneckerPower{Float64,Array{Float64,2}}: + 0.331156 0.320332 0.320332 0.309862 + 0.428891 0.178407 0.414872 0.172576 + 0.428891 0.414872 0.178407 0.172576 + 0.555469 0.23106 0.23106 0.0961148
julia> inv(K2)4×4 KroneckerPower{Float64,Array{Float64,2}}: + 1.71892 -3.08635 -3.08635 5.54159 + -4.13229 3.19064 7.41959 -5.72884 + -4.13229 7.41959 3.19064 -5.72884 + 9.93404 -7.6703 -7.6703 5.92242
julia> K12 = K2 ⊗ 6 # works recursively4096×4096 KroneckerPower{Float64,KroneckerPower{Float64,Array{Float64,2}}}: + 0.00131886 0.00127575 0.00127575 … 0.000915045 0.000885136 + 0.0017081 0.000710522 0.00165227 0.0011851 0.00049297 + 0.0017081 0.00165227 0.000710522 0.000509628 0.00049297 + 0.00221221 0.000920218 0.000920218 0.000660034 0.000274556 + 0.0017081 0.00165227 0.00165227 0.000509628 0.00049297 + 0.00221221 0.000920218 0.0021399 … 0.000660034 0.000274556 + 0.00221221 0.0021399 0.000920218 0.000283834 0.000274556 + 0.0028651 0.0011918 0.0011918 0.000367602 0.000152912 + 0.0017081 0.00165227 0.00165227 0.000509628 0.00049297 + 0.00221221 0.000920218 0.0021399 0.000660034 0.000274556 ⋮ ⋱ ⋮ - 0.0300606 0.01014 0.01014 6.02887e-9 2.03365e-9 - 0.0051722 5.43875e-5 5.43875e-5 3.23367e-11 3.40031e-13 - 0.0124691 0.00420609 0.000131117 7.79573e-11 2.62965e-11 - 0.0124691 0.000131117 0.00420609 … 2.50077e-9 2.62965e-11 - 0.0300606 0.01014 0.01014 6.02887e-9 2.03365e-9 - 0.0124691 0.000131117 0.000131117 2.50077e-9 2.62965e-11 - 0.0300606 0.01014 0.000316098 6.02887e-9 2.03365e-9 - 0.0300606 0.000316098 0.01014 1.93399e-7 2.03365e-9 - 0.0724703 0.0244456 0.0244456 … 4.66246e-7 1.57274e-7
julia> K12^2 # example4096×4096 KroneckerPower{Float64,KroneckerPower{Float64,Array{Float64,2}}}: - 4.77432e-12 8.87792e-14 8.87792e-14 … 4.38842e-31 8.16033e-33 - 2.0354e-11 3.19729e-12 3.78485e-13 1.87088e-30 2.93886e-31 - 2.0354e-11 3.78485e-13 3.19729e-12 1.58044e-29 2.93886e-31 - 8.67734e-11 1.36307e-11 1.36307e-11 6.73777e-29 1.0584e-29 - 2.0354e-11 3.78485e-13 3.78485e-13 1.58044e-29 2.93886e-31 - 8.67734e-11 1.36307e-11 1.61356e-12 … 6.73777e-29 1.0584e-29 - 8.67734e-11 1.61356e-12 1.36307e-11 5.6918e-28 1.0584e-29 - 3.69934e-10 5.81108e-11 5.81108e-11 2.42654e-27 3.81171e-28 - 2.0354e-11 3.78485e-13 3.78485e-13 1.58044e-29 2.93886e-31 - 8.67734e-11 1.36307e-11 1.61356e-12 6.73777e-29 1.0584e-29 - ⋮ ⋱ ⋮ - 4.03666e-5 6.34096e-6 6.34096e-6 6.86675e-15 1.07866e-15 - 2.221e-6 4.12997e-8 4.12997e-8 4.47243e-17 8.31655e-19 - 9.46858e-6 1.48737e-6 1.7607e-7 1.90669e-16 2.99512e-17 - 9.46858e-6 1.7607e-7 1.48737e-6 … 1.6107e-15 2.99512e-17 - 4.03666e-5 6.34096e-6 6.34096e-6 6.86675e-15 1.07866e-15 - 9.46858e-6 1.7607e-7 1.7607e-7 1.6107e-15 2.99512e-17 - 4.03666e-5 6.34096e-6 7.50623e-7 6.86675e-15 1.07866e-15 - 4.03666e-5 7.50623e-7 6.34096e-6 5.80076e-14 1.07866e-15 - 0.000172092 2.70329e-5 2.70329e-5 … 2.47299e-13 3.88468e-14
Kronecker.kroneckerMethod
kronecker(A::AbstractMatrix, pow::Int)

Kronecker power, computes A ⊗ A ⊗ ... ⊗ A. Returns a lazy KroneckerPower type.

source
Kronecker.:⊗Method
⊗(A::AbstractMatrix, pow::Int)

Kronecker power, computes A ⊗ A ⊗ ... ⊗ A. Returns a lazy KroneckerPower type.

source

Kronecker graphs

An exciting application of Kronecker powers (or Krocker products in general) is generating large, realistic graphs from an initial 'seed' via a stochastic process. This is called a Kronecker graph and is described in detail in Leskovec et al. (2008).

If we use an initial matrix $P$ with values in $[0,1]$ as a seed, then $P_n=P^{\otimes n}$ can be seen as a probability distribution for an adjacency matrix of a graph. The elements $(P_n)_{i,j}$ give the probabilities that there is an edge from node $i$ to node $j$. Leskovec and co-authors give two algorithms for sampling adjacency matrices from this distribution, both provided by Kronecker.jl:

  • naivesample gives exact samples, but has a computational time proportional to the number of elements and hence prohibitive for large graphs;
  • fastsample a recursive heuristic, has a computational time proportional to the expected number of edges in the graph.

The latter can easily scale to generate graphs of millions of nodes. Both return the adjacency matrix as a sparse array.

julia> using Kronecker
julia> P = rand(2, 2)2×2 Array{Float64,2}: - 0.0699036 0.484521 - 0.694499 0.762908
julia> P10 = P ⊗ 101024×1024 KroneckerPower{Float64,Array{Float64,2}}: - 2.78609e-12 1.93112e-11 1.93112e-11 … 0.000102875 0.000713057 - 2.76801e-11 3.04066e-11 1.91858e-10 0.00102208 0.00112275 - 2.76801e-11 1.91858e-10 3.04066e-11 0.000161984 0.00112275 - 2.75005e-10 3.02093e-10 3.02093e-10 0.00160932 0.00176784 - 2.76801e-11 1.91858e-10 1.91858e-10 0.000161984 0.00112275 - 2.75005e-10 3.02093e-10 1.90613e-9 … 0.00160932 0.00176784 - 2.75005e-10 1.90613e-9 3.02093e-10 0.000255053 0.00176784 - 2.7322e-9 3.00132e-9 3.00132e-9 0.00253398 0.00278358 - 2.76801e-11 1.91858e-10 1.91858e-10 0.000161984 0.00112275 - 2.75005e-10 3.02093e-10 1.90613e-9 0.00160932 0.00176784 - ⋮ ⋱ - 0.00262752 0.00288633 0.00288633 … 0.0386156 0.0424192 - 2.66196e-5 0.000184508 0.000184508 0.00246848 0.0171097 - 0.000264468 0.000290519 0.0018331 0.0245246 0.0269403 - 0.000264468 0.0018331 0.000290519 0.00388678 0.0269403 - 0.00262752 0.00288633 0.00288633 0.0386156 0.0424192 - 0.000264468 0.0018331 0.0018331 … 0.00388678 0.0269403 - 0.00262752 0.00288633 0.018212 0.0386156 0.0424192 - 0.00262752 0.018212 0.00288633 0.00611998 0.0424192 - 0.0261047 0.028676 0.028676 0.0608026 0.0667917
julia> sum(P10) # expected number of edges1086.2176016047729
julia> A = fastsample(P10)1024×1024 SparseArrays.SparseMatrixCSC{Bool,Int64} with 1082 stored entries: - [1007, 4] = 1 - [1024, 12] = 1 - [1017, 19] = 1 - [1022, 23] = 1 - [998 , 28] = 1 - [957 , 32] = 1 - [1019, 32] = 1 - [748 , 37] = 1 - [764 , 37] = 1 + 0.0226802 0.00943434 0.00943434 3.40302e-6 1.41556e-6 + 0.0135213 0.0130794 0.0130794 4.71781e-6 4.5636e-6 + 0.0175119 0.00728447 0.0169395 6.11017e-6 2.54167e-6 + 0.0175119 0.0169395 0.00728447 … 2.62755e-6 2.54167e-6 + 0.0226802 0.00943434 0.00943434 3.40302e-6 1.41556e-6 + 0.0175119 0.0169395 0.0169395 2.62755e-6 2.54167e-6 + 0.0226802 0.00943434 0.0219389 3.40302e-6 1.41556e-6 + 0.0226802 0.0219389 0.00943434 1.4634e-6 1.41556e-6 + 0.0293738 0.0122187 0.0122187 … 1.89529e-6 7.88389e-7
julia> K12^2 # example4096×4096 KroneckerPower{Float64,KroneckerPower{Float64,Array{Float64,2}}}: + 0.0297211 0.019637 0.019637 0.0129743 … 0.000311299 0.000205678 + 0.0262918 0.0203572 0.0173713 0.0134502 0.000275381 0.000213222 + 0.0262918 0.0173713 0.0203572 0.0134502 0.000322717 0.000213222 + 0.0232582 0.0180084 0.0180084 0.0139435 0.000285482 0.000221043 + 0.0262918 0.0173713 0.0173713 0.0114773 0.000322717 0.000213222 + 0.0232582 0.0180084 0.0153669 0.0118983 … 0.000285482 0.000221043 + 0.0232582 0.0153669 0.0180084 0.0118983 0.000334554 0.000221043 + 0.0205747 0.0159306 0.0159306 0.0123347 0.000295953 0.00022915 + 0.0262918 0.0173713 0.0173713 0.0114773 0.000322717 0.000213222 + 0.0232582 0.0180084 0.0153669 0.0118983 0.000285482 0.000221043 + ⋮ ⋱ ⋮ + 0.00771583 0.00597421 0.00597421 0.00462571 0.000394797 0.000305684 + 0.00985985 0.00651449 0.00651449 0.00430418 0.000430501 0.000284436 + 0.00872221 0.00675343 0.00576284 0.00446205 0.000380829 0.000294868 + 0.00872221 0.00576284 0.00675343 0.00446205 … 0.000446291 0.000294868 + 0.00771583 0.00597421 0.00597421 0.00462571 0.000394797 0.000305684 + 0.00872221 0.00576284 0.00576284 0.00380756 0.000446291 0.000294868 + 0.00771583 0.00597421 0.00509792 0.00394722 0.000394797 0.000305684 + 0.00771583 0.00509792 0.00597421 0.00394722 0.00046266 0.000305684 + 0.00682557 0.0052849 0.0052849 0.00409199 … 0.000409278 0.000316895
Kronecker.kroneckerMethod
kronecker(A::AbstractMatrix, pow::Int)

Kronecker power, computes A ⊗ A ⊗ ... ⊗ A. Returns a lazy KroneckerPower type.

source
Kronecker.:⊗Method
⊗(A::AbstractMatrix, pow::Int)

Kronecker power, computes A ⊗ A ⊗ ... ⊗ A. Returns a lazy KroneckerPower type.

source

Kronecker graphs

An exciting application of Kronecker powers (or Krocker products in general) is generating large, realistic graphs from an initial 'seed' via a stochastic process. This is called a Kronecker graph and is described in detail in Leskovec et al. (2008).

If we use an initial matrix $P$ with values in $[0,1]$ as a seed, then $P_n=P^{\otimes n}$ can be seen as a probability distribution for an adjacency matrix of a graph. The elements $(P_n)_{i,j}$ give the probabilities that there is an edge from node $i$ to node $j$. Leskovec and co-authors give two algorithms for sampling adjacency matrices from this distribution, both provided by Kronecker.jl:

  • naivesample gives exact samples, but has a computational time proportional to the number of elements and hence prohibitive for large graphs;
  • fastsample a recursive heuristic, has a computational time proportional to the expected number of edges in the graph.

The latter can easily scale to generate graphs of millions of nodes. Both return the adjacency matrix as a sparse array.

julia> using Kronecker
julia> P = rand(2, 2)2×2 Array{Float64,2}: + 0.30703 0.553901 + 0.745568 0.558225
julia> P10 = P ⊗ 101024×1024 KroneckerPower{Float64,Array{Float64,2}}: + 7.44413e-6 1.34297e-5 1.34297e-5 … 0.00150686 0.00150686 0.00271846 + 1.80767e-5 1.35345e-5 3.26115e-5 0.00151862 0.00365914 0.00273969 + 1.80767e-5 3.26115e-5 1.35345e-5 0.00365914 0.00151862 0.00273969 + 4.38961e-5 3.28661e-5 3.28661e-5 0.0036877 0.0036877 0.00276108 + 1.80767e-5 3.26115e-5 3.26115e-5 0.00151862 0.00151862 0.00273969 + 4.38961e-5 3.28661e-5 7.91912e-5 … 0.00153048 0.0036877 0.00276108 + 4.38961e-5 7.91912e-5 3.28661e-5 0.0036877 0.00153048 0.00276108 + 0.000106594 7.98094e-5 7.98094e-5 0.00371649 0.00371649 0.00278263 + 1.80767e-5 3.26115e-5 3.26115e-5 0.00151862 0.00151862 0.00273969 + 4.38961e-5 3.28661e-5 7.91912e-5 0.00153048 0.0036877 0.00276108 + ⋮ ⋱ + 0.0218559 0.016364 0.016364 … 0.00389401 0.00389401 0.00291554 + 0.00370643 0.00668663 0.00668663 0.00159116 0.00159116 0.00287055 + 0.0090004 0.00673883 0.0162373 0.00160358 0.00386384 0.00289296 + 0.0090004 0.0162373 0.00673883 0.00386384 0.00160358 0.00289296 + 0.0218559 0.016364 0.016364 0.00389401 0.00389401 0.00291554 + 0.0090004 0.0162373 0.0162373 … 0.00160358 0.00160358 0.00289296 + 0.0218559 0.016364 0.0394293 0.0016161 0.00389401 0.00291554 + 0.0218559 0.0394293 0.016364 0.00389401 0.0016161 0.00291554 + 0.053073 0.0397371 0.0397371 0.00392441 0.00392441 0.0029383
julia> sum(P10) # expected number of edges2259.5821501399823
julia> A = fastsample(P10)1024×1024 SparseArrays.SparseMatrixCSC{Bool,Int64} with 2250 stored entries: + [702 , 4] = 1 + [749 , 4] = 1 + [761 , 4] = 1 + [878 , 4] = 1 + [925 , 4] = 1 + [248 , 5] = 1 + [571 , 5] = 1 + [1024, 5] = 1 + [120 , 6] = 1 ⋮ - [752 , 1022] = 1 - [999 , 1022] = 1 - [1008, 1022] = 1 - [1019, 1022] = 1 - [492 , 1023] = 1 - [191 , 1024] = 1 - [469 , 1024] = 1 - [531 , 1024] = 1 - [593 , 1024] = 1 - [973 , 1024] = 1
Kronecker.isprobFunction
isprob(A::AbstractArray)

Test if a matrix can be interpeted as a probability matrix, i.e., all elements are between 0 and 1.

source
isprob(K::AbstractKroneckerProduct)

Test if a Kronecker product can be interpeted as a probability matrix, i.e., all elements are between 0 and 1.

source
Kronecker.naivesampleFunction
naivesample(P::AbstractKroneckerProduct)

Sample a Kronecker graph from a probabilistic Kronecker product P using the naive method. This method has a time complexity in the size of the Kronecker product (but is still light in memory use). Consider using fastsample.

source
Kronecker.fastsampleFunction
fastsample(P::AbstractKroneckerProduct)

Uses the heuristic sampling from Leskovec et al. (2008) to sample a large Kronecker graph.

source
+ [119 , 1022] = 1 + [188 , 1023] = 1 + [510 , 1023] = 1 + [294 , 1024] = 1 + [389 , 1024] = 1 + [410 , 1024] = 1 + [576 , 1024] = 1 + [660 , 1024] = 1 + [700 , 1024] = 1 + [998 , 1024] = 1
Kronecker.isprobFunction
isprob(A::AbstractArray)

Test if a matrix can be interpeted as a probability matrix, i.e., all elements are between 0 and 1.

source
isprob(K::AbstractKroneckerProduct)

Test if a Kronecker product can be interpeted as a probability matrix, i.e., all elements are between 0 and 1.

source
Kronecker.naivesampleFunction
naivesample(P::AbstractKroneckerProduct)

Sample a Kronecker graph from a probabilistic Kronecker product P using the naive method. This method has a time complexity in the size of the Kronecker product (but is still light in memory use). Consider using fastsample.

source
Kronecker.fastsampleFunction
fastsample(P::AbstractKroneckerProduct)

Uses the heuristic sampling from Leskovec et al. (2008) to sample a large Kronecker graph.

source
diff --git a/dev/man/kroneckersums/index.html b/dev/man/kroneckersums/index.html index 95ef6ac..5c47741 100644 --- a/dev/man/kroneckersums/index.html +++ b/dev/man/kroneckersums/index.html @@ -1,62 +1,62 @@ Kronecker sums · Kronecker.jl

Kronecker sums

A Kronecker sum between two square matrices of the same size is defined as

\[A \oplus B = A ⊗ I + I \oplus B\,.\]

To construct objects of the KroneckerSum type, one can either use kroneckersum or the binary operator . Lazy Kronecker sums work like lazy Kronecker products, though there are far fewer methods to process these constructs efficiently. The most important property for Kronecker sums relates to matrix exponentiation:

\[\exp(A \oplus B) = \exp(A) \otimes \exp(B)\,.\]

The function collect can be used to transform a KroneckerSum struct into a sparse array. It is recommended to make it 'dense' this way before doing operations such as multiplication with a vector.


julia> A, B = rand(Bool, 5, 5), rand(4, 4);
julia> K = A ⊕ B20×20 KroneckerSum{Float64,Array{Bool,2},Array{Float64,2}}: - 1.75853 0.678104 0.677818 0.493941 … 0.0 0.0 0.0 - 0.861629 1.54312 0.963897 0.505276 0.0 0.0 0.0 - 0.989594 0.193727 1.3328 0.909029 0.0 0.0 0.0 - 0.504015 0.572695 0.838269 1.2505 0.0 0.0 0.0 - 1.0 0.0 0.0 0.0 0.0 0.0 0.0 - 0.0 1.0 0.0 0.0 … 0.0 0.0 0.0 - 0.0 0.0 1.0 0.0 0.0 0.0 0.0 - 0.0 0.0 0.0 1.0 0.0 0.0 0.0 - 1.0 0.0 0.0 0.0 0.0 0.0 0.0 - 0.0 1.0 0.0 0.0 1.0 0.0 0.0 - 0.0 0.0 1.0 0.0 … 0.0 1.0 0.0 - 0.0 0.0 0.0 1.0 0.0 0.0 1.0 - 1.0 0.0 0.0 0.0 0.0 0.0 0.0 - 0.0 1.0 0.0 0.0 0.0 0.0 0.0 - 0.0 0.0 1.0 0.0 0.0 0.0 0.0 - 0.0 0.0 0.0 1.0 … 0.0 0.0 0.0 - 0.0 0.0 0.0 0.0 0.678104 0.677818 0.493941 - 0.0 0.0 0.0 0.0 0.543121 0.963897 0.505276 - 0.0 0.0 0.0 0.0 0.193727 0.332797 0.909029 - 0.0 0.0 0.0 0.0 0.572695 0.838269 0.250501
julia> exp(K)20×20 Kronecker.KroneckerProduct{Float64,Array{Float64,2},Array{Float64,2}}: - 27.6038 14.844 18.8656 15.0359 … 7.07669 3.8055 4.83652 3.85471 - 23.9644 20.8075 21.5761 16.4567 6.14369 5.33435 5.5314 4.21894 - 20.8566 11.3642 21.4953 15.7453 5.34694 2.9134 5.51069 4.03658 - 17.5128 12.0943 16.9858 17.8438 4.48969 3.10059 4.35458 4.57457 - 17.3402 9.32474 11.8511 9.4453 5.60146 3.0122 3.82828 3.05114 - 15.0541 13.0709 13.5538 10.3378 … 4.86295 4.22234 4.3783 3.33945 - 13.1018 7.13879 13.503 9.89096 4.2323 2.30606 4.36192 3.1951 - 11.0012 7.59747 10.6702 11.2092 3.55375 2.45423 3.44681 3.62094 - 17.3402 9.32474 11.8511 9.4453 10.2635 5.51924 7.01455 5.5906 - 15.0541 13.0709 13.5538 10.3378 8.91037 7.73657 8.02235 6.11886 - 13.1018 7.13879 13.503 9.89096 … 7.75482 4.22539 7.99232 5.85438 - 11.0012 7.59747 10.6702 11.2092 6.51153 4.49688 6.31558 6.63463 - 24.8057 13.3393 16.9533 13.5118 4.11678 2.21381 2.81359 2.24243 - 21.5353 18.6983 19.389 14.7885 3.57401 3.1032 3.21782 2.45432 - 18.7424 10.2122 19.3164 14.1493 3.11052 1.69484 3.20578 2.34823 - 15.7376 10.8684 15.264 16.0351 … 2.61182 1.80373 2.53323 2.6612 - 0.0 0.0 0.0 0.0 4.66208 2.50704 3.18627 2.53945 - 0.0 0.0 0.0 0.0 4.04742 3.51424 3.64405 2.77941 - 0.0 0.0 0.0 0.0 3.52253 1.91933 3.63041 2.65927 - 0.0 0.0 0.0 0.0 2.95778 2.04265 2.86877 3.01369
julia> collect(K)20×20 SparseArrays.SparseMatrixCSC{Float64,Int64} with 112 stored entries: - [1 , 1] = 1.75853 - [2 , 1] = 0.861629 - [3 , 1] = 0.989594 - [4 , 1] = 0.504015 - [5 , 1] = 1.0 - [9 , 1] = 1.0 + 0.313838 0.75306 0.0112007 0.540038 … 0.0 0.0 0.0 + 0.691031 0.641369 0.64634 0.209703 0.0 0.0 0.0 + 0.321617 0.216254 0.870073 0.304266 0.0 0.0 0.0 + 0.323434 0.104137 0.366677 0.78911 0.0 0.0 0.0 + 0.0 0.0 0.0 0.0 0.0 0.0 0.0 + 0.0 0.0 0.0 0.0 … 1.0 0.0 0.0 + 0.0 0.0 0.0 0.0 0.0 1.0 0.0 + 0.0 0.0 0.0 0.0 0.0 0.0 1.0 + 0.0 0.0 0.0 0.0 0.0 0.0 0.0 + 0.0 0.0 0.0 0.0 0.0 0.0 0.0 + 0.0 0.0 0.0 0.0 … 0.0 0.0 0.0 + 0.0 0.0 0.0 0.0 0.0 0.0 0.0 + 1.0 0.0 0.0 0.0 0.0 0.0 0.0 + 0.0 1.0 0.0 0.0 0.0 0.0 0.0 + 0.0 0.0 1.0 0.0 0.0 0.0 0.0 + 0.0 0.0 0.0 1.0 … 0.0 0.0 0.0 + 1.0 0.0 0.0 0.0 0.75306 0.0112007 0.540038 + 0.0 1.0 0.0 0.0 0.641369 0.64634 0.209703 + 0.0 0.0 1.0 0.0 0.216254 0.870073 0.304266 + 0.0 0.0 0.0 1.0 0.104137 0.366677 0.78911
julia> exp(K)20×20 Kronecker.KroneckerProduct{Float64,Array{Float64,2},Array{Float64,2}}: + 2.05929 1.50266 0.755388 1.30741 … 0.0 0.0 0.0 + 1.61831 2.65953 1.7201 1.13753 0.0 0.0 0.0 + 0.961594 0.839322 2.79314 1.03977 0.0 0.0 0.0 + 0.879089 0.611547 1.05038 2.61121 0.0 0.0 0.0 + 4.2274 3.08473 1.55069 2.68391 3.6496 1.83465 3.17538 + 3.32213 5.45959 3.53109 2.33517 … 6.45933 4.17769 2.76277 + 1.974 1.723 5.73388 2.13449 2.0385 6.78385 2.52535 + 1.80463 1.25541 2.15627 5.3604 1.4853 2.55112 6.34197 + 0.0 0.0 0.0 0.0 0.0 0.0 0.0 + 0.0 0.0 0.0 0.0 0.0 0.0 0.0 + 0.0 0.0 0.0 0.0 … 0.0 0.0 0.0 + 0.0 0.0 0.0 0.0 0.0 0.0 0.0 + 5.00151 3.6496 1.83465 3.17538 1.77809 0.893844 1.54705 + 3.93046 6.45933 4.17769 2.76277 3.14699 2.03538 1.34603 + 2.33547 2.0385 6.78385 2.52535 0.993162 3.3051 1.23035 + 2.13509 1.4853 2.55112 6.34197 … 0.723638 1.24291 3.08982 + 3.21084 2.34295 1.1778 2.03851 2.80931 1.41224 2.44427 + 2.52326 4.14673 2.68197 1.77363 4.97213 3.21581 2.12667 + 1.49932 1.30867 4.35506 1.62121 1.56916 5.22193 1.94391 + 1.37067 0.953524 1.63776 4.07139 1.14332 1.96375 4.88179
julia> collect(K)20×20 SparseArrays.SparseMatrixCSC{Float64,Int64} with 116 stored entries: + [1 , 1] = 0.313838 + [2 , 1] = 0.691031 + [3 , 1] = 0.321617 + [4 , 1] = 0.323434 [13, 1] = 1.0 - [1 , 2] = 0.678104 - [2 , 2] = 1.54312 + [17, 1] = 1.0 + [1 , 2] = 0.75306 + [2 , 2] = 0.641369 + [3 , 2] = 0.216254 ⋮ - [11, 19] = 1.0 - [17, 19] = 0.677818 - [18, 19] = 0.963897 - [19, 19] = 0.332797 - [20, 19] = 0.838269 - [12, 20] = 1.0 - [17, 20] = 0.493941 - [18, 20] = 0.505276 - [19, 20] = 0.909029 - [20, 20] = 0.250501
Kronecker.kroneckersumFunction
kroneckersum(A::AbstractMatrix, B::AbstractMatrix)

Construct a sum of Kronecker products between two square matrices and their respective identity matrices. Does not evaluate the Kronecker products explicitly.

source
kroneckersum(A::AbstractMatrix, B::AbstractMatrix...)

Higher-order lazy kronecker sum, e.g.

kroneckersum(A,B,C,D)
source
kroneckersum(A::AbstractMatrix, pow::Int)

Kronecker-sum power, computes A ⊕ A ⊕ ... ⊕ A = (A ⊗ I ⊗ ... ⊗ I) + (I ⊗ A ⊗ ... ⊗ I) + ... (I ⊗ I ⊗ ... A).

source
Kronecker.:⊕Function
⊕(A::AbstractMatrix, B::AbstractMatrix)

Binary operator for kroneckersum, computes as Lazy Kronecker sum. See kroneckersum for documentation.

source
Base.collectMethod
collect(K::AbstractKroneckerSum)

Collects a lazy instance of the AbstractKroneckerSum type into a full, native matrix. Returns the result as a sparse matrix.

source
Base.expFunction
exp(K::AbstractKroneckerSum)

Computes the matrix exponential of an AbstractKroneckerSum K. Returns an instance of KroneckerProduct.

source
Missing docstring.

Missing docstring for mul!(x::AbstractVector, K::AbstractKroneckerSum, v::AbstractVector). Check Documenter's build log for details.

+ [7 , 19] = 1.0 + [17, 19] = 0.0112007 + [18, 19] = 0.64634 + [19, 19] = 0.870073 + [20, 19] = 0.366677 + [8 , 20] = 1.0 + [17, 20] = 0.540038 + [18, 20] = 0.209703 + [19, 20] = 0.304266 + [20, 20] = 0.78911
Kronecker.kroneckersumFunction
kroneckersum(A::AbstractMatrix, B::AbstractMatrix)

Construct a sum of Kronecker products between two square matrices and their respective identity matrices. Does not evaluate the Kronecker products explicitly.

source
kroneckersum(A::AbstractMatrix, B::AbstractMatrix...)

Higher-order lazy kronecker sum, e.g.

kroneckersum(A,B,C,D)
source
kroneckersum(A::AbstractMatrix, pow::Int)

Kronecker-sum power, computes A ⊕ A ⊕ ... ⊕ A = (A ⊗ I ⊗ ... ⊗ I) + (I ⊗ A ⊗ ... ⊗ I) + ... (I ⊗ I ⊗ ... A).

source
Kronecker.:⊕Function
⊕(A::AbstractMatrix, B::AbstractMatrix)

Binary operator for kroneckersum, computes as Lazy Kronecker sum. See kroneckersum for documentation.

source
Base.collectMethod
collect(K::AbstractKroneckerSum)

Collects a lazy instance of the AbstractKroneckerSum type into a full, native matrix. Returns the result as a sparse matrix.

source
Base.expFunction
exp(K::AbstractKroneckerSum)

Computes the matrix exponential of an AbstractKroneckerSum K. Returns an instance of KroneckerProduct.

source
Missing docstring.

Missing docstring for mul!(x::AbstractVector, K::AbstractKroneckerSum, v::AbstractVector). Check Documenter's build log for details.

diff --git a/dev/man/multiplication/index.html b/dev/man/multiplication/index.html index 5feabed..2a4dcfc 100644 --- a/dev/man/multiplication/index.html +++ b/dev/man/multiplication/index.html @@ -1,67 +1,67 @@ Multiplication · Kronecker.jl

Multiplication

Kronecker.jl allows for efficient multiplication of large Kronecker systems by overloading the multiplication function *. We distinguish three cases:

  • Kronecker-Kronecker multiplications yield again a type of AbstractKroneckerProduct;
  • Kronecker-vector multiplications use the 'vec trick' and yield a vector;
  • sampled Kronecker-vector multiplications use the sampled-vec trick to yield a vector.

Kronecker-kronecker multiplications

Multiplying two conformable Kronecker products of the same order yield a new Kronecker product, based on the mixed-product property:

\[(A \otimes B)(C \otimes D) = (AC) \otimes (BD),\]

A, B, C, D = randn(5, 5), randn(4, 4), randn(5, 4), randn(4, 4);
 (A ⊗ B) * (C ⊗ D)
20×16 Kronecker.KroneckerProduct{Float64,Array{Float64,2},Array{Float64,2}}:
- -1.41597   -0.634721   -0.82631    …  -4.01667   -5.22909    -7.58473
-  0.786877   0.913958    0.359631       5.78375    2.27584    -0.0398716
- -0.995304  -0.395844    0.0658113     -2.505      0.41647    -5.01377
- -1.15645   -0.323985    0.919331      -2.05026    5.81775     3.95641
- 12.105      5.42616     7.06403        1.74613    2.2732      3.29724
- -6.72692   -7.81332    -3.07445    …  -2.51432   -0.989355    0.0173331
-  8.50874    3.38402    -0.562613       1.08898   -0.181049    2.1796
-  9.88636    2.76971    -7.85926        0.891291  -2.5291     -1.71994
-  8.4957     3.80827     4.95779       -7.35561   -9.57587   -13.8897
- -4.72119   -5.48367    -2.15776       10.5916     4.16767    -0.0730157
-  5.97174    2.37503    -0.394862   …  -4.58732    0.762669   -9.18157
-  6.9386     1.94388    -5.51591       -3.75457   10.6539      7.24525
- -7.94352   -3.56075    -4.63555       -3.00544   -3.91263    -5.67522
-  4.41434    5.12725     2.01751        4.32765    1.70288    -0.0298337
- -5.5836    -2.22066     0.369198      -1.87435    0.311621   -3.75152
- -6.48762   -1.81754     5.1574     …  -1.53409    4.35309     2.96035
-  0.357149   0.160095    0.208419       2.03164    2.64489     3.83638
- -0.198473  -0.230527   -0.0907095     -2.92544   -1.15112     0.0201672
-  0.251045   0.0998433  -0.0165995      1.26703   -0.210652    2.53598
-  0.29169    0.0817185  -0.231882       1.03703   -2.94264    -2.00116

The Vec trick

Reshaping allows computing a product between a Kronecker product and vector as two matrix multiplications. This is the so-called vec trick which holds for any set of conformable matrices:

\[(A \otimes B) \text{vec}(X) = \text{vec}(B^\intercal X A).\]

Here, $\text{vec}(\cdot)$ is the vectorization operator, which stacks all columns of a matrix into a vector.

A, B = rand(10, 10), rand(5, 6);
+ -2.53001     1.32594      1.31749     …  -0.182948     0.547951
+  6.14912     7.16137      2.66271        -0.369747    -0.919557
+  1.19679     0.886609     0.293427       -0.0407456   -0.405255
+ -2.4154     -0.0394593   -7.63511         1.06022      1.92124
+  1.26891    -0.66502     -0.660778       -0.0472649    0.141564
+ -3.08406    -3.59175     -1.33547     …  -0.0955249   -0.237569
+ -0.600245   -0.444674    -0.147167       -0.0105267   -0.104698
+  1.21143     0.0197906    3.82935         0.27391      0.496356
+ -0.0692255   0.0362801    0.0360487      -0.0210722    0.0631141
+  0.168251    0.195947     0.0728564      -0.0425882   -0.105916
+  0.0327463   0.0242591    0.00802866  …  -0.00469315  -0.046678
+ -0.0660895  -0.00107968  -0.20891         0.122118     0.221292
+  1.64099    -0.860019    -0.854533       -0.212799     0.637361
+ -3.98838    -4.64493     -1.72706        -0.430079    -1.0696
+ -0.77625    -0.575063    -0.190319       -0.0473941   -0.471381
+  1.56665     0.0255937    4.9522      …   1.23322      2.23473
+ -1.31762     0.690545     0.686141       -1.43423      4.29569
+  3.20243     3.72961      1.38673        -2.89865     -7.20892
+  0.623284    0.461742     0.152815       -0.319427    -3.17701
+ -1.25793    -0.0205503   -3.97633         8.31165     15.0617

The Vec trick

Reshaping allows computing a product between a Kronecker product and vector as two matrix multiplications. This is the so-called vec trick which holds for any set of conformable matrices:

\[(A \otimes B) \text{vec}(X) = \text{vec}(B^\intercal X A).\]

Here, $\text{vec}(\cdot)$ is the vectorization operator, which stacks all columns of a matrix into a vector.

A, B = rand(10, 10), rand(5, 6);
 x = randn(60);
 (A ⊗ B) * x
50-element Array{Float64,1}:
-  0.8732028865534095
- -0.4713619754955599
-  1.151994188869568
-  0.4530859295184606
- -1.0289208685903914
- -2.557131243968723
- -5.606978585939877
- -4.5408861723006435
- -3.215197450946855
- -2.1736822640065254
+ -6.755234772252771
+ -1.5339020476853158
+  0.28718084992929105
+ -4.461604506324915
+ -1.683274371359666
+ -7.108126720386315
+ -2.963076723433096
+  0.5198640466570326
+ -5.503484373407693
+ -0.8754558089887536
   ⋮
- -2.2775682510587627
- -2.513796579857731
- -0.49281054900392074
- -0.19563486071303227
- -0.2633446226701133
- -3.274578954963514
- -2.717018017998703
- -0.7185585428910832
-  1.1692304644213616

Note that this trick is extended to also work with matrices:

A, B = rand(10, 10), rand(5, 6);
+ -1.7003184119406807
+  0.4328280494699081
+ -5.023359964824601
+ -1.0650826889880298
+ -7.945219678754793
+ -2.4329946184020574
+ -0.20306351171838877
+ -6.644509080895488
+ -1.4967462019517703

Note that this trick is extended to also work with matrices:

A, B = rand(10, 10), rand(5, 6);
 x = randn(60, 2);
 (A ⊗ B) * x
50×2 Array{Float64,2}:
-  1.65095     0.673186
-  1.08421    -0.118595
-  0.826557    0.48378
-  2.38658    -0.144422
- -0.0628015   0.0195526
-  5.58909     1.95851
-  1.23669     2.05705
-  3.78343     2.01431
-  3.51855     0.53174
-  0.914412    2.33533
-  ⋮          
-  2.54741     2.73608
-  4.09452     3.2244
-  3.87428     2.3917
-  2.08825     2.44305
-  3.97916    -1.24857
- -0.216333    0.0153396
-  2.29598    -0.471994
-  2.02098    -0.469581
- -1.06236     0.186135

The vec trick works with higher-order Kronecker products. However, at the moment this has a substantial overhead and likely be relatively slow.

Docstrings

Missing docstring.

Missing docstring for mul!. Check Documenter's build log for details.

LinearAlgebra.lmul!Function
lmul!(a::Number, K::AbstractKroneckerProduct)

Scale an AbstractKroneckerProduct K inplace by a factor a by rescaling the left matrix.

source
lmul!(a::Number, K::KroneckerPower)

Scale an KroneckerPower K inplace by a factor a by rescaling the matrix the base matrix with a factor a^(1/N).

It is recommended to rewrite your Kronecker product rather as copy(A) ⊗ (A ⊗ n - 1) (note the copy) for numerical stability. This will only modify the first matrix, leaving the chain of Kronecker products alone.

source
LinearAlgebra.rmul!Function
rmul!(K::AbstractKroneckerProduct, a::Number)

Scale an AbstractKroneckerProduct K inplace by a factor a by rescaling the right matrix.

source

Sampled Kronecker-vector multiplications

See Indexed Kronecker products for the specifics.

+ 3.6005 -2.62589 + 4.18739 -0.533891 + 2.57193 -1.84092 + 4.49801 0.55351 + 5.46304 -3.07077 + 0.147221 -2.64655 + 1.84116 -1.82511 + -0.593763 -2.94895 + 1.32617 -2.69926 + 1.45043 -3.32702 + ⋮ + 2.07592 0.227418 + 0.418109 -1.04095 + 2.00125 1.076 + 2.47961 -1.98871 + 2.30232 -2.0384 + 4.41552 0.426986 + 2.32245 -1.57576 + 5.42984 1.64215 + 3.68175 -1.81372

The vec trick works with higher-order Kronecker products. However, at the moment this has a substantial overhead and likely be relatively slow.

Docstrings

Missing docstring.

Missing docstring for mul!. Check Documenter's build log for details.

LinearAlgebra.lmul!Function
lmul!(a::Number, K::AbstractKroneckerProduct)

Scale an AbstractKroneckerProduct K inplace by a factor a by rescaling the left matrix.

source
lmul!(a::Number, K::KroneckerPower)

Scale an KroneckerPower K inplace by a factor a by rescaling the matrix the base matrix with a factor a^(1/N).

It is recommended to rewrite your Kronecker product rather as copy(A) ⊗ (A ⊗ n - 1) (note the copy) for numerical stability. This will only modify the first matrix, leaving the chain of Kronecker products alone.

source
LinearAlgebra.rmul!Function
rmul!(K::AbstractKroneckerProduct, a::Number)

Scale an AbstractKroneckerProduct K inplace by a factor a by rescaling the right matrix.

source

Sampled Kronecker-vector multiplications

See Indexed Kronecker products for the specifics.

diff --git a/dev/man/types/index.html b/dev/man/types/index.html index 8a5ee78..1970d6e 100644 --- a/dev/man/types/index.html +++ b/dev/man/types/index.html @@ -1,2 +1,2 @@ -Types · Kronecker.jl

Types

The abstract type at the top of the hierarchy of Kronecker.jl's type system is GeneralizedKroneckerProduct a subtype of AbstractMatrix. GeneralizedKroneckerProduct contains all subtypes which contain a Kronecker product.

Pure Kronecker products, i.e., all expressions that one can write as A ⊗ B, with A and B AbstractMatix types are part of the abstract type AbstractKroneckerProduct <: GeneralizedKroneckerProduct. Concrete instantiations are stored in the structure KroneckerProduct <: AbstractKroneckerProduct, a container for A and B. Instances of KroneckerProduct structs are annotated with the element type of the Kronecker product (promoted from the element types of A and B) and the types of A and B.

For Kronecker powers, iterative multiplications of the same matrix, i.e.,

\[\bigotimes_{i=1}^K A = A\otimes A \otimes \ldots \otimes A\,,\]

are stored in the structure KroneckerPower <: AbstractKroneckerProduct. This is more efficient, as it only processes a single matrix, irregardless of the order of the product.

Special cases are KroneckerSum <: AbstractKroneckerSum <: GeneralizedKroneckerProduct for the Kronecker sum:

\[A \oplus B = A \otimes I + I \otimes B\,.\]

These work similar to instances of AbstractKroneckerProduct.

Finally, we have IndexedKroneckerProduct <: GeneralizedKroneckerProduct, which stores submatrices of a Kronecker product. This contains both the Kronecker product as well as the indices.

It is important to note that since all instances of subtypes of GeneralizedKroneckerProduct are instances of an AbstractMatrix, it is possible to combine them at heart. This is because Kronecker products are between any types of matrices, which Kronecker products themselves are.

+Types · Kronecker.jl

Types

The abstract type at the top of the hierarchy of Kronecker.jl's type system is GeneralizedKroneckerProduct a subtype of AbstractMatrix. GeneralizedKroneckerProduct contains all subtypes which contain a Kronecker product.

Pure Kronecker products, i.e., all expressions that one can write as A ⊗ B, with A and B AbstractMatix types are part of the abstract type AbstractKroneckerProduct <: GeneralizedKroneckerProduct. Concrete instantiations are stored in the structure KroneckerProduct <: AbstractKroneckerProduct, a container for A and B. Instances of KroneckerProduct structs are annotated with the element type of the Kronecker product (promoted from the element types of A and B) and the types of A and B.

For Kronecker powers, iterative multiplications of the same matrix, i.e.,

\[\bigotimes_{i=1}^K A = A\otimes A \otimes \ldots \otimes A\,,\]

are stored in the structure KroneckerPower <: AbstractKroneckerProduct. This is more efficient, as it only processes a single matrix, irregardless of the order of the product.

Special cases are KroneckerSum <: AbstractKroneckerSum <: GeneralizedKroneckerProduct for the Kronecker sum:

\[A \oplus B = A \otimes I + I \otimes B\,.\]

These work similar to instances of AbstractKroneckerProduct.

Finally, we have IndexedKroneckerProduct <: GeneralizedKroneckerProduct, which stores submatrices of a Kronecker product. This contains both the Kronecker product as well as the indices.

It is important to note that since all instances of subtypes of GeneralizedKroneckerProduct are instances of an AbstractMatrix, it is possible to combine them at heart. This is because Kronecker products are between any types of matrices, which Kronecker products themselves are.

diff --git a/dev/search/index.html b/dev/search/index.html index 3a1ef98..ae52e16 100644 --- a/dev/search/index.html +++ b/dev/search/index.html @@ -1,2 +1,2 @@ -Search · Kronecker.jl

Loading search...

    +Search · Kronecker.jl

    Loading search...