On Demand Matrices and Vectors

In the case that the matrix $V$ is too large to store in memory, when using a KernelDowndater such as GivensUpDowndater which only requires access to a select number of rows of $V$ at a time, we have implemented a matrix type OnDemandMatrix which stores only the required rows (or columns) at a time. The GivensUpDowndater or FullQRUpDowndater will automatically delete unneeded rows/columns throughout the pruning procedure.

CaratheodoryPruning.OnDemandMatrixType

OnDemandMatrix{T,TV<:AbstractVector{T}} <: AbstractMatrix{T}

Matrix subtype for which only a subset of the columns or rows (determined by if cols=true) need to be stored at a time in case storing the full matrix is too expensive.

To form an n×m "identity" OnDemandMatrix which is stored column-wise, call

M = OnDemandMatrix(n, m, j -> [1.0*(i==j) for i in 1:n]).

To store the matrix row-wise, call

M = OnDemandMatrix(n, m, i -> [1.0*(i==j) for j in 1:m], by=:rows).

Will only call the provided column or row function when trying to access in that column or row.

To "forget" or erase a given column or row, indexed by i, call

forget!(M, i).

Useful for use with caratheodory_pruning with the kernel option :GivensUpDown where only a subset of rows/columns are required at a time.

source

Forming an OnDemandMatrix requires passing the full-size of the matrix, the function that generates new rows or columns, and whether it is to be stored column-wise or row-wise. This type works nicely with transposition.

To manually erase or forget a given row/column, call the forget! method.

CaratheodoryPruning.forget!Function

forget!(M::OnDemandMatrix, i::Int)

Erases from memory the given column or row (determined by M.cols). If the given column or row is not stored, will do nothing.

source

forget!(M::OnDemandVector, i::Int)

Erases from memory the given element. If the given element is not stored, will do nothing.

source

Similarly, if the larger dimension of $V$ is so large that we wish to have complete memory independence from that dimension, we can store the weights in an OnDemandVector which only stores the required elements at a time. The method caratheodory_pruning will automatically delete unneeded elements throughout the pruning procedure.

CaratheodoryPruning.OnDemandVectorType

OnDemandVector{T} <: AbstractVector{T} where T

Vector subtype for which only a subset of the elements need to be stored at a time in case storing the full vector is too costly.

To form a length n OnDemandVector with value 1 at index 1 and zero otherwise, call

v = OnDemandVector(n, i -> 1.0 * (i == 1)).

To "forget" or erase a given element, indexed by i, call

forget!(v, i).

Useful for use with caratheodory_pruning with the kernel option :GivensUpDown where only a subset of elements are required at a time.

source

The method forget! works the same for the OnDemandVector.

Related to on demand matrices is a VandermondeVector which is a thin wrapper for a standard vector which stores one additional piece of information such as the point used to generate the corresponding slice of the Vandermonde matrix.

CaratheodoryPruning.VandermondeVectorType

VandermondeVector{T,TV<:AbstractVector{T},TP} <: AbstractVector{T}

v = VandermondeVector(vec, [pt=nothing])

Vector subtype useful for storing a slice (row or column) of a Vandermonde matrix along with the point used to form the slice. The slice is stored in vec and the point is stored in pt. Behaves like a normal vector with contents vec.

Given v = VandermondeVector(vec, pt), the point can be accessed with getpt(v) or v.pt.

source

See the Monte Carlo example for use of this.