R/ewUpdate.R

#' Create a Bin from a Number of Pruned Bins
#' 
#' Given a number of bins that we would like to prune, combine them into a single bin and update all relevant bin information
#' 
#' @param bins A list of bin objects to be pruned
#' @param binMeasure A user supplied function to compute the measure associated with each bin
#' @param boundaryTest A user supplied function to test if a given point is contained in the bin
#' @param inputs A list containing additional input parameters required by user supplied functions 
#'
#' @return An updated bin object containing the contents of the pruned bins
#'
#' @export
ewUpdate  <- function(bins, binMeasure, boundaryTest, info){
  #Using pruned nodes, update information
  newContents <- c()
  newLowerBounds <- c()
  newUpperBounds <- c()
  
  for(i in 1:length(bins)){
    newContents <- rbind(newContents, bins[[i]]@contents)
    newLowerBounds <- rbind(newLowerBounds, bins[[i]]@info$binRange[1,])
    newUpperBounds <- rbind(newUpperBounds, bins[[i]]@info$binRange[2,])
  }
  
  newBoundary <- rbind(apply(newLowerBounds, 2, min), apply(newUpperBounds, 2, max))
  
  newBin <- bin(boundary = boundaryTest, contents = newContents, index = info$node, info=list(binRange = newBoundary))
  newBin@measure <- binMeasure(newBin, inputs)
  
  return(newBin)
  
}
rwoldford/treebinr documentation built on May 12, 2019, 4:38 a.m.