# \donttest{
# Generate Poisson data
set.seed(2025)
# Generate 5 sources with different ranks
n1 <- 100; p1 <- 100
source_list <- list()
# Sources 1-2: rank 2 (same as target)
r_s <- 2
F_s <- matrix(runif(n1 * r_s, min = -2, max = 2), n1, r_s)
B_s <- matrix(runif(p1 * r_s, min = -2, max = 2), p1, r_s)
M_s <- F_s %*% t(B_s)
for (s in 1:2) {
X_s <- matrix(rpois(n1 * p1, exp(M_s)), n1, p1)
# Add 10% missing values
n_missing <- floor(n1 * p1 * 0.1)
missing_idx <- sample(n1 * p1, n_missing)
X_s[missing_idx] <- NA
source_list[[s]] <- X_s
}
# Sources 3-5: rank 3 (different from target)
for (s in 3:5) {
r_s_nega <- 3
F_s_nega <- matrix(runif(n1 * r_s_nega, min = -2, max = 2), n1, r_s_nega)
B_s_nega <- matrix(runif(p1 * r_s_nega, min = -2, max = 2), p1, r_s_nega)
M_s_nega <- F_s_nega %*% t(B_s_nega)
X_s_nega <- matrix(rpois(n1 * p1, exp(M_s_nega)), n1, p1)
n_missing <- floor(n1 * p1 * 0.1)
missing_idx <- sample(n1 * p1, n_missing)
X_s_nega[missing_idx] <- NA
source_list[[s]] <- X_s_nega
}
# Target data: rank 2
n0 <- 50; p0 <- 50; r_target <- 2
M_target <- M_s[1:n0, 1:p0]
X_target <- matrix(rpois(n0 * p0, exp(M_target)), n0, p0)
# Identify potential sources
result <- source_potential(
X_sources = source_list,
X0 = X_target,
r_max = 5,
ic_type = "IC1",
data_type = "count",
verbose = TRUE
)
print(result$positive_potential_sources) # Should be c(1, 2)
print(result$negative_sources) # Should be c(3, 4, 5)
print(result$r_target) # Should be 2
print(result$r_sources) # Should be c(2, 2, 3, 3, 3)
# }
Run the code above in your browser using DataLab