感谢@ user20650和@ ??? 李哲远,这是我想出的解决方案:
# Example data set: df
# 3600 observations/points
# Create a vector of the cumulative distances between all of the points
require(Momocs)
cumdist <- coo_perimcum(df)
# Apply splines parametrically - define a spline interpolated mapping R --> R^2 of some curve c
# c(t) = (x(t), y(t))
# 't' is the set of cumulative distances (as defined above)
# Set the number of points to some fraction of the number of observations in the data …Run Code Online (Sandbox Code Playgroud) 给定 R 编程语言中的以下矩阵:
set.seed(123)
matrix_1 <- matrix(rbinom(100, 1, 0.5), nrow = 10, ncol = 10)
Run Code Online (Sandbox Code Playgroud)
这是一个深度优先搜索 (DFS) 算法,用于识别该矩阵中 1 的簇。在此上下文中,“簇”是整数在矩阵上的连续映射,最小簇大小为 3,并假设 8 个连通性(即,包括对角线)。注意:我尝试对包使用基于图像的方法EBImage,但其执行速度对于我的目的来说太慢了。我有数千个 100X100 矩阵需要分析!
find_clusters <- function(matrix) {
rows <- nrow(matrix)
cols <- ncol(matrix)
# Create a matrix of the same size to mark visited cells
visited <- matrix(0, nrow = rows, ncol = cols)
# Define all 8 possible movements from a cell (8-connectivity)
row_nbr <- c(-1, -1, -1, 0, 0, 1, 1, 1)
col_nbr <- …Run Code Online (Sandbox Code Playgroud)