Learn R Programming

hilbertSimilarity (version 0.4.3)

make.cut: Generate Cutting Points for a Multidimensional Matrix

Description

For a given column cur.ch that belongs to a matrix, and a given number of cuts n, compute n-1 bins using either fixed of combined limits

Usage

make.cut(mat, n = 5, count.lim = 40)

Arguments

mat

the matrix to cut

n

the number of cuts to generate (defaults to 5)

count.lim

the minimum number of counts to consider for density (defaults to 40)

Value

a list of of cuts for each column in mat, see details

Details

the fixed limits correspond to 5 equally spaced values over the range of the column. the combined limits take the local minima and maxima determined using the localMinima and localMaxima functions, to adjust the limits using the following algorithm:

  • define d as half the distance between 2 fixed limits

  • merge local minima and local maxima that are closer than d

  • if any fixed limit is closer to a local minima than d, move the fixed limit to the local minima; move the limits that are not been moved yet, and that are before and after the moved limit so that they are evenly spread; repeat until no fixed limit can be moved

  • if some limits have been moved to a local minima, remove limits that are closer than d to a local maxima; move the limits that are not been moved yet, and that are before and after the deleted limit so that they are evenly spread; repeat until no fixed limit can be moved

  • if no limits has been moved to a local minima, move limits that are closer than d to a local maxima; move the limits that are not been moved yet, and that are before and after the moved limit so that they are evenly spread; repeat until no fixed limit can be moved

The function returns a list of lists, one for each column in mat, consisting of

  • cur.dens the density used to describe the data

  • cur.hist the histogram used to describe the data

  • fixed the fixed, evenly spaced cuts

  • minima the local minima detected in the data

  • maxima the local maxima detected in the data

  • combined the cuts defined using a combination of fixed positions, local minima and local maxima

Examples

Run this code
# NOT RUN {
# generate a random 3D matrix with 2 peaks
mat <- rbind(matrix(rnorm(300),ncol=3),
             matrix(rnorm(300,5,1),ncol=3))
dimnames(mat)[[2]] <- LETTERS[1:3]
# estimate the Hilbert order
hilbert.order(mat)
# generate 2 bins with a minimum bin size of 5
cuts <- make.cut(mat,n=3,count.lim=5)
show.cut(cuts)
# Generate the cuts
cut.mat <- do.cut(mat,cuts,type='fixed')
head(cut.mat)
# }

Run the code above in your browser using DataLab