R/ADPclustering.R

Defines functions ADPclustering

Documented in ADPclustering

ADPclustering=function(Data,ClusterNo=NULL,PlotIt=FALSE,...){
  # INPUT
  # Data[1:n,1:d]     Data set with n observations and d features
  # ClusterNo         Number of clusters to search for
  #
  # OPTIONAL
  # PlotIt            Boolean. Decision to plot or not
  #
  # OUTPUT
  # Cls[1:n]          Clustering of data
  # Object            Object of adpclust
  #
  # Author: MT, 04/2018
  if (!requireNamespace('ADPclust', quietly = TRUE)) {
    message(
      'Subordinate clustering package (ADPclust) is missing. No computations are performed.
            Please install the package which is defined in "Suggests".'
    )
    return(
      list(
        Cls = rep(1, nrow(Data)),
        Object = "Subordinate clustering package (ADPclust) is missing.
                Please install the package which is defined in 'Suggests'."
      )
    )
  }
  
  if (!requireNamespace('cluster', quietly = TRUE)) {
    message(
      'Subordinate clustering package (cluster) is missing although its imported in ADPclust. No computations are performed.
            Please install the package which is defined in "Suggests".'
    )
    return(
      list(
        Cls = rep(1, nrow(Data)),
        Object = "Subordinate clustering package (cluster) is missing  although its imported in ADPclust.
                Please install the package which is defined in 'Suggests'."
      )
    )
  }
  
  if(is.null(ClusterNo))
	adp=ADPclust::adpclust(Data,...)
  else
  adp=ADPclust::adpclust(Data,nclust=ClusterNo,...)
  
  Cls=as.numeric(adp$clusters)
  Cls=ClusterRename(Cls,Data)
  if(PlotIt){
    ClusterPlotMDS(Data,Cls)
  }
  return(list(Cls=Cls,Object=adp))
}

#other package, were params have to be chosen
# DensityPeakClustering=function(DataOrDistances,Knn=10,rho=2, delta=2, method="euclidean",PlotIt=TRUE,...){
#   #Rodriguez, A., & Laio, A.: Clustering by fast search and find of density peaks. Science, 344(6191), 1492-1496. doi:10.1126/science.1242072, 2014.
#   requireNamespace('densityClust')
#   if(!is.matrix(DataOrDistances)){
#     warning('DataOrDistances is not a matrix. Calling as.matrix()')
#     DataOrDistances=as.matrix(DataOrDistances)
#   }
#   if(!mode(DataOrDistances)=='numeric'){
#     warning('Data is not a numeric matrix. Calling mode(DataOrDistances)="numeric"')
#     mode(DataOrDistances)='numeric'
#   }
#   AnzData = nrow(DataOrDistances)
#   
#   if (!isSymmetric(DataOrDistances)) {
#     requireNamespace('parallelDist')
#     
#     Distances=as.matrix(parallelDist::parDist(DataOrDistances,method=method))
#   }
#   
#   out=densityClust::densityClust(Distances,...)
#   
#   if(PlotIt){
#     requireNamespace('DataVisualizations')
#     if (!isSymmetric(DataOrDistances)) {
#       DataVisualizations::Plot3D(DataOrDistances,Cls,k=Knn)
#     }else{
#       requireNamespace('ProjectionBasedClustering')
#       
#       DataVisualizations::Plot3D(DataOrDistances,ProjectionBasedClustering::MDS(DataOrDistances,OutputDimension = 3)$ProjectedPoints)
#     }
#   }
#   return(list(Cls=NULL,DPobject=out))
# } 

Try the FCPS package in your browser

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

FCPS documentation built on July 8, 2021, 1:06 a.m.