R/00_pmclust.r

Defines functions pkmeans pmclust

Documented in pkmeans pmclust

### For general methods.

pmclust <- function(X = NULL, K = 2, MU = NULL,
    algorithm = .PMC.CT$algorithm, RndEM.iter = .PMC.CT$RndEM.iter,
    CONTROL = .PMC.CT$CONTROL, method.own.X = .PMC.CT$method.own.X,
    rank.own.X = .pbd_env$SPMD.CT$rank.source, comm = .pbd_env$SPMD.CT$comm){
  if(comm.all(is.null(X))){
    # Check global matrix.
    A <- exists("X.spmd", envir = .GlobalEnv)
    if(!A){
      if(! algorithm[1] %in% .PMC.CT$algorithm.gbd){
        comm.stop("A global X.spmd is required in .GlobalEnv.")
      }
    }
  }

  if(algorithm[1] %in% .PMC.CT$algorithm.gbd){
    ret <- pmclust.internal(X, K,
                            MU = MU,
                            algorithm = algorithm[1],
                            RndEM.iter = RndEM.iter,
                            CONTROL = CONTROL,
                            method.own.X = method.own.X[1],
                            rank.own.X = rank.own.X,
                            comm = comm)
  } else{
    comm.stop("The algorithm is not found.")
  }

  if(algorithm[1] %in% c("kmeans")){
    class(ret) <- "pkmeans"
  } else{
    class(ret) <- "pmclust"
  }
  ret
} # end of pmclust().


pkmeans <- function(X = NULL, K = 2, MU = NULL,
    algorithm = c("kmeans"),
    CONTROL = .PMC.CT$CONTROL, method.own.X = .PMC.CT$method.own.X,
    rank.own.X = .pbd_env$SPMD.CT$rank.source, comm = .pbd_env$SPMD.CT$comm){
  if(comm.all(is.null(X))){
    # Check global matrix.
    A <- exists("X.spmd", envir = .GlobalEnv)
    if(!A){
      if(! algorithm[1] %in% .PMC.CT$algorithm.gbd){
        comm.stop("A global X.spmd is required in .GlobalEnv.")
      }
    }
  }

  if(algorithm[1] == "kmeans"){
    ret <- pmclust.internal(X, K,
                            MU = MU,
                            algorithm = algorithm[1],
                            CONTROL = CONTROL,
                            method.own.X = method.own.X[1],
                            rank.own.X = rank.own.X,
                            comm = comm)
  } else{
    comm.stop("The algorithm is not found.")
  }
  class(ret) <- "pkmeans"
  ret
} # end of pkmeans().
snoweye/pmclust documentation built on Sept. 12, 2023, 5:42 a.m.