mat.mask | R Documentation |
Transforms a matrix called org
, represented by \mathbf{Z} = (z_{ij})_{p \times q}
, using a matrix called mask
, represented by \mathbf{M} = (m_{ij})_{p \times q}
.
Both matrices, org
and mask
have the same dimensionality, i.e. p \times q
.
However both matrices belong to different vector spaces,
Since org
is real or complex, but mask
is boolean, i.e. \mathbf{Z} \in \mathbb{C}^{p \times q}\, \wedge \, \mathbf{M} \in \mathbb{B}^{p \times q}
mat.mask(org, mask, drop.dat=F)
mat.mask(org, mask)
mat.mask(org, mask, drop.dat=T)
org |
The original data matrix |
mask |
The masking matrix |
drop.dat |
Boolean bit defaulting to |
drop.dat == F
preserves the size of the org
and mask
data and transfers it to the output.
The unmasked parts, where m_{ij} == \code{F}
are at least etched down to 0
.
Hence a presumptive bias might be needed in the org
matrix to separate actual 0
s and etched 0
s.
When drop.dat == T
, after the etching process, the matrix might be reduced in size.
The algo chooses the largest bounding rectangle of choice which contains the masked results.
The rest of the complementary data outside the rectangle contains only etched 0
s and are removed from the result.
Hence drop.dat == T
might fail to transfer the size of org
or mask
to the result.
Please see figure below.
The returned value is a matrix which is exactly the type(numeric, complex, boolean) that org
was.
The size of the matrix is p \times q
(same as mask
and org
) when drop.dat == F
.
The size of the matrix might be different when drop.dat == T
.
Chitran Ghosal
####create a 3 gaussian function
gauss3 <- function(X, Y){
set.seed(2)
mu <- runif(n = 6, min = 2, max = 7)
sd <- runif(n = 6, min = 1, max = 3)
gauss1 <- gauss(X, mu=mu[1], sig = sd[1], probability = T)*gauss(Y, mu=mu[2], sig = sd[2], probability = T)
gauss2 <- gauss(X, mu=mu[3], sig = sd[3], probability = T)*gauss(Y, mu=mu[4], sig = sd[4], probability = T)
gauss3 <- gauss(X, mu=mu[5], sig = sd[5], probability = T)*gauss(Y, mu=mu[6], sig = sd[6], probability = T)
return(gauss1 + gauss2 + gauss3)
}
####define the X and Y values
X <- seq(0, 10, by=0.05)
Y <- seq(0, 10, by=0.05)
Z <- 0.9*function_2D(X, Y, func = gauss3)
####plot the matrix
image(Z, asp=1.0, main = 'org', col = terrain.colors(1000))
####create the masks
mask1 <- Z > 0.5*max(Z)
mask2 <- Z > 0.75*max(Z)
image(mask1, asp = 1.0, main = 'mask1',col = terrain.colors(1000) )
image(mask2, asp = 1.0, main = 'mask2', col = terrain.colors(1000))
##The mask after dropping points
Z1 <- mat.mask(org = Z, mask = mask1, drop.dat = T)
Z2 <- mat.mask(org = Z, mask = mask2, drop.dat = T)
image(Z1, asp=1.0, main = 'after masking by mask1: points dropped', col = terrain.colors(1000))
image(Z2, asp=1.0, main = 'after masking by mask2: points dropped', col = terrain.colors(1000))
##The mask set without dropping points
Z1 <- mat.mask(org = Z, mask = mask1, drop.dat = F)
Z2 <- mat.mask(org = Z, mask = mask2, drop.dat = F)
image(log(Z1+1), asp=1.0, main = 'after masking by mask1: points NOT dropped', col = terrain.colors(1000))
image(log(Z2+1), asp=1.0, main = 'after masking by mask2: points NOT dropped', col = terrain.colors(1000))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.