Learn R Programming

densityratio (version 0.2.1)

ulsif: Unconstrained least-squares importance fitting

Description

Unconstrained least-squares importance fitting

Usage

ulsif(
  df_numerator,
  df_denominator,
  intercept = TRUE,
  scale = "numerator",
  nsigma = 10,
  sigma_quantile = NULL,
  sigma = NULL,
  nlambda = 20,
  lambda = NULL,
  ncenters = 200,
  centers = NULL,
  parallel = FALSE,
  nthreads = NULL,
  progressbar = TRUE
)

Value

ulsif-object, containing all information to calculate the density ratio using optimal sigma and optimal weights.

Arguments

df_numerator

data.frame with exclusively numeric variables with the numerator samples

df_denominator

data.frame with exclusively numeric variables with the denominator samples (must have the same variables as df_denominator)

intercept

logical Indicating whether to include an intercept term in the model. Defaults to TRUE.

scale

"numerator", "denominator", or NULL, indicating whether to standardize each numeric variable according to the numerator means and standard deviations, the denominator means and standard deviations, or apply no standardization at all.

nsigma

Integer indicating the number of sigma values (bandwidth parameter of the Gaussian kernel gram matrix) to use in cross-validation.

sigma_quantile

NULL or numeric vector with probabilities to calculate the quantiles of the distance matrix to obtain sigma values. If NULL, nsigma values between 0.05 and 0.95 are used.

sigma

NULL or a scalar value to determine the bandwidth of the Gaussian kernel gram matrix. If NULL, nsigma values between 0.05 and 0.95 are used.

nlambda

Integer indicating the number of lambda values (regularization parameter), by default, lambda is set to 10^seq(3, -3, length.out = nlambda).

lambda

NULL or numeric vector indicating the lambda values to use in cross-validation

ncenters

Maximum number of Gaussian centers in the kernel gram matrix. Defaults to all numerator samples.

centers

NULL or numeric matrix with the same dimensions as the data, indicating the centers for the Gaussian kernel gram matrix.

parallel

logical indicating whether to use parallel processing in the cross-validation scheme.

nthreads

NULL or integer indicating the number of threads to use for parallel processing. If parallel processing is enabled, it defaults to the number of available threads minus one.

progressbar

Logical indicating whether or not to display a progressbar.

References

Kanamori, T., Hido, S., & Sugiyama, M. (2009). A least-squares approach to direct importance estimation. Journal of Machine Learning Research, 10, 1391-1445. Available from https://jmlr.org/papers/v10/kanamori09a.html

Examples

Run this code
set.seed(123)
# Fit model
dr <- ulsif(numerator_small, denominator_small)
# Inspect model object
dr
# Obtain summary of model object
summary(dr)
# Plot model object
plot(dr)
# Plot density ratio for each variable individually
plot_univariate(dr)
# Plot density ratio for each pair of variables
plot_bivariate(dr)
# Predict density ratio and inspect first 6 predictions
head(predict(dr))
# Fit model with custom parameters
ulsif(numerator_small, denominator_small, sigma = 2, lambda = 2)

Run the code above in your browser using DataLab