biScale {softImpute} | R Documentation |
Standardize a matrix to have optionally row means zero and variances one, and/or column means zero and variances one.
Description
A function for standardizing a matrix in a symmetric fashion. Generalizes
the scale
function in R. Works with matrices with NAs, matrices of
class "Incomplete", and matrix in "sparseMatrix" format.
Usage
biScale(
x,
maxit = 20,
thresh = 1e-09,
row.center = TRUE,
row.scale = TRUE,
col.center = TRUE,
col.scale = TRUE,
trace = FALSE
)
Arguments
x |
matrix, possibly with NAs, also of class "Incomplete" or "sparseMatrix" format. |
maxit |
When both row and column centering/scaling is requested, iteration is may be necessary |
thresh |
Convergence threshold |
row.center |
if |
row.scale |
if |
col.center |
Similar to |
col.scale |
Similar to |
trace |
with |
Details
This function computes a transformation
\frac{X_{ij}-\alpha_i-\beta_j}{\gamma_i\tau_j}
to transform the
matrix X
. It uses an iterative algorithm based on
"method-of-moments". At each step, all but one of the parameter vectors is
fixed, and the remaining vector is computed to solve the required
condition. Although in genereal this is not guaranteed to converge, it
mostly does, and quite rapidly. When there are convergence problems, remove
some of the required constraints. When any of the row/column centers or
scales are provided, they are used rather than estimated in the above
model.
Value
A matrix like x
is returned, with attributes:
biScale:row |
a list with elements |
biScale:column |
Same details as |
For matrices with
missing values, the constraints apply to the non-missing entries. If
x
is of class "sparseMatrix"
, then the sparsity is
maintained, and an object of class "SparseplusLowRank"
is returned,
such that the low-rank part does the centering.
Note
This function will be described in detail in a forthcoming paper
Author(s)
Trevor Hastie, with help from Andreas Buja and Steven Boyd
,
Maintainer: Trevor Hastie hastie@stanford.edu
References
Trevor Hastie, Rahul Mazumder, Jason Lee, Reza Zadeh (2015)
Matrix Completion and Low-rank SVD via Fast Alternating Least Squares,
https://arxiv.org/abs/1410.2596
Journal of Machine Learning Research, 16, 3367-3402
See Also
softImpute
,Incomplete
,lambda0
,impute
,complete
,
and class "SparseplusLowRank"
Examples
set.seed(101)
n=200
p=100
J=50
np=n*p
missfrac=0.3
x=matrix(rnorm(n*J),n,J)%*%matrix(rnorm(J*p),J,p)+matrix(rnorm(np),n,p)/5
xc=biScale(x)
ix=seq(np)
imiss=sample(ix,np*missfrac,replace=FALSE)
xna=x
xna[imiss]=NA
xnab=biScale(xna,row.scale=FALSE,trace=TRUE)
xnaC=as(xna,"Incomplete")
xnaCb=biScale(xnaC)
nnz=trunc(np*.3)
inz=sample(seq(np),nnz,replace=FALSE)
i=row(x)[inz]
j=col(x)[inz]
x=rnorm(nnz)
xS=sparseMatrix(x=x,i=i,j=j)
xSb=biScale(xS)
class(xSb)