bd_wproduct

bd_wproduct

LINEAR_ALGEBRA

1 Description

Compute weighted operations using a diagonal weight from w: Inputs may be base numeric matrices .

2 Usage

bd_wproduct(X, w, op)

3 Arguments

Parameter Description
X Numeric matrix (n x p).
w Numeric weight vector (length or ), or a 1D matrix coerced to a vector.
op Character string (case-insensitive): one of , , , .

4 Value

Numeric matrix with dimensions depending on : for , for , and for /.

5 Details

w is interpreted as the diagonal of a weight matrix; its required length depends on the operation: rows for "xtwx" and "wx", columns for "xwxt" and "xw".

6 Examples

set.seed(1)
n <- 10; p <- 5
X <- matrix(rnorm(n * p), n, p)
u <- runif(n); w <- u * (1 - u)
bd_wproduct(X, w, "xtwx")  # p x p
bd_wproduct(X, w, "wx")    # n x p (row scaling)

v <- runif(p)
bd_wproduct(X, v, "xw")    # n x p (col scaling)
bd_wproduct(X, v, "xwxt")  # n x n