This function generate the pairwise difference matrix(D matrix in the paper). By default it returns a sparse matrix(matrix.csr) from the package SparseM.
RSAVS_Generate_D_Matrix(n, dense = FALSE, w_vec = 1)
number of observations.
logical, whether the return type should be in dense matrix or not
a scalar value of a length \(n * (n - 1) / 2\) vector representing
the weights for left part in each pair(e.g. \(\mu_i\) in \(\mu_i - \mu_j\)).
If w_vec
is a scalar, it will be recycled for every pair.
Defaults to 1.
a difference matrix with size \((n * (n - 1) / 2) \times n\)
In Original RSAVS via ADMM algorithm. This functions generates the pairwise
difference matrix with w_vec = 1
.
In RSI, the original objective function is converted to a sparse median regression
via LLA. The pairwise difference matrix is coupled with weights extracted from
the penalty functions. This is supplied into this function through w_vec
.
RSAVS:::RSAVS_Generate_D_Matrix(5)
#> An object of class "matrix.csr"
#> Slot "ra":
#> [1] 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1
#>
#> Slot "ja":
#> [1] 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5 4 5
#>
#> Slot "ia":
#> [1] 1 3 5 7 9 11 13 15 17 19 21
#>
#> Slot "dimension":
#> [1] 10 5
#>
RSAVS:::RSAVS_Generate_D_Matrix(4, dense = TRUE)
#> [,1] [,2] [,3] [,4]
#> [1,] 1 -1 0 0
#> [2,] 1 0 -1 0
#> [3,] 1 0 0 -1
#> [4,] 0 1 -1 0
#> [5,] 0 1 0 -1
#> [6,] 0 0 1 -1
RSAVS:::RSAVS_Generate_D_Matrix(3, w_vec = 2)
#> An object of class "matrix.csr"
#> Slot "ra":
#> [1] 2 -2 2 -2 2 -2
#>
#> Slot "ja":
#> [1] 1 2 1 3 2 3
#>
#> Slot "ia":
#> [1] 1 3 5 7
#>
#> Slot "dimension":
#> [1] 3 3
#>
RSAVS:::RSAVS_Generate_D_Matrix(4, dense = TRUE, w_vec = c(1, -2, 3, -4, 5, -6))
#> [,1] [,2] [,3] [,4]
#> [1,] 1 -1 0 0
#> [2,] -2 0 2 0
#> [3,] 3 0 0 -3
#> [4,] 0 -4 4 0
#> [5,] 0 5 0 -5
#> [6,] 0 0 -6 6