Title: | Density Ratio Estimation |
---|---|
Description: | Density ratio estimation. The estimated density ratio function can be used in many applications such as anomaly detection, change-point detection, covariate shift adaptation. The implemented methods are uLSIF (Hido et al. (2011) <doi:10.1007/s10115-010-0283-2>), RuLSIF (Yamada et al. (2011) <doi:10.1162/NECO_a_00442>), and KLIEP (Sugiyama et al. (2007) <doi:10.1007/s10463-008-0197-x>). |
Authors: | Koji Makiyama [aut, cre] |
Maintainer: | Koji Makiyama <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.1 |
Built: | 2024-11-11 04:14:23 UTC |
Source: | https://github.com/hoxo-m/densratio |
Estimate Density Ratio p(x)/q(x)
densratio(x1, x2, method = c("uLSIF", "RuLSIF", "KLIEP"), sigma = "auto", lambda = "auto", alpha = 0.1, kernel_num = 100, fold = 5, verbose = TRUE)
densratio(x1, x2, method = c("uLSIF", "RuLSIF", "KLIEP"), sigma = "auto", lambda = "auto", alpha = 0.1, kernel_num = 100, fold = 5, verbose = TRUE)
x1 |
numeric vector or matrix. Data from a numerator distribution p(x). |
x2 |
numeric vector or matrix. Data from a denominator distribution q(x). |
method |
"uLSIF" (default), "RuLSIF", or "KLIEP". |
sigma |
positive numeric vector. Search range of Gaussian kernel bandwidth. |
lambda |
positive numeric vector. Search range of regularization parameter for uLSIF and RuLSIF. |
alpha |
numeric in [0, 1]. Relative parameter for RuLSIF. Default 0.1. |
kernel_num |
positive integer. Number of kernels. |
fold |
positive integer. Numer of the folds of cross validation for KLIEP. |
verbose |
logical (default TRUE). |
densratio object that contains a function to compute estimated density ratio.
x1 <- rnorm(200, mean = 1, sd = 1/8) x2 <- rnorm(200, mean = 1, sd = 1/2) densratio_obj <- densratio(x1, x2) new_x <- seq(0, 2, by = 0.05) estimated_density_ratio <- densratio_obj$compute_density_ratio(new_x) plot(new_x, estimated_density_ratio, pch=19)
x1 <- rnorm(200, mean = 1, sd = 1/8) x2 <- rnorm(200, mean = 1, sd = 1/2) densratio_obj <- densratio(x1, x2) new_x <- seq(0, 2, by = 0.05) estimated_density_ratio <- densratio_obj$compute_density_ratio(new_x) plot(new_x, estimated_density_ratio, pch=19)
Estimate Density Ratio p(x)/q(x) by KLIEP (Kullback-Leibler Importance Estimation Procedure)
KLIEP(x1, x2, sigma = "auto", kernel_num = 100, fold = 5, verbose = TRUE)
KLIEP(x1, x2, sigma = "auto", kernel_num = 100, fold = 5, verbose = TRUE)
x1 |
numeric vector or matrix. Data from a numerator distribution p(x). |
x2 |
numeric vector or matrix. Data from a denominator distribution q(x). |
sigma |
positive numeric vector. Search range of Gaussian kernel bandwidth. |
kernel_num |
positive integer. Number of kernels. |
fold |
positive integer. Number of the folds of cross validation. |
verbose |
logical (default TRUE). |
KLIEP object that contains a function to compute estimated density ratio.
Estimate alpha-Relative Density Ratio p(x)/(alpha p(x) + (1-alpha) q(x)) by RuLSIF (Relative unconstrained Least-Square Importance Fitting)
RuLSIF(x1, x2, sigma = 10^seq(-3, 1, length.out = 9), lambda = 10^seq(-3, 1, length.out = 9), alpha = 0.1, kernel_num = 100, verbose = TRUE)
RuLSIF(x1, x2, sigma = 10^seq(-3, 1, length.out = 9), lambda = 10^seq(-3, 1, length.out = 9), alpha = 0.1, kernel_num = 100, verbose = TRUE)
x1 |
numeric vector or matrix. Data from a numerator distribution p(x). |
x2 |
numeric vector or matrix. Data from a denominator distribution q(x). |
sigma |
positive numeric vector. Search range of Gaussian kernel bandwidth. |
lambda |
positive numeric vector. Search range of regularization parameter. |
alpha |
numeric value from 0.0 to 1.0. Relative parameter. Default 0.1. |
kernel_num |
positive integer. Number of kernels. |
verbose |
logical. Default TRUE. |
RuLSIF object which has 'compute_density_ratio()'.
Compute Squared Euclid Distance
squared_euclid_distance(x, y)
squared_euclid_distance(x, y)
x |
a numeric vector. |
y |
a numeric vector. |
squared Euclid distance
Estimate Density Ratio p(x)/q(x) by uLSIF (unconstrained Least-Square Importance Fitting)
uLSIF(x1, x2, sigma = 10^seq(-3, 1, length.out = 9), lambda = 10^seq(-3, 1, length.out = 9), kernel_num = 100, verbose = TRUE)
uLSIF(x1, x2, sigma = 10^seq(-3, 1, length.out = 9), lambda = 10^seq(-3, 1, length.out = 9), kernel_num = 100, verbose = TRUE)
x1 |
numeric vector or matrix. Data from a numerator distribution p(x). |
x2 |
numeric vector or matrix. Data from a denominator distribution q(x). |
sigma |
positive numeric vector. Search range of Gaussian kernel bandwidth. |
lambda |
positive numeric vector. Search range of regularization parameter. |
kernel_num |
positive integer. Number of kernels. |
verbose |
logical(default TRUE). |
uLSIF object that contains a function to compute estimated density ratio.