R/feature_centroid.R

Defines functions feature_centroid

Documented in feature_centroid

#' Centroid features.
#' 
#' Includes the coordinates of the mean coordinates of the the point cloud
#' and the statistics of the distances of all cities from it.
#'
#' @param x [\code{\link{tsp_instance}}]\cr
#'   TSP instance.
#' @return [\code{list}].
#' @export
feature_centroid = function(x) {
  coords = x$coords
  centroid = colMeans(coords)
  c_dists = apply(coords, 1, function(point) l2_norm(point - centroid))
  res = list(centroid_centroid_x = centroid[1], centroid_centroid_y = centroid[2])
  c(res, numvec_feature_statistics(c_dists, "centroid_dist"))
}

Try the tspmeta package in your browser

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

tspmeta documentation built on May 2, 2019, 2:43 a.m.