| Measure | R Documentation |
Constructor for an R6 Measure object.
cot_default_unit_id(x, unit.id = NULL)
Measure(
x,
weights = NULL,
probability.measure = TRUE,
adapt = c("none", "weights", "x"),
balance.functions = NA_real_,
target.values = NA_real_,
unit.id = NULL,
dtype = NULL,
device = NULL
)
x |
The data points |
unit.id |
Optional unit identifiers. If NULL, non-automatic row names from |
weights |
The empirical measure. If NULL, assigns equal weight to each observation |
probability.measure |
Is the empirical measure a probability measure? Default is TRUE. |
adapt |
Should we try to adapt the data ("x"), the weights ("weights"), or neither ("none"). Default is "none". |
balance.functions |
A matrix of functions of the covariates to target for mean balance. If NULL and |
target.values |
The targets for the balance functions. Should be the same length as columns in |
dtype |
The torch_tensor dtype or NULL. |
device |
The device to have the data on. Should be result of |
An R6 class for representing empirical measures (data + weights) with optional gradient-based adaptation via torch.
Use Measure() to construct a measure. The returned object supports
active bindings like $weights and $x, and methods like $detach(). See below for defined methods and fields.
Returns a Measure object
if(torch::torch_is_installed()) {
m <- Measure(x = matrix(0, 10, 2), adapt = "none",
device = torch::torch_device("cpu"),
dtype = torch::torch_double())
print(m)
m$x
m$x <- matrix(1,10,2) # must have same dimensions
m$x
m$weights
m$weights <- 1:10/sum(1:10)
m$weights
# with gradients
m <- Measure(x = matrix(0, 10, 2),
adapt = "weights",
device = torch::torch_device("cpu"),
dtype = torch::torch_double())
m$requires_grad # TRUE
m$requires_grad <- "none" # turns off
m$requires_grad # FALSE
m$requires_grad <- "x"
m$requires_grad # TRUE
m <- Measure(matrix(0, 10, 2), adapt = "none",
device = torch::torch_device("cpu"),
dtype = torch::torch_double())
m$grad # NULL
m <- Measure(matrix(0, 10, 2), adapt = "weights",
device = torch::torch_device("cpu"),
dtype = torch::torch_double())
loss <- sum(m$weights * 1:10)
loss$backward()
m$grad
# note the weights gradient is on the log softmax scale
#and the first parameter is fixed for identifiability
m$grad <- rep(1,9)
m$grad
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.