R/SimiFunc.r

Defines functions SimiFunc

# this function outputs a similarity matrix based on one input data matrix
# with the interpoint dissimilarities measured by Euclidean distance
SimiFunc = function(dat){
  N = nrow(dat)
  SimiMat = matrix(0, N, N)
  for(i in 1:N) {
    for(j in 1:N) {
      SimiMat[i,j] = 1/norm(as.matrix(dat[i,]-dat[j,]), type="F")
      SimiMat[i,i] = 1
    }
  }
  return(SimiMat)
}

# alternatively, the following two lines do the exact same thing

# dist.vec = dist(X, method = 'euclidean')
# dist.mat <- as.matrix(dist.vec)
hankuipeng/HKCluster documentation built on May 27, 2019, 8:45 a.m.