R/boxcox-stress.r

Defines functions rcboxcox energy

# Use 1e36 consistently to subsitute non-local distances
.myInf <- 1e36

# rcboxcox
# Basic wrapper to C function
# 
# @returns the configuration generated by B-C stress function.
# @arguments intial configuration, n x d matrix
# @arguments dissimilarity matrix. Keeps local distances and use .myInf to subsitute non-local distances. Saves both local distances and neighborhood information. 
# @arguments 
# @arguments 
# @arguments 
# @arguments 
# @arguments maximum number of interations
# @keyword internal
rcboxcox <- function(X1, D0, lam, mu, nu, tau, niter)   {
  sel <- D0 != 0 & D0 != .myInf

  k <- sum(sel)/nrow(D0) # Average size of neighhood 

  energy <- 0
  c <- k/nrow(D0) * (median(D0[sel])) ^ (1/lam+nu) * tau # Relative weight of repulsion

  tmp<-.C("boxcox", 
    X1 = as.double(t(X1)), 
    D0 = as.double(D0),
    n = as.integer(nrow(X1)),
    d = as.integer(ncol(X1)),
    lam = as.double(lam), 
    mu = as.double(mu),
    nu = as.double(nu), 
    c = as.double(c), 
    energy = as.double(energy), 
    niter = as.integer(niter)
  )

  proj <- matrix(tmp$X1, ncol = ncol(X1), byrow = TRUE)
  attr(proj, "energy") <- tmp$energy
  proj
}


# Energy
# Extract energy of configuration
# 
# @keyword manip
energy <- function(x) attr(x, "energy")
hadley/localmds documentation built on May 17, 2019, 10:42 a.m.