R/GEnIs.R

Defines functions GEnIs GEnIs.coMa print.GEnIs

Documented in GEnIs GEnIs.coMa

#' @export
GEnIs<- function(object){
  UseMethod("GEnIs",object)
}

#' @name GEnIs
#' @title Global measures of global index based on entropy
#' @description General function that groups global measures of global index based on entropy. This function is made up of:
#' Normalized mutual information using the arithmetic mean of the entropies on map and on ground truthing.
#' Normalized mutual information using the geometric mean of the entropies on map and on ground truthing. Mutual information, which is a symmetric measure to quantify the statistical information shared between two distributions (Cover and Thomas, 1991), provides a sound indication of the shared information between a pair of clusterings.
#' Normalized mutual information using the arithmetic mean of the maximum entropies on map and on ground truthing.
#' Normalized mutual information using the entropy on ground truthing.
#' Normalized mutual information using the entropy on map.
#' @usage GEnIs(object)
#' @param object a coMa object (confusion matrix object)
#' @details In the normalized mutual information using the arithmetic mean of the entropies on map and on ground truthing, Arithmetic mean is used because of the analogy with a normalized inner product in Hilbert space.
#' In the normalized mutual information using the arithmetic mean of the maximum entropies on map and on ground truthing ,geometric mean is used because of the analogy with a normalized inner product in Hilbert space.
#' @return \code{GEnIs} returns a list with the following elements:
# #' \item{Normalized mutual information using the arithmetic mean of the entropies on map and on ground truthing.}
# #' \item{Normalized mutual information using the geometric mean of the entropies on map and on ground truthing.}
# #' \item{Normalized mutual information using the arithmetic mean of the maximum entropies on map and on ground truthing.}
# #' \item{Normalized mutual information using the entropy on ground truthing.}
# #' \item{Normalized mutual information using the entropy on map.}
#' @references
#' Strehl, A., & Ghosh, J. (2002).
#' \emph{ Cluster ensembles: A knowledge reuse framework for combining multiple partitions.}
#' Journal of Machine Learning Research, 3, 583-617.
#' @references
#' Strehl, A., & Ghosh, J. (2002).
#' \emph{ Cluster ensembles: A knowledge reuse framework for combining multiple partitions.}
#' Journal of Machine Learning Research, 3, 583-617.
#' @references
#' Ghosh, J., Strehl, A., & Merugu, S. (2002).
#' \emph{A consensus framework for integrating distributed clusterings under limited knowledge sharing.}
#' Proc. NSF Workshop on Next Generation Data Mining, 99-108.
#' @references
#' Finn, J. T. (1993).
#' \emph{Use of the average mutual information index in evaluating classification error and consistency.}
#' International Journal of Geographical Information Systems, 7, 349-366.
#' @examples
#' #Let evaluate measures of global index based on entropy
#' ## Confusion matrix included in Congalton and Green (2009), pg. 108.
#' x <- coMa(cbind(c(65,6,0,4),c(4,81,11,7),c(22,5,85,3),c(24,8,19,90)))
#' ## Measures of global index based on entropy
#' Entropy <- GEnIs(x)
#' @export

#Funcion general que agrupa los indices globales basados en entropias
GEnIs.coMa <- function(object){
  if (!inherits(object,"coMa"))
    stop("object must be a coMa object")
  x<-object$data

  Margcol <- colSums(x)
  Margrow <- rowSums(x)
  n = sqrt(length(x))
  N = sum(x)
  p = N*(t(t(x)/(rep(Margrow,rep(n,n))*Margcol)))
  logaritmo = ifelse(p == 0, 0, log2(p))
  ami = sum ((x/N) * logaritmo)

  HB = - sum ((Margrow/N) * (log2(Margrow/N)))
  HA = - sum ((Margcol/N) * (log2(Margcol/N)))

  if (HA + HB == 0) {
    stop ("/ by 0")
  }

  nmiam = 2*ami/(HA+HB)


  if (HA * HB == 0) {
    stop ("/ by 0")
  }

  nmigm = ami / sqrt(HA * HB)

  nmimx = ami / log2 (n)

  if (HA == 0){
    stop ("/ by 0")
  }

  nmip = ami/HA

  if(HB == 0){
    stop("/ by 0")
  }

  nmiu = ami/HB


  ans <- list(
    Normalized.Arithmetic.Mean = nmiam,
    Normalized.Geometric.Mean = nmigm,
    Normalized.Arithmetic.Mean.Maximum = nmimx,
    Normalized.Mutual.Information.Producer = nmip,
    Normalized.Mutual.Information.User = nmiu)
  class(ans)<-"GEnIs"
  return(ans)

}


#' @method print GEnIs
#' @export
print.GEnIs<-function(x, ...){
  function (x, ...){
    if (!inherits(x, "GEnIs")){
      stop("x not is a coMa object")
    }else{
      cat("Object class coMa\n")
      cat("GKappa\n")
    }
  }
}
ujaen-statistics/ThemAAs documentation built on Nov. 5, 2019, 11:03 a.m.