generate_component_matrix generates the sparse random component matrix for performing sparse random projection. If density is the density of the sparse matrix and n_components is the size of the projected space, the elements of the random matrix are drawn from

generate_component_matrix(n_features, n_components, density)

Arguments

n_features

the dimensionality of the original space.

n_components

the dimensionality of the projected space.

density

the density of the sparse random matrix.

Value

A sparse random matrix of size (n_features, n_components).

Details

-sqrt(1 / (density * n_components)) with probability density / 2 0 with probability 1 - density sqrt(1 / (density * n_components)) with probability density / 2

Examples

M <- generate_component_matrix(500, 100, 0.3) M[1:10, 1:10]
#> 10 x 10 sparse Matrix of class "dgCMatrix" #> #> [1,] . -0.1825742 . . -0.1825742 . #> [2,] . . -0.1825742 -0.1825742 . . #> [3,] . . -0.1825742 0.1825742 . . #> [4,] . . . -0.1825742 . -0.1825742 #> [5,] . . . . -0.1825742 . #> [6,] . . . . . 0.1825742 #> [7,] . 0.1825742 0.1825742 -0.1825742 . . #> [8,] . . . 0.1825742 -0.1825742 . #> [9,] -0.1825742 -0.1825742 . . . -0.1825742 #> [10,] . . . -0.1825742 . . #> #> [1,] . . . 0.1825742 #> [2,] . . . 0.1825742 #> [3,] . . -0.1825742 . #> [4,] . 0.1825742 . 0.1825742 #> [5,] . . . -0.1825742 #> [6,] -0.1825742 . 0.1825742 . #> [7,] . . . . #> [8,] . . . . #> [9,] -0.1825742 . 0.1825742 . #> [10,] . . . -0.1825742