CX

class spalor.models.CX(n_components=10, method='approximate')[source]
Dimensionality reduction based on a low-rank matrix faactorization:

A=C*X

where C consists of columns sampled from A, and X=(C’*C)^-1 *C’ *A.

Typically, the columns sampled to get C are selected at random with probabilites proportional to the leverage scores.

n_componentsint, default=10

Number of columns to sample.

method{‘exact’, ‘approximate’, ‘random’}, default=’exact’
method to select rows.
  • “exact”: randomly select by leverage scores

  • “approximate” : randomly select columns by approximated leverage scores

  • “random” : randomly select columns

d1int

number or rows in the original matrix

d2int

number of columns in the original matrix

colslist

list containing indices of columns sampled

Cndarray, shape = (d1,n_components)

Columns sampled

Xndarray, shape = (n_components, d2)

Score matrix, often used for classification. Coordinates in the lower dimensional column space

``` A=np.array([[1, 1, 2, 2],

[2, 1, 3, 5], [1, 2, 3, 1], [3, 1, 4, 8]], dtype=float)

cx=CX(n_components=2) X=cx.fit_transform(A) print(“C:

“, cx.C)

print(“X:

“, cx.X)

print(“columns used:

“, cx.cols)

```

fit(A, cols=None, svdA=None)[source]

Fit CX model

A: numpy array with shape (n,d)

Matrix to fit model to

cols(optional) list or 1d numpy array

list of columns to use. If specified, method and n_components are ignored

svdA(optional) length 3 tuple

the output of np.linalg.svd or scipy.sparse.linalg.svds. If you already have the svd of A, specifying it saves on computation.

updated model

fit_transform(A, cols=None, svdA=None)[source]

Fit and return columns

inverse_transform(C)[source]

Infer entire matrix from subset of columns

C: numpy array with shape(n, n_components)

ndarray with shape (n,d)

transform(A)[source]

Extract columns of A

A: numpy array with shape (n,d)

Columns of A corresponding to the ones use in the CX model