View source: R/get_optimal_grid.R
get_optimal_grid | R Documentation |
This function computes an optimal grid assignment between two variables x
and y
based on a third variable z
.
It uses the quantiles of x
and y
to segment the data based on the distribution of z
. Then, it computes the cost of
assigning points from x
to y
by calculating the counts of y
values within quantile ranges of x
and y
, and then solves
the assignment problem using the Hungarian algorithm.
get_optimal_grid(x, y, z)
x |
A numeric vector of values representing the first variable. |
y |
A numeric vector of values representing the second variable. |
z |
A numeric vector representing the distribution of the third variable, used to define quantiles for |
A numeric vector of optimal indices that represents the optimal assignment of x
values to y
values.
# Test Case 1: Simple uniform data
x <- rnorm(1000)
y <- rnorm(1000)
z <- sample(1:5, 1000, replace = TRUE)
optimal_assignment <- get_optimal_grid(x, y, z)
# Test Case 2: Data with a skewed distribution
x <- rexp(1000, rate = 1)
y <- rpois(1000, lambda = 2)
z <- sample(1:3, 1000, replace = TRUE)
optimal_assignment <- get_optimal_grid(x, y, z)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.