R/00_pmclust_internal.r

Defines functions pmclust.internal

### For general internal methods.

pmclust.internal <- function(X = NULL, K = 2, MU = NULL,
    algorithm = .PMC.CT$algorithm.gbd, 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){
  # Check.
  if(! (algorithm[1] %in% .PMC.CT$algorithm.gbd)){
    comm.stop("The algorithm is not supported")
  }
  if(! (method.own.X[1] %in% .PMC.CT$method.own.X)){
    comm.stop("The method.own.X is not found.")
  }

  # Check X.
  if(comm.all(is.null(X))){
    # Assume X.spmd in .GlobalEnv and no need for converting or check.
  } else{
    # Assign X to .pmclustEnv if it is not in .GlobalEnv
    convert.data(X, method.own.X[1], rank.own.X, comm)
  }

  # Set global variables.
  PARAM.org <- set.global(K = K, RndEM.iter = RndEM.iter)
  if(! comm.all(is.null(CONTROL))){
    tmp <- .pmclustEnv$CONTROL[!(names(.pmclustEnv$CONTROL) %in%
                                 names(CONTROL))]
    .pmclustEnv$CONTROL <- c(tmp, CONTROL)
  }

  # Initialization for algorithms.
  if(! comm.all(is.null(MU))){
    if(algorithm[1] != "kmeans"){
      PARAM.org <- initial.em(PARAM.org, MU = MU)
    } else{
      PARAM.org <- initial.center(PARAM.org, MU = MU)
    }
  } else{
    if(algorithm[1] != "kmeans"){
      PARAM.org <- initial.RndEM(PARAM.org)
    } else{
      PARAM.org <- initial.center(PARAM.org)
    }
  }

  # Update steps.
  method.step <- switch(algorithm[1],
                        "em" = em.step,
                        "aecm" = aecm.step,
                        "apecm" = apecm.step,
                        "apecma" = apecma.step,
                        "kmeans" = kmeans.step,
                        NULL)
  PARAM.new <- method.step(PARAM.org)

  # Obtain classifications.
  if(algorithm[1] == "kmeans"){
    kmeans.update.class()
  } else{
    em.update.class()
  }

  # Get class numbers.
  N.CLASS <- get.N.CLASS(K)

  # For return.
  ret <- list(algorithm = algorithm[1],
              param = PARAM.new,
              class = .pmclustEnv$CLASS.spmd,
              n.class = N.CLASS,
              check = .pmclustEnv$CHECK)
  ret
} # End of pmclust.internal().

Try the pmclust package in your browser

Any scripts or data that you put into this service are public.

pmclust documentation built on Feb. 11, 2021, 5:05 p.m.