Package: densityratio 0.1.1

densityratio: Distribution Comparison Through Density Ratio Estimation

Fast, flexible and user-friendly functionality to directly estimate the ratio of two probability distributions from samples from these distributions without estimating the densities separately. Estimated density ratios can, among other things, be used for prediction, outlier detection, change-point detection in time-series, importance weighting under domain adaptation (i.e., sample selection bias) and evaluation of synthetic data utility. The rationale behind these use-cases is that differences between two data distributions can be captured in the ratio their density ratio, which is estimated over the entire multivariate space of the data. Computationally intensive code is executed in `C++` using `Rcpp` and `RcppArmadillo`. The package provides good default hyperparameters that can be optimized in cross-validation (we do recommend understanding those parameters before using `densityratio` in practice). Multiple density ratio estimation methods are implemented, such as unconstrained least-squares importance fitting (`ulsif()`), Kullback-Leibler importance estimation procedure (`kliep()`), spectral density ratio estimation (`spectral()`), and least-squares heterodistributional subspace search (`lhss()`).

Authors:Thom Volker [aut, cre, cph], Carlos Gonzalez Poses [ctb], Erik-Jan van Kesteren [ctb]

densityratio_0.1.1.tar.gz
densityratio_0.1.1.zip(r-4.5)densityratio_0.1.1.zip(r-4.4)densityratio_0.1.1.zip(r-4.3)
densityratio_0.1.1.tgz(r-4.5-x86_64)densityratio_0.1.1.tgz(r-4.5-arm64)densityratio_0.1.1.tgz(r-4.4-x86_64)densityratio_0.1.1.tgz(r-4.4-arm64)densityratio_0.1.1.tgz(r-4.3-x86_64)densityratio_0.1.1.tgz(r-4.3-arm64)
densityratio_0.1.1.tar.gz(r-4.5-noble)densityratio_0.1.1.tar.gz(r-4.4-noble)
densityratio_0.1.1.tgz(r-4.4-emscripten)densityratio_0.1.1.tgz(r-4.3-emscripten)
densityratio.pdf |densityratio.html
densityratio/json (API)

# Install 'densityratio' in R:
install.packages('densityratio', repos = c('https://thomvolker.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/thomvolker/densityratio/issues

Uses libs:
  • openblas– Optimized BLAS
  • c++– GNU Standard C++ Library v3
  • openmp– GCC OpenMP (GOMP) support library
Datasets:

On CRAN:

Conda:

openblascppopenmp

4.07 score 6 stars 18 scripts 10 exports 33 dependencies

Last updated 2 months agofrom:fa8ef0f113. Checks:4 OK, 8 NOTE. Indexed: yes.

TargetResultLatest binary
Doc / VignettesOKMar 30 2025
R-4.5-win-x86_64NOTEMar 30 2025
R-4.5-mac-x86_64NOTEMar 30 2025
R-4.5-mac-aarch64NOTEMar 30 2025
R-4.5-linux-x86_64NOTEMar 30 2025
R-4.4-win-x86_64NOTEMar 30 2025
R-4.4-mac-x86_64NOTEMar 30 2025
R-4.4-mac-aarch64NOTEMar 30 2025
R-4.4-linux-x86_64NOTEMar 30 2025
R-4.3-win-x86_64OKMar 30 2025
R-4.3-mac-x86_64OKMar 30 2025
R-4.3-mac-aarch64OKMar 30 2025

Exports:distancekernel_gaussiankliepkmmlhssnaiveplot_bivariateplot_univariatespectralulsif

Dependencies:clicolorspacefansifarverggplot2gluegtableisobandlabelinglatticelifecyclemagrittrMASSMatrixmgcvmunsellnlmeosqppbapplypillarpkgconfigR6RColorBrewerRcppRcppArmadilloRcppProgressrlangscalestibbleutf8vctrsviridisLitewithr

Readme and manuals

Help Manual

Help pageTopics
Bivariate plotcreate_bivariate_plot
Indivual univariate plotcreate_univariate_plot
denominator_datadenominator_data
denominator_smalldenominator_small
Create a Gram matrix with squared Euclidean distances between observations in the input matrix 'X' and the input matrix 'Y'distance
A histogram of density ratio estimatesdr.histogram plot.kliep plot.kmm plot.lhss plot.naivedensityratio plot.spectral plot.ulsif
Create gaussian kernel gram matrix from distance matrixkernel_gaussian
Kullback-Leibler importance estimation procedurekliep
Kernel mean matching approach to density ratio estimationkmm
Least-squares heterodistributional subspace searchlhss
Naive density ratio estimationnaive
numerator_datanumerator_data
numerator_smallnumerator_small
Single permutationpermute permute.kliep permute.kmm permute.lhss permute.naivedensityratio permute.spectral permute.ulsif
Densityratio in bidimensional plotplot_bivariate
Scatter plot of density ratios and individual variablesplot_univariate
Obtain predicted density ratio values from a 'kliep' objectpredict.kliep
Obtain predicted density ratio values from a 'kmm' objectpredict.kmm
Obtain predicted density ratio values from a 'lhss' objectpredict.lhss
Obtain predicted density ratio values from a 'naivedensityratio' objectpredict.naivedensityratio
Obtain predicted density ratio values from a 'spectral' objectpredict.spectral
Obtain predicted density ratio values from a 'ulsif' objectpredict.ulsif
Print a 'kliep' objectprint.kliep
Print a 'kmm' objectprint.kmm
Print a 'lhss' objectprint.lhss
Print a 'naivedensityratio' objectprint.naivedensityratio
Print a 'spectral' objectprint.spectral
Print a 'summary.kliep' objectprint.summary.kliep
Print a 'summary.kmm' objectprint.summary.kmm
Print a 'summary.lhss' objectprint.summary.lhss
Print a 'summary.naivedensityratio' objectprint.summary.naivedensityratio
Print a 'summary.spectral' objectprint.summary.spectral
Print a 'summary.ulsif' objectprint.summary.ulsif
Print a 'ulsif' objectprint.ulsif
Spectral series based density ratio estimationspectral
Extract summary from 'kliep' object, including two-sample significance test for homogeneity of the numerator and denominator samplessummary.kliep
Extract summary from 'kmm' object, including two-sample significance test for homogeneity of the numerator and denominator samplessummary.kmm
Extract summary from 'lhss' object, including two-sample significance test for homogeneity of the numerator and denominator samplessummary.lhss
Extract summary from 'naivedensityraito' object, including two-sample significance test for homogeneity of the numerator and denominator samplessummary.naivedensityratio
Extract summary from 'spectral' object, including two-sample significance test for homogeneity of the numerator and denominator samplessummary.spectral
Extract summary from 'ulsif' object, including two-sample significance test for homogeneity of the numerator and denominator samplessummary.ulsif
Unconstrained least-squares importance fittingulsif