Functions
BlockTensorFactorization.Core.:×₁ — Method
1-mode product between a tensor and a matrix
BlockTensorFactorization.Core.:×₂ — Function
2-mode product between a tensor and a matrix. See nmode_product.
BlockTensorFactorization.Core.:×₃ — Function
3-mode product between a tensor and a matrix. See nmode_product.
BlockTensorFactorization.Core.:×₄ — Function
4-mode product between a tensor and a matrix. See nmode_product.
BlockTensorFactorization.Core.:×₅ — Function
5-mode product between a tensor and a matrix. See nmode_product.
BlockTensorFactorization.Core.:×₆ — Function
6-mode product between a tensor and a matrix. See nmode_product.
BlockTensorFactorization.Core.:×₇ — Function
7-mode product between a tensor and a matrix. See nmode_product.
BlockTensorFactorization.Core.:×₈ — Function
8-mode product between a tensor and a matrix. See nmode_product.
BlockTensorFactorization.Core.:×₉ — Function
9-mode product between a tensor and a matrix. See nmode_product.
BlockTensorFactorization.Core.:⋅₁ — Function
Slice-wise dot along mode 1. See slicewise_dot.
BlockTensorFactorization.Core.:⋅₂ — Function
Slice-wise dot along mode 2. See slicewise_dot.
BlockTensorFactorization.Core.:⋅₃ — Function
Slice-wise dot along mode 3. See slicewise_dot.
BlockTensorFactorization.Core.:⋅₄ — Function
Slice-wise dot along mode 4. See slicewise_dot.
BlockTensorFactorization.Core.:⋅₅ — Function
Slice-wise dot along mode 5. See slicewise_dot.
BlockTensorFactorization.Core.:⋅₆ — Function
Slice-wise dot along mode 6. See slicewise_dot.
BlockTensorFactorization.Core.:⋅₇ — Function
Slice-wise dot along mode 7. See slicewise_dot.
BlockTensorFactorization.Core.:⋅₈ — Function
Slice-wise dot along mode 8. See slicewise_dot.
BlockTensorFactorization.Core.:⋅₉ — Function
Slice-wise dot along mode 9. See slicewise_dot.
BlockTensorFactorization.Core.DEFAULT_INIT — Function
Default initialization function to use when creating a random decomposition.
BlockTensorFactorization.Core.Diagonal_col_norm — Method
Diagonal_col_norm(X)Calculates a diagonal matrix with entries that are the Euclidean norm of each column of X.
Shorthand for Diagonal(norm.(eachcol(X))).
BlockTensorFactorization.Core.IntervalConstraint — Method
Entrywise(x -> clamp(x, a, b), x -> a ≤ x ≤ b)
BlockTensorFactorization.Core.ReLU — Method
max(0,x)
BlockTensorFactorization.Core._factorize — Method
_factorize(Y; kwargs...)Inner level function once keyword arguments are set
BlockTensorFactorization.Core._gettuckerindex — Method
Just computes index I in the tucker product
BlockTensorFactorization.Core.abs_randn — Method
abs_randn(x...)Folded normal or more specifically the half-normal initialization.
BlockTensorFactorization.Core.all_recursive — Method
all_recursive(x)
all_recursive(f, x)Like all but checks recursively on nested types like arrays of vectors, tuples of sets of arrays, etc.
BlockTensorFactorization.Core.array — Method
array(D::AbstractDecomposition)Turns a decomposition into the full array, usually by multiplying the factors to reconstruct the full array.
BlockTensorFactorization.Core.best_breakpoint — Method
best_breakpoint(xs, ys; breakpoints=xs)Breakpoint z in breakpoints that minimizes the breakpoint_error.
BlockTensorFactorization.Core.binary! — Function
Entrywise(binaryproject, x -> x in (0, 1))
BlockTensorFactorization.Core.breakpoint_curvature — Method
breakpoint_curvature(y)This is a hacked way to fit the data y with a breakpoint model, which can be called by k = standard_curvature(...; model=:breakpoints)
This lets us call argmax(k) to get the breakpoint that minimizes the model error.
BlockTensorFactorization.Core.breakpoint_error — Method
breakpoint_error(xs, ys, z)Squared L2 error between the best breakpoint model (with breakpoint z) evaluated at xs and the data ys.
BlockTensorFactorization.Core.breakpoint_model — Method
breakpoint_model(a, b, c, z)Returns a function x -> a + b*(min(x, z) - z) + c*(max(x, z) - z).
BlockTensorFactorization.Core.breakpoint_model_coefficients — Method
breakpoint_model_coefficients(xs, ys, breakpoint)Least squares fit data $(x_i, y_i)$
$\min_{a,b,c} 0.5\sum_{i} (f(x_i; a,b,c) - y_i)^2$
with the model
$f(x; a,b,c) = a + b(\min(x, z) - x) + c(\max(x, z) - x)$
for some fixed $z$.
BlockTensorFactorization.Core.check — Method
check(C::AbstractConstraint, A::AbstractArray)::BoolReturns true if A satisfies the constraint C.
BlockTensorFactorization.Core.check — Method
check(C::Entrywise, A::AbstractArray)::BoolChecks if A is entry-wise constrained.
BlockTensorFactorization.Core.circle_curvature — Method
circle_curvature(y::AbstractVector{<:Real}; h=1, estimate_endpoints=true)Inverse radius of a the circle passing through each 3 adjacent points on y, (0,y[i-1]), (h,y[i]), and (2h,y[i+1]).
If estimate_endpoints=true, assumes the function that y comes from is 1 to the left of the given values, and 0 to the right. This is typical of relative error decay as a function of rank. If false, pads the boundary with the adjacent curvature.
See three_point_circle.
BlockTensorFactorization.Core.coarsen — Method
coarsen(Y::AbstractArray, scale::Integer; dims=1:ndims(Y))Coarsens or downsamples Y by scale. Only keeps every scale entries along the dimensions specified.
Example
Y = randn(12, 12, 12)
coarsen(Y, 2) == Y[begin:2:end, begin:2:end, begin:2:end]
coarsen(Y, 4; dims=(1, 3)) == Y[begin:4:end, :, begin:4:end]
coarsen(Y, 3; dims=2) == Y[:, begin:3:end, :]BlockTensorFactorization.Core.contractions — Method
contractions(D::AbstractDecomposition)A tuple of functions defining a recipe for reconstructing a full array from the factors of the decomposition.
Example
(op1, op2) = contractions(D)
(A, B, C) = factors(D)
array(D) == op2(op1(A, B), C)BlockTensorFactorization.Core.core — Method
core(T::AbstractTucker)The core of a Tucker-like decomposition. Same number of dimensions as the full array.
BlockTensorFactorization.Core.cpproduct — Method
cpproduct((A, B, C, ...))
cpproduct(A, B, C, ...)Multiplies the inputs by treating them as matrices in a CP decomposition.
Example
cpproduct(A, B, C) == @einsum T[i, j, k] := A[i, r] * B[j, r] * C[k, r]
BlockTensorFactorization.Core.cubic_spline_coefficients — Method
cubic_spline_coefficients(y::AbstractVector{<:Real}; h=1)Calculates the list of coefficients a, b, c, d for an interpolating spline of y[i]=y(x[i]).
The spline is defined as $f(x) = g_i(x)$ on $x[i] \leq x \leq x[i+1]$ where
$g_i(x) = a[i](x-x[i])^3 + b[i](x-x[i])^2 + c[i](x-x[i]) + d[i]$
Uses the following boundary conditions
- $g_1(x[1]-h) = 1$ (i.e. the $y$-intercept is $(0,1)$ for uniform spaced
x=1:I) - $g_I(x[I]+h) = y[I]$ (i.e. repeated right end-point)
- $g_I''(x[I]+h) = 0$ (i.e. flat/no-curvature one spacing after end-point)
BlockTensorFactorization.Core.curvature — Method
curvature(y::AbstractVector{<:Real}; method=:finite_differences)Approximates the signed curvature of a function given evenly spaced samples.
Possible methods
:finite_differences: Approximates first and second derivative with 3rd order finite differences. Seed_dxandd2_dx2.:splines: Curvature of a third order spline. Seed_dx_and_d2_dx2_spline.:circles: Inverse radius of a circle through rolling three points. Seecircle_curvature.:breakpoints: WARNING does not compute a value that approximates the curvature of a continuous function. Computes the inverse least-squares error off.(eachindex(y); z)andyfor allz in eachindex(y)wheref(x; z) = a + b(min(x, z) - z) + c(max(x, z) - z). Useful ifylooks like two lines. Seebreakpoint_curvature.
BlockTensorFactorization.Core.d2_dx2 — Method
d2_dx2(y::AbstractVector{<:Real})Approximate second derivative with finite elements.
$\frac{d^2}{dx^2}y[i] \approx \frac{1}{\Delta x^2}(y[i-1] - 2y[i] + y[i+1])$
Assumes y[i] = y(x[i]) are samples with unit spaced inputs Δx = x[i+1] - x[i] = 1.
BlockTensorFactorization.Core.d_dx — Method
d_dx(y::AbstractVector{<:Real})Approximate first derivative with finite elements.
$\frac{d}{dx}y[i] \approx \frac{1}{2\Delta x}(y[i+1] - y[i-1])$
Assumes y[i] = y(x[i]) are samples with unit spaced inputs Δx = x[i+1] - x[i] = 1.
BlockTensorFactorization.Core.d_dx_and_d2_dx2_spline — Method
d_dx_and_d2_dx2_spline(y::AbstractVector{<:Real}; h=1)Extracts the first and second derivatives of the splines from y at the knots
BlockTensorFactorization.Core.default_kwargs — Method
default_kwargs(Y; kwargs...)Handles all keywords and options, and sets defaults if not provided.
Keywords & Defaults
Initialization
decomposition:nothing. Can provide a custom initialized AbstractDecomposition. Note this exact decomposition is mutated.model:Tucker1, but overridden by the type of AbstractDecomposition if givendecompositionrank:nothing, but overridden by the rank of AbstractDecomposition if givendecomposition. Automatically callsrank_detect_factorizeif bothrank&decompositionare not provided.init:abs_randnfor nonnegative inputsY,randnotherwiseconstrain_init:true. Ensures the initialization satisfies all givenconstraints. Defaults tofalseif givendecompositionfreeze: the default frozen factors of themodelcontinuous_dims:missing. Dimensions ofYthat come from discretizations of continuous data. If provided,multiscale_factorizeis called and can speed up factorization. Ifcontinuous_dims==nothing, factorization will only happen at one scale. In the future, ifcontinuous_dims==missing,factorizemay guess if there are continuous dimensions.
Updates
objective:L2(). Objective to minimizenorm:l2norm. Norm to use for statistics, can be unrelated to the objectiverandom_order:false. Perform the updates in a random order each iteration, Overrides totruewhenrecursive_random_order=truegroup_updates_by_factor:false. Groups updates on the same factor together. Overrides totruewhenrandom_order=true. Useful when randomizing order of updates but you want to keep matching momentum-gradientstep-constraint togetherrecursive_random_order:false. Performs inner blocked updates (grouped updates) in a random order (recursively) each iteration. Note the outer most list of updates can be performed in order ifrandom_order=falsedo_subblock_updates:false. Performs gradient descent on subblocks within a factor separately. May result in smaller Lipschitz constants and hence larger step sizes being used.
Momentum
momentum:trueδ:0.9999. Amount of momentum, between [0,1)previous_iterates:1. Number of pervious iterates to save and use between iterations
Constraints
constraints:nothing. Can be a list of ConstraintUpdate, or just onefinal_constraints:nothing. Constraints to apply after the final iteration. Will applyconstraintsifconstrain_outputistrueand none are givenconstrain_output:false. Apply thefinal_constraints, will override totrueiffinal_constraintsare given
Stats
stats:[Iteration, ObjectiveValue, GradientNorm]or in the case of nonnegativeY,GradientNNConein place ofGradientNormconverged:GradientNormor in the case of nonnegativeY,GradientNNCone. What stat(s) to use for convergence. Will converge is any one of the provided stats is below their respective tolerancetolerance:1. A list the same length asconvergedmaxiter:1000. Additional stopping criterion if the number of iterations exceeds this number
BlockTensorFactorization.Core.eachfactorindex — Method
eachfactorindex(D::AbstractDecomposition)An iterable to index the factors of D; not necessarily 1:ndims(D). Does not include non-data factors like the core of a CPDecomposition.
For example, eachfactorindex(D::Tucker) == 0:ndims(D) since core(D) is the zeroth factor. eachfactorindex(D::CPDecomposition) == 1:ndims(D). core(D) exists, but it is frozen as the identity tensor. And eachfactorindex(D::Tucker1) == 0:1 representing the core and matrix factor of D.
BlockTensorFactorization.Core.eachfibre — Method
eachfibre(A::AbstractArray; n::Integer, kwargs...)Creates views of A that are that n-fibres of A.
Shorthand for eachslice(A; dims=(1,...,n-1,n+1,...,ndims(A))).
See eachslice.
BlockTensorFactorization.Core.eachrank1term — Method
eachrank1term(T::AbstractTucker)Creates a generator for each rank 1 term of a Tucker decomposition.
BlockTensorFactorization.Core.eachrank1term — Method
eachrank1term(T::CPDecomposition)The (CP) rank-1 tensors Tr[i1, ..., iN] = A1[i1, r] * … * AN[iN, r] for each r = 1, …, rankof(T).
BlockTensorFactorization.Core.eachrank1term — Method
eachrank1term(T::Tucker1)The (Tucker-1) rank-1 tensors Tr[i1, ..., iN] = A[i1, r] * B[r, i2, ..., iN] for each r = 1, …, rankof(T).
BlockTensorFactorization.Core.expand_decomposition_constraints — Method
expand_decomposition_constraints(Y, kwargs)Use the same initialization as factorize to get the expanded set of constraints.
BlockTensorFactorization.Core.factorize — Method
factorize(Y; rank=nothing, model=Tucker1, kwargs...)Factorizes Y according to the decomposition model.
See default_kwargs for the default keywords.
BlockTensorFactorization.Core.factors — Method
factors(D::AbstractDecomposition)A tuple of arrays representing the decomposition of D.
Use factor to get just the nth factor.
BlockTensorFactorization.Core.false_tuple — Method
false_tuple(n::Integer)Makes a Tuple of length n filled with false.
BlockTensorFactorization.Core.finalconstrain! — Method
finalconstrain!(decomposition; constraints, final_constraints, kwargs...)Applies final_constraints (or if its nothing, applies constraints) to the decomposition.
Any RescaleUpdate are applied (the factor is scaled), but the rescaling of other factors is skipped.
BlockTensorFactorization.Core.frozen — Method
frozen(D::AbstractDecomposition)A tuple of Bools the same length as factors(D) showing which factors are "frozen" in the sense that a block decent algorithm should skip these factors when decomposing a tensor.
See isfrozen.
BlockTensorFactorization.Core.geomean — Method
geomean(v)
geomean(v...)Geometric mean of a collection: prod(v)^(1/length(v)).
If prod(v) is detected to be 0 or Inf, the safer (but slower) implementation exp(mean(log.(v))) is used.
BlockTensorFactorization.Core.getnotindex — Function
getnotindex(A, i::Int; view=false)
getnotindex(A, I; view=false)Like getindex but returns the compliment to the index or indices requested.
BlockTensorFactorization.Core.group_by_factor — Method
group_by_factor(blockedupdate::BlockedUpdate)Groups updates according to the factor they operate on.
If blockedupdate contains other BlockedUpdates, the inner updates are grouped when they all operate on the same factor.
Updates which do not have an assigned factor are grouped together.
The order which these groups appear in the output follows the same order as the first appearence of each unique factor that is operated on.
BlockTensorFactorization.Core.identity_tensor — Method
identity_tensor(I, ndims)
identity_tensor(T, I, ndims)Creates a SuperDiagonal array of ones with size I × ... × I of order ndims.
Can provide a type T for the identity tensor.
BlockTensorFactorization.Core.identityslice — Method
identityslice(x::AbstractArray{T, N})Useful for returning an iterable with a single iterate x
BlockTensorFactorization.Core.initialize — Method
initialize(Y, kwargs)Main initialization function for factorize.
BlockTensorFactorization.Core.initialize_continuous_dims — Method
initialize_continuous_dims(Y; kwargs...)Lists dimensions of Y that represent a discretization of a continuous function.
Defaults to all of them: continuous_dims = 1:ndims(Y).
BlockTensorFactorization.Core.initialize_decomposition — Method
initialize_decomposition(Y; decomposition, model, rank, kwargs...)The decomposition model Y will be factored into
BlockTensorFactorization.Core.initialize_parameters — Method
initialize_parameters(decomposition, Y, previous; momentum::Bool, random_order, recursive_random_order, kwargs...)update parameters needed for the update
BlockTensorFactorization.Core.initialize_previous — Method
initialize_previous(decomposition, Y; previous_iterates::Integer, kwargs...)Keep track of one or more previous iterates
BlockTensorFactorization.Core.initialize_scales — Method
initialize_scales(Y, kwargs)Initializes the plan for factorizing at progressively finer scales.
The list of scales should be ordered from largest (coarse) to smallest (fine) and end with 1.
BlockTensorFactorization.Core.initialize_stats — Method
initialize_stats(decomposition, Y, previous, parameters; stats, kwargs...)The stats that will be saved every iteration
BlockTensorFactorization.Core.interlace — Method
interlace(u, v)Takes two iterables, u and v, and alternates elements from u and v into a vector. If u and v are not the same length, extra elements are put on the end of the vector.
BlockTensorFactorization.Core.interpolate — Method
interpolate(Y, scale; dims=1:ndims(Y), degree=0, kwargs...)Interpolates Y to a larger array with repeated values.
Keywords
scale. How much to scale up the size of Y. A dimension with size k will be scaled to scale*k - (scale - 1) = scale*(k-1) + 1
dims:1:ndims(Y). Which dimensions to interpolate.
degree:0. What degree of interpolation to use. 0 is constant interpolation, 1 is linear.
Like the opposite of coarsen.
Example
julia> Y = collect(reshape(1:6, 2, 3))
2×3 Matrix{Int64}:
1 3 5
2 4 6
julia> interpolate(Y, 2)
3×5 Matrix{Int64}:
1 1 3 3 5
1 1 3 3 5
2 2 4 4 6
julia> interpolate(Y, 3; dims=2)
2×7 Matrix{Int64}:
1 1 1 3 3 3 5
2 2 2 4 4 4 6
julia> interpolate(Y, 1) == Y
trueBlockTensorFactorization.Core.isfrozen — Method
isfrozen(D::AbstractDecomposition, n::Integer)True if the nth factor of D is frozen. See frozen.
BlockTensorFactorization.Core.isnonnegative — Method
isnonnegative(X::AbstractArray{<:Real})
isnonnegative(x::Real)Checks if all entries of X are bigger or equal to zero. Will be a standard function in Base but using this for now: https://github.com/JuliaLang/julia/pull/53677
BlockTensorFactorization.Core.isnonnegative_sumtoone — Method
isnonnegative_sumtoone(x)Short for all(isnonnegative, x) && sum(x) ≈ 1.
BlockTensorFactorization.Core.khatrirao — Method
khatrirao(A::AbstractMatrix, B::AbstractMatrix)
A ⊙ BKhatri-Rao product of two matrices. A ⊙ B can be typed with \odot.
BlockTensorFactorization.Core.l1normalize! — Function
l1normalize! <: ProjectedNormalizationAlias for
ProjectedNormalization(l1norm, l1project!; whats_normalized=identityslice).
BlockTensorFactorization.Core.l1normalize_12slices! — Function
l1normalize_12slices! <: ProjectedNormalizationAlias for
ProjectedNormalization(l1norm, l1project!; whats_normalized=each12slice).
BlockTensorFactorization.Core.l1normalize_1slices! — Function
l1normalize_1slices! <: ProjectedNormalizationAlias for
ProjectedNormalization(l1norm, l1project!; whats_normalized=each1slice).
BlockTensorFactorization.Core.l1normalize_cols! — Function
l1normalize_cols! <: ProjectedNormalizationAlias for
ProjectedNormalization(l1norm, l1project!; whats_normalized=eachcol).
BlockTensorFactorization.Core.l1normalize_rows! — Function
l1normalize_rows! <: ProjectedNormalizationAlias for
ProjectedNormalization(l1norm, l1project!; whats_normalized=eachrow).
BlockTensorFactorization.Core.l1scale! — Function
l1scale! <: ScaledNormalizationAlias for
ScaledNormalization(l1norm; whats_normalized=identityslice).
See ScaledNormalization.
BlockTensorFactorization.Core.l1scale_12slices! — Function
l1scale_12slices! <: ScaledNormalizationAlias for
ScaledNormalization(l1norm; whats_normalized=each12slice).
See ScaledNormalization.
BlockTensorFactorization.Core.l1scale_1slices! — Function
l1scale_1slices! <: ScaledNormalizationAlias for
ScaledNormalization(l1norm; whats_normalized=each1slice).
See ScaledNormalization.
BlockTensorFactorization.Core.l1scale_average12slices! — Function
l1scale_average12slices! <: ScaledNormalizationAlias for
ScaledNormalization(l1norm; whats_normalized=each1slice, scale=size2).
See ScaledNormalization.
BlockTensorFactorization.Core.l1scale_cols! — Function
l1scale_cols! <: ScaledNormalizationAlias for
ScaledNormalization(l1norm; whats_normalized=eachcol).
See ScaledNormalization.
BlockTensorFactorization.Core.l1scale_rows! — Function
l1scale_rows! <: ScaledNormalizationAlias for
ScaledNormalization(l1norm; whats_normalized=eachrow).
See ScaledNormalization.
BlockTensorFactorization.Core.l2normalize! — Function
l2normalize! <: ProjectedNormalizationAlias for
ProjectedNormalization(l2norm, l2project!; whats_normalized=identityslice).
BlockTensorFactorization.Core.l2normalize_12slices! — Function
l2normalize_12slices! <: ProjectedNormalizationAlias for
ProjectedNormalization(l2norm, l2project!; whats_normalized=each12slice).
BlockTensorFactorization.Core.l2normalize_1slices! — Function
l2normalize_1slices! <: ProjectedNormalizationAlias for
ProjectedNormalization(l2norm, l2project!; whats_normalized=each1slice).
BlockTensorFactorization.Core.l2normalize_cols! — Function
l2normalize_cols! <: ProjectedNormalizationAlias for
ProjectedNormalization(l2norm, l2project!; whats_normalized=eachcol).
BlockTensorFactorization.Core.l2normalize_rows! — Function
l2normalize_rows! <: ProjectedNormalizationAlias for
ProjectedNormalization(l2norm, l2project!; whats_normalized=eachrow).
BlockTensorFactorization.Core.l2scale! — Function
l2scale! <: ScaledNormalizationAlias for
ScaledNormalization(l2norm; whats_normalized=identityslice).
See ScaledNormalization.
BlockTensorFactorization.Core.l2scale_12slices! — Function
l2scale_12slices! <: ScaledNormalizationAlias for
ScaledNormalization(l2norm; whats_normalized=each12slice).
See ScaledNormalization.
BlockTensorFactorization.Core.l2scale_1slices! — Function
l2scale_1slices! <: ScaledNormalizationAlias for
ScaledNormalization(l2norm; whats_normalized=each1slice).
See ScaledNormalization.
BlockTensorFactorization.Core.l2scale_average12slices! — Function
l2scale_average12slices! <: ScaledNormalizationAlias for
ScaledNormalization(l2norm; whats_normalized=each1slice, scale=size2).
See ScaledNormalization.
BlockTensorFactorization.Core.l2scale_cols! — Function
l2scale_cols! <: ScaledNormalizationAlias for
ScaledNormalization(l2norm; whats_normalized=eachcol).
See ScaledNormalization.
BlockTensorFactorization.Core.l2scale_rows! — Function
l2scale_rows! <: ScaledNormalizationAlias for
ScaledNormalization(l2norm; whats_normalized=eachrow).
See ScaledNormalization.
BlockTensorFactorization.Core.linftynorm — Method
linftynorm(x::AbstractArray)Calculates ‖x‖_∞.
BlockTensorFactorization.Core.linftynormalize! — Function
linftynormalize! <: ProjectedNormalizationAlias for
ProjectedNormalization(linftynorm, linftyproject!; whats_normalized=identityslice).
BlockTensorFactorization.Core.linftynormalize_12slices! — Function
linftynormalize_12slices! <: ProjectedNormalizationAlias for
ProjectedNormalization(linftynorm, linftyproject!; whats_normalized=each12slice).
BlockTensorFactorization.Core.linftynormalize_1slices! — Function
linftynormalize_1slices! <: ProjectedNormalizationAlias for
ProjectedNormalization(linftynorm, linftyproject!; whats_normalized=each1slice).
BlockTensorFactorization.Core.linftynormalize_cols! — Function
linftynormalize_cols! <: ProjectedNormalizationAlias for
ProjectedNormalization(linftynorm, linftyproject!; whats_normalized=eachcol).
BlockTensorFactorization.Core.linftynormalize_rows! — Function
linftynormalize_rows! <: ProjectedNormalizationAlias for
ProjectedNormalization(linftynorm, linftyproject!; whats_normalized=eachrow).
BlockTensorFactorization.Core.linftyproject! — Method
linftyproject!(x::AbstractArray)Euclidean projection onto the unit L∞-ball.
BlockTensorFactorization.Core.linftyscale! — Function
linftyscale! <: ScaledNormalizationAlias for
ScaledNormalization(linftynorm; whats_normalized=identityslice).
See ScaledNormalization.
BlockTensorFactorization.Core.linftyscale_12slices! — Function
linftyscale_12slices! <: ScaledNormalizationAlias for
ScaledNormalization(linftynorm; whats_normalized=each12slice).
See ScaledNormalization.
BlockTensorFactorization.Core.linftyscale_1slices! — Function
linftyscale_1slices! <: ScaledNormalizationAlias for
ScaledNormalization(linftynorm; whats_normalized=each1slice).
See ScaledNormalization.
BlockTensorFactorization.Core.linftyscale_average12slices! — Function
linftyscale_average12slices! <: ScaledNormalizationAlias for
ScaledNormalization(linftynorm; whats_normalized=each1slice, scale=size2).
See ScaledNormalization.
BlockTensorFactorization.Core.linftyscale_cols! — Function
linftyscale_cols! <: ScaledNormalizationAlias for
ScaledNormalization(linftynorm; whats_normalized=eachcol).
See ScaledNormalization.
BlockTensorFactorization.Core.linftyscale_rows! — Function
linftyscale_rows! <: ScaledNormalizationAlias for
ScaledNormalization(linftynorm; whats_normalized=eachrow).
See ScaledNormalization.
BlockTensorFactorization.Core.make_spline — Method
make_spline(y::AbstractVector{<:Real}; h=1)Returns a function f(x) that is an interpolating/extrapolating spline for y, with uniform stepsize h between the x-values of the knots.
BlockTensorFactorization.Core.make_update! — Method
make_update!(decomposition, Y; momentum, constraints, constrain_init, group_updates_by_factor, do_subblock_updates, kwargs...)What one iteration of the algorithm looks like. One iteration is likely a full cycle through each block or factor of the model.
BlockTensorFactorization.Core.mat — Method
mat(A::AbstractArray, n::Integer)Matricize along the nth mode.
BlockTensorFactorization.Core.match_cols! — Method
match_cols!(X::AbstractMatrix, Y::AbstractMatrix; kwargs...)match_slices! along the second dimension.
BlockTensorFactorization.Core.match_factors! — Method
match_factors!(X::T, Y::T; dist=L2) where {T <: AbstractDecomposition}Reorders the rank-1 terms of X to best match the slices of Y.
This is currently implemented for Tucker1 and CPDecomposition.
See match_slices!.
BlockTensorFactorization.Core.match_rows! — Method
match_rows!(X::AbstractMatrix, Y::AbstractMatrix; kwargs...)match_slices! along the first dimension.
BlockTensorFactorization.Core.match_slices! — Method
match_slices!(X, Y; dims, dist=L2)Reorders the order-dims slices of X to best match the slices of Y.
BlockTensorFactorization.Core.matrix_factor — Method
matrix_factor(T::AbstractTucker, n::Integer)The nth matrix factor. See matrix_factors.
BlockTensorFactorization.Core.matrix_factors — Method
matrix_factors(T::AbstractTucker)Tuple of the non-core factors of T. See matrix_factor.
BlockTensorFactorization.Core.max_possible_rank — Method
max_possible_rank(Y, model)Returns the maximum rank possible Y could have under the model.
For matrices I × J this is 1:min(I, J). This is can be extended to tensors for different type of decompositions.
Tucker-1 rank is ≤ min(I, prod(J1,...,JN)) for tensors I × J1 × … × JN.
The CP-rank is ≤ minimum_{n} (prod(I1,...,IN) / In) for tensors I1 × … × IN in general. Although some shapes have have tighter upper bounds. For example, 2 × I × I tensors over ℝ have a maximum rank of floor(3I/2).
BlockTensorFactorization.Core.mtt — Method
mtt(A::AbstractMatrix, B::AbstractArray)Matrix Times Tensor. Entry-wise,
mtt(A, B)[i1, i2, …, iN] = ∑_r A[i1, r] * B[r, i2, …, iN].
BlockTensorFactorization.Core.multifoldl — Method
multifoldl(ops, args)Like foldl, but with a different folding operation between each argument.
Example
julia> multifoldl((+,*,-), (2,3,4,5))
15
julia> ((2 + 3) * 4) - 5
15BlockTensorFactorization.Core.multiscale_factorize — Method
multiscale_factorize(Y; continuous_dims=1:ndims(Y), rank=1, model=Tucker1, kwargs...)Like factorize but uses progressively finer sub-grids of Y to speed up convergence. This is only effective when the dimensions given by dims come from discretizations of continuous data.
For example, if Y has 3 dimensions where Y[i, j, k] are samples from a continuous 2D function fi(xj, y_k) on a grid, use
multiscale_factorize(Y; continuous_dims=(2,3))
since second and third dimensions are continuous.
BlockTensorFactorization.Core.nfactors — Method
nfactors(D::AbstractDecomposition)Returns the number of factors/blocks in a decomposition.
BlockTensorFactorization.Core.nmode_product — Method
nmode_product(A::AbstractArray, B::AbstractMatrix, n::Integer)Contracts the nth mode of A with the first mode of B. Equivalent to A ×ₙ B where
(A ×ₙ B)[i₁, …, i_N] = ∑ⱼ A[i₁, …, iₙ₋₁, j, iₙ₊₁, …, i_N] B[iₙ, j].
BlockTensorFactorization.Core.nmode_product — Method
nmode_product(A::AbstractArray, b::AbstractVector, n::Integer)Contracts the nth mode of A with b. Equivalent to A ×ₙ b where
(A ×ₙ b)[i₁, …, iₙ₋₁, iₙ₊₁, …, i_N] = ∑_iₙ A[i₁, …, i_N] b[iₙ].
BlockTensorFactorization.Core.nmp — Function
Shorthand for nmode_product.
BlockTensorFactorization.Core.nonnegative! — Function
Entrywise(ReLU, isnonnegative)
BlockTensorFactorization.Core.norm2 — Method
norm2(x)L2 norm squared, the sum of squares of the entries of x.
BlockTensorFactorization.Core.outer_product — Method
outer_product(vectors)
outer_product(vectors...)Outer product of a collection of vectors.
For example,
outer_product(u, v) == u * v'
and
outer_product(u, v, w)[i, j, k] == u[i] * v[j] * w[k].
Returned array will have same number dimensions as the length of the collection.
BlockTensorFactorization.Core.parse_constraints — Method
parse_constraints(constraints, decomposition; kwargs...)Parses the constraints to make sure we have a valid list of ConstraintUpdate.
If only one AbstractConstraint is given, assume we want this constraint to apply to every factor in the decomposition, and make a ConstraintUpdate for each factor.
If we are given a list of AbstractConstraint, assume we want them to apply to each factor of the decomposition in order.
BlockTensorFactorization.Core.postprocess! — Method
postprocess!(decomposition, Y, previous, parameters, stats_data, updateparameters!, getstats, kwargs)Any post algorithm processing that needs to be done in factorize.
BlockTensorFactorization.Core.proj_one_hot! — Method
proj_one_hot!(x)Mutating version of proj_one_hot.
BlockTensorFactorization.Core.proj_one_hot — Method
proj_one_hot(x)Projects an array x to the closest one hot array: an array with all 0's except for a single 1. Does not mutate; see proj_one_hot! for a mutating version.
This is not a unique projection if there are multiple largest entries. In this case, will pick one of the largest entries to be 1 and set the rest to zero.
BlockTensorFactorization.Core.projsplx! — Method
projsplx!(y; sum=one(eltype(y)))Projects (in Euclidean distance) the array y into the simplex.
See projsplx for a non-mutating version.
[1] Yunmei Chen and Xiaojing Ye, "Projection Onto A Simplex", 2011
BlockTensorFactorization.Core.projsplx — Method
projsplx(y; sum=one(eltype(y)))Non-mutating version of projsplx!.
BlockTensorFactorization.Core.rank_detect_factorize — Method
rank_detect_factorize(Y; kwargs...)Wraps factorize() with rank detection.
Selects the rank that maximizes the standard curvature of the Relative Error (as a function of rank).
Keywords
online_rank_estimation:false. Set totrueto stop testing larger ranks after the first peak in curvaturecurvature_method::splines. Can also pick:finite_differences(faster but less accurate) orcircles(fastest and smallest memory but more sensitive to results fromfactorize). Set to:breakpointsto pick the rankRthat minimizes least-squares error in the modelf(r) = a + b(min(r, R) - R) + c(max(r, R) - R)and the errors.model:Tucker1. Only rank detection withTucker1andCPDecompositionis currently implementedmax_rank:max_possible_rank(Y, model). Test ranks from1up tomax_rank. Defaults to largest possible rank under the modelrank:nothing. If a rank is passed, rank detection is ignored andfactorize(Y; kwargs...)is called
Any other keywords from factorize, full list given by default_kwargs.
BlockTensorFactorization.Core.rankof — Method
rankof(D::AbstractDecomposition)Internal dimension sizes for a decomposition. Returns the sizes of all factors if not defined for a concrete subtype of AbstractDecomposition.
Examples
CPDecomposition: size of second dimension for the factors Tucker: size of the core factor Tucker1: size of the first dimension of the core factor
BlockTensorFactorization.Core.rankof — Method
The single rank for a CP Decomposition
BlockTensorFactorization.Core.reshape_ndims — Method
reshape_ndims(x, n)Reshapes x to a higher order array with n dimensions.
When n > ndims(x), extra dimensions are prepended. Otherwise, trailing dimensions are collapsed.
Example
julia> x = [1, 2, 3]
3-element Vector{Int64}:
1
2
3
julia> reshape_ndims(x, 1)
3-element Vector{Int64}:
1
2
3
julia> reshape_ndims(x, 2)
1×3 Matrix{Int64}:
1 2 3
julia> reshape_ndims(x, 3)
1×1×3 Array{Int64, 3}:
[:, :, 1] =
1
[:, :, 2] =
2
[:, :, 3] =
3
julia> A = reshape(collect(1:12), 2, 2, 3)
2×2×3 Array{Int64, 3}:
[:, :, 1] =
1 3
2 4
[:, :, 2] =
5 7
6 8
[:, :, 3] =
9 11
10 12
julia> reshape_ndims(A, 2)
2×6 Matrix{Int64}:
1 3 5 7 9 11
2 4 6 8 10 12Credit: https://discourse.julialang.org/t/outer-product-broadcast/103731/7
BlockTensorFactorization.Core.scale_constraint — Method
scale_constraint(constraint::AbstractConstraint, scale, n_continuous_dims)Returns a scaled version of the constraint based off the number of relevant continuous dimensions the constraint acts on.
BlockTensorFactorization.Core.scale_constraints — Method
scale_constraints(Y, scale; kwargs...)Scales any constraints that need to be modified to use at a coarser scale.
BlockTensorFactorization.Core.scale_decomposition_constraint — Method
Idea is that external dimensions (I₁, I₂, ...) that are continuous dimensions need to be scaled, but internal dimensions (R₁, R₂, ...) or non-continuous dimensions don't.
BlockTensorFactorization.Core.signed_circle_curvature — Method
signed_circle_curvature((a,f),(b,g),(c,h))Signed inverse radius of the circle passing through the 3 points in the xy-plane.
See three_point_circle.
BlockTensorFactorization.Core.simplex! — Function
simplex! <: ProjectedNormalizationAlias for
ProjectedNormalization(isnonnegative_sumtoone, projsplx!; whats_normalized=identityslice).
BlockTensorFactorization.Core.simplex_12slices! — Function
simplex_12slices! <: ProjectedNormalizationAlias for
ProjectedNormalization(isnonnegative_sumtoone, projsplx!; whats_normalized=each12slice).
BlockTensorFactorization.Core.simplex_1slices! — Function
simplex_1slices! <: ProjectedNormalizationAlias for
ProjectedNormalization(isnonnegative_sumtoone, projsplx!; whats_normalized=each1slice).
BlockTensorFactorization.Core.simplex_cols! — Function
simplex_cols! <: ProjectedNormalizationAlias for
ProjectedNormalization(isnonnegative_sumtoone, projsplx!; whats_normalized=eachcol).
BlockTensorFactorization.Core.simplex_rows! — Function
simplex_rows! <: ProjectedNormalizationAlias for
ProjectedNormalization(isnonnegative_sumtoone, projsplx!; whats_normalized=eachrow).
BlockTensorFactorization.Core.slicewise_dot — Method
slicewise_dot(A::AbstractArray, B::AbstractArray; dims=1, dimsA=dims, dimsB=dims)Contracts all but the dimensions dimsA and dimsB of A and B. Entry-wise
(slicewise_dot(A,B; dimsA, dimsB))[i_dimsA, i_dimsB] = A[…, i_dimsA, ⋯] ⋅ B[…, i_dimsB, ⋯].
When dims==n, equivalent to A ⋅ₙ B. If A and B are both matrices, slicewise_dot(A, B) == A'B.
BlockTensorFactorization.Core.smart_insert! — Method
smart_insert!(U::BlockedUpdate, V::AbstractUpdate)Tries to insert V into U after the last matching update in U. A "matching update" means it updates the same factor/block n. See smart_interlace!
BlockTensorFactorization.Core.smart_interlace! — Method
smart_interlace!(U::BlockedUpdate, V)smart_insert!s each update in V, into U. See smart_insert!
BlockTensorFactorization.Core.spline_mat — Method
spline_mat(n)Creates the Tridiagonal matrix to solve for coefficients b. See cubic_spline_coefficients.
BlockTensorFactorization.Core.standard_curvature — Method
standard_curvature(y::AbstractVector{<:Real}; method=:finite_differences)Approximates the signed curvature of a function, scaled to the unit box $[0,1]^2$.
Assumes the function is 1 at 0 and (after x dimension is scaled) 0 at 1.
See curvature.
Possible methods
:finite_differences: Approximates first and second derivative with 3rd order finite differences. Seed_dxandd2_dx2.:splines: Curvature of a third order spline. Seed_dx_and_d2_dx2_spline.:circles: Inverse radius of a circle through rolling three points. Seecircle_curvature.:breakpoints: WARNING does not compute a value that approximates the curvature of a continuous function. Computes the inverse least-squares error off.(eachindex(y); z)andyfor allz in eachindex(y)wheref(x; z) = a + b(min(x, z) - z) + c(max(x, z) - z). Useful ifylooks like two lines. Seebreakpoint_curvature.
BlockTensorFactorization.Core.swapdims — Function
swapdims(A::AbstractArray, a::Integer, b::Integer=1)Swap dimensions a and b.
BlockTensorFactorization.Core.three_point_circle — Method
three_point_circle((a,f),(b,g),(c,h))Calculates radius r and center point (p, q) of the circle passing through the three points in the xy-plane.
Example
r, (p, q) = three_point_circle((1,2), (2,1), (5,2))
(r, (p, q)) == (√5, (3, 3))BlockTensorFactorization.Core.tucker_contractions — Method
tucker_contractions(N)Contractions used in a full Tucker decomposition of order N. This is a tuple of the n-mode products from 1 to N in order.
BlockTensorFactorization.Core.tuckerproduct — Method
tuckerproduct(G, (A, B, ...))
tuckerproduct(G, A, B, ...)Multiplies the inputs by treating the first argument as the core and the rest of the arguments as matrices in a Tucker decomposition.
Example
tuckerproduct(G, (A, B, C)) == G ×₁ A ×₂ B ×₃ C
tuckerproduct(G, (A, B, C); exclude=2) == G ×₁ A ×₃ C
tuckerproduct(G, (A, B, C); exclude=2, excludes_missing=false) == G ×₁ A ×₃ C
tuckerproduct(G, (A, C); exclude=2, excludes_missing=true) == G ×₁ A ×₃ C