Name: Zhuoyan Xu

Email: zhuoyan.xu@wisc.edu

knitr::opts_chunk$set(
  cache = TRUE,
  collapse = TRUE,
  comment = "#>",
  dpi = 200,
  echo = TRUE,
  fig.align = "center",
  fig.height = 8,
  fig.width = 8,
  message = FALSE,
  out.width = 650,
  warning = FALSE
)
library(waveST)
library(fields)
library(tidyverse)
theme_set(theme_minimal())

Part 1: Basic Example of running

wave = waveST(data = raws[, 1:5])

decomp = decompose(wave, "raw", "SVD", K = 5)
plot(decomp, k = 1, wave = FALSE)


decomp = decompose(wave, "wave", "SVD", K = 5, tau = 40)
plot(decomp, k = 1, wave = TRUE)

Part 2: Simulation

Step 1: Data Generation

########## ==================  Data Generation
NUM_GENES = 300
K = 9

## == Step 1. generate coordinate matrix image with different patterns
# @N_dup, generate duplicates of each matrix pattern with a little permutation

CMls = generateCoorM(1)

We show all the generated pattern:

# show in scaled version
lay = layout(matrix(1:9, 3, 3, byrow = TRUE))
CMls %>%
  map(~ .x / sqrt(sum(.x^2))) %>%
  map(~ image.plot(.x, asp = 1))
layout(1)

We treat previous 9 patterns as factor genes, i.e. we have 8 factors matrix F = D^2xK (1024x8), where 1024 comes from (D^2) 32^2. We consider p = 500 genes in this simulation generate nxp(1024x500) data matrix by F%*%V, where V is \code{K}xp (8x500), compute the magnitude of each image matrix

scales = CMls %>%
  map_dbl(~ sqrt(sum(.x^2)))
## rescale each image matrix to norm 1 (eigen gene has norm 1)
FctGenes = CMls %>%
  map(~ .x / sqrt(sum(.x^2))) %>%
  map_dfc(~ as.vector(.)) %>%
  as.matrix()

LoadGenes = rep(1000, 9) %>%
  map_dfc(~ .x * rnorm(NUM_GENES)) %>%
  as.matrix(.) %>%
  t(.)

truth = FctGenes %*% LoadGenes

## we generate data by add random noise
raws = truth + matrix(rnorm(prod(dim(truth)), mean = 0, sd = 190), nrow = dim(truth)[1], ncol = dim(truth)[2])
wave = waveST(data = raws)

Step 2: Construct class and apply SVD with or without wavelet.

Without wavelet:

decomp = decompose(wave, "raw", "SVD", K = 5)
plot(decomp, k = 1, wave = FALSE)

With wavelet:

decomp = decompose(wave, "wave", "SVD", K = 5, tau = 40)
plot(decomp, k = 1, wave = TRUE)

Part 2: Real Data

Step 1: Data Generation by k over A filter.

res = kOverA_ST(k = 3, A = 7)
viz = res$viz
df = res$df

Step 2: Construct class and apply SVD with or without wavelet.

Without wavelet:

wave = waveST(data = df[, 1:5], spatial = viz)
decomp = decompose(wave, "raw", "SVD", K = 5)
plot(decomp, k = 1, wave = FALSE)

With wavelet:

decomp = decompose(wave, "wave", "SVD", K = 5, tau = 40)
plot(decomp, k = 1, wave = TRUE)


OliverXUZY/waveST documentation built on June 9, 2024, 6:18 a.m.