Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
112 changes: 56 additions & 56 deletions R/ComputeEdgelist.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,62 +73,62 @@ ComputeEdgelist <- function(node.object,
#### MSBR 2024-06-16
#### Revised MSBR 2025-11-22 to fix k inheritance bug

if(!(is.null(k)) & nn.method == 'aoz'){
# df <- data.frame(x = node.object[[position.x]], y = node.object[[position.y]])
# df$barcode <- rownames(df)
# df$x <- as.character(df$x)
# df$y <- as.character(df$y)
# df$x <- as.numeric(df$x)
# df$y <- as.numeric(df$y)
# df <- df[,c('x','y')]
#
# coords <- as.matrix(df)#cbind(data.list[[i]]$x,data.list[[i]]$y)
coords <- as.matrix(cbind(node.object$x,node.object$y))
ord <- order(coords[,1])

n.neighbors <- k # inherits input 'k'
n.omp.t <- 1

n <- nrow(coords)


u.search.type <- 2 ##2 is very fast, 1 is slightly faster than 0, and 0 is the orginal slow one (2 and 0 should match, 1 is also corrected just different opposite sorting among the children)

indx <- spNNGP:::mkNNIndxCB(coords, n.neighbors, n.omp.t)

nn.indx <- indx$nnIndx
nn.indx.lu <- indx$nnIndxLU
nn.indx.run.time <- indx$run.time

storage.mode(nn.indx) <- "integer"
storage.mode(nn.indx.lu) <- "integer"

n.indx <- spNNGP:::mk.n.indx.list(nn.indx, n, n.neighbors)
names(n.indx) <- 1:nrow(coords)

# build sparse Adjacency Matrix
n.indx.names <- names(n.indx)
# this unusual code let's me reference a list element's
# name INSIDE the apply function, neat
# THIS NEXT STEP AOZ WROTE - IT'S SLOW AND COULD BE SPED UP
adj.ij <- lapply(setNames(n.indx.names, n.indx.names), function(nameindex) {
data.frame(i=rep(as.integer(nameindex), length(n.indx[[nameindex]])),
j=n.indx[[nameindex]])})
adj.ij <- data.table::rbindlist(adj.ij)
# clean and make it mutual
adj.ij <- na.omit(adj.ij)
adj.ij <- rbind(adj.ij,
data.frame(i=adj.ij$j,
j=adj.ij$i))
# map back to original coord indexing
adj.ij$i <- ord[adj.ij$i]
adj.ij$j <- ord[adj.ij$j]
adj.ij <- as.data.frame(adj.ij)
colnames(adj.ij) <- c("from", "to")
edgelist <- adj.ij


}
# if(!(is.null(k)) & nn.method == 'aoz'){
# # df <- data.frame(x = node.object[[position.x]], y = node.object[[position.y]])
# # df$barcode <- rownames(df)
# # df$x <- as.character(df$x)
# # df$y <- as.character(df$y)
# # df$x <- as.numeric(df$x)
# # df$y <- as.numeric(df$y)
# # df <- df[,c('x','y')]
# #
# # coords <- as.matrix(df)#cbind(data.list[[i]]$x,data.list[[i]]$y)
# coords <- as.matrix(cbind(node.object$x,node.object$y))
# ord <- order(coords[,1])
#
# n.neighbors <- k # inherits input 'k'
# n.omp.t <- 1
#
# n <- nrow(coords)
#
#
# u.search.type <- 2 ##2 is very fast, 1 is slightly faster than 0, and 0 is the orginal slow one (2 and 0 should match, 1 is also corrected just different opposite sorting among the children)
#
# indx <- spNNGP:::mkNNIndxCB(coords, n.neighbors, n.omp.t)
#
# nn.indx <- indx$nnIndx
# nn.indx.lu <- indx$nnIndxLU
# nn.indx.run.time <- indx$run.time
#
# storage.mode(nn.indx) <- "integer"
# storage.mode(nn.indx.lu) <- "integer"
#
# n.indx <- spNNGP:::mk.n.indx.list(nn.indx, n, n.neighbors)
# names(n.indx) <- 1:nrow(coords)
#
# # build sparse Adjacency Matrix
# n.indx.names <- names(n.indx)
# # this unusual code let's me reference a list element's
# # name INSIDE the apply function, neat
# # THIS NEXT STEP AOZ WROTE - IT'S SLOW AND COULD BE SPED UP
# adj.ij <- lapply(setNames(n.indx.names, n.indx.names), function(nameindex) {
# data.frame(i=rep(as.integer(nameindex), length(n.indx[[nameindex]])),
# j=n.indx[[nameindex]])})
# adj.ij <- data.table::rbindlist(adj.ij)
# # clean and make it mutual
# adj.ij <- na.omit(adj.ij)
# adj.ij <- rbind(adj.ij,
# data.frame(i=adj.ij$j,
# j=adj.ij$i))
# # map back to original coord indexing
# adj.ij$i <- ord[adj.ij$i]
# adj.ij$j <- ord[adj.ij$j]
# adj.ij <- as.data.frame(adj.ij)
# colnames(adj.ij) <- c("from", "to")
# edgelist <- adj.ij
#
#
# }
return(edgelist)

}
2 changes: 1 addition & 1 deletion packageUpdateScript.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ pkgdown::build_article(name = "07 Spatiotemporal NICHES",lazy = T)

# Install from release ?
install_github('msraredon/NICHES',
ref = 'v1.2.0',
ref = 'v1.2.1',
auth_token = 'f7ea5d8790fe721ac0c9d5ef115d04068b19ed6d',
force = T)
Loading