Learn R Programming

apcluster (version 1.2.1)

sparseToFull: Convert a Sparse Similarity Matrix to Standard Representation

Description

Converts a similarity matrix in sparse format to a full l by l matrix

Usage

sparseToFull(s, fill=-Inf)

Arguments

s
a similarity matrix in sparse format; s must have exactly three columns; the matrix interpreted as follows: assume that a given row contains an integer index i in the 1st column and an integer index j in the 2nd
fill
value to fill in for entries not specified in s

Value

  • returns a square similarity matrix

Details

Frey's and Dueck's implementation can handle $l\times l$ similarity matrices and similarity matrices of the sparse format described above. Presently our implementation does not make any use of the sparsity of the similarity matrix. The functions apcluster, apclusterK, and preferenceRange, therefore, only accept square similarity matrices. This function is a utility for converting sparse similarity matrices - wherever they may come from.

Note that most of Frey's and Dueck's Matlab functions make an internal conversion. Guessing the right format from the matrix's dimension may be wrong for $3\times 3$ matrices. We avoid this problem by explicitly distinguishing between sparse and dense similarity matrices (although we admit that clustering of 3 values makes as little sense as considering similarity matrices with only three entries).

References

http://www.bioinf.jku.at/software/apcluster

Frey, B. J. and Dueck, D. (2007) Clustering by passing messages between data points. Science 315, 972-976. DOI: http://dx.doi.org/10.1126/science.1136800{10.1126/science.1136800}.

Bodenhofer, U., Kothmeier, A., and Hochreiter, S. (2011) APCluster: an R package for affinity propagation clustering. Bioinformatics 27, 2463-2464. DOI: http://dx.doi.org/10.1093/bioinformatics/btr406{10.1093/bioinformatics/btr406}.

Examples

Run this code
## create similarity matrix in sparse format
sp <- matrix(c(1, 1, 0.5, 3, 1, 0.2, 5, 4, -0.2, 3, 3, 1.2), 4, 3, byrow=TRUE)
sp

## perform conversion
s <- sparseToFull(sp, fill=0)
s

Run the code above in your browser using DataLab