Chi2: Chi-squared kernel

View source: R/kernel_functions.R

Chi2R Documentation

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)

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).

Value

Kernel matrix (dimension: NxN).

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

## 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)

kerntools documentation built on April 3, 2025, 7:52 p.m.