| Measure {causalOT} | R Documentation |
An R6 Class for setting up measures
Description
An R6 Class for setting up measures
Usage
Measure(
x,
weights = NULL,
probability.measure = TRUE,
adapt = c("none", "weights", "x"),
balance.functions = NA_real_,
target.values = NA_real_,
dtype = NULL,
device = NULL
)
Arguments
x |
The data points |
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 |
Value
Returns a Measure object
Public fields
balance_functionsthe functions of the data that we want to adjust towards the targets
balance_targetthe values the balance_functions are targeting
adaptWhat aspect of the data will be adapted. One of "none","weights", or "x".
devicethe
torch::torch_deviceof the data.dtypethe torch::torch_dtype of the data.
nthe rows of the covariates, x.
dthe columns of the covariates, x.
probability_measureis the measure a probability measure?
Active bindings
gradgets or sets gradient
init_weightsreturns the initial value of the weights
init_datareturns the initial value of the data
requires_gradchecks or turns on/off gradient
weightsgets or sets weights
xGets or sets the data
Methods
Public methods
Method detach()
generates a deep clone of the object without gradients.
Usage
Measure$detach()
Method get_weight_parameters()
Makes a copy of the weights parameters.
Usage
Measure$get_weight_parameters()
Method clone()
The objects of this class are cloneable with this method.
Usage
Measure$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Examples
if(torch::torch_is_installed()) {
m <- Measure(x = matrix(0, 10, 2), adapt = "none")
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")
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")
m$grad # NULL
m <- Measure(matrix(0, 10, 2), adapt = "weights")
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
}