Learn R Programming

kerntools (version 1.2.0)

Chi2: Chi-squared kernel

Description

`Chi2()` computes the basic \(\chi^2\) kernel for bag-of-words (BoW) or bag-of-visual-words data. This kernel computes the similarity between two nonnegative vectors that represent the occurrence counts of words in two different documents.

Usage

Chi2(X, g = NULL)

Value

Kernel matrix (dimension: NxN).

Arguments

X

Matrix or data.frame (dimension NxD) that contains nonnegative numbers. Each row represents the counts of words of N documents, while each column is a word.

g

Gamma hyperparameter. If g=0 or NULL, `Chi2()` returns the LeCam distances between the documents instead of the \(\chi^2\) kernel matrix. (Defaults=NULL).

References

Zhang, Jianguo, et al. Local features and kernels for classification of texture and object categories: A comprehensive study. International journal of computer vision 73 (2007): 213-238. Link

Examples

Run this code
## Example dataset: word counts in 4 documents
documents <- matrix( c(0, 1, 3, 2, 1, 0,  1, 1, 6,4,3,1,3,5,6,2), nrow=4,byrow=TRUE)
rownames(documents) <- paste0("doc",1:4)
colnames(documents) <- c("animal","life","tree","ecosystem")
documents
Chi2(documents,g=NULL)

Run the code above in your browser using DataLab