torch.distributions.Independent
class Independent extends Distributionnew Independent(base_distribution: Distribution, reinterpreted_batch_ndims: number, options?: DistributionOptions)
- readonly
base_dist(Distribution) - – The base distribution.
- readonly
reinterpreted_batch_ndims(number) - – Number of rightmost batch dims to reinterpret as event dims.
- readonly
arg_constraints(Record<string, Constraint>) - readonly
support(Constraint) - readonly
has_rsample(boolean) - readonly
has_enumerate_support(boolean) - readonly
mean(Tensor) - readonly
mode(Tensor) - readonly
variance(Tensor)
Independent distribution wrapper: reinterprets batch dimensions as event dimensions.
This is useful for computing log_prob of a diagonal multivariate distribution, or when working with batched distributions where you want to treat some batch dims as event dims. Essential for:
- Converting independent batch dimensions to multivariate events
- Diagonal covariance multivariate models
- Reshaping probability computations
- Hierarchical model structures
Examples
// Create a 2D independent normal from a batch of 1D normals
const base = new Normal(torch.zeros(3), torch.ones(3)); // batch_shape=[3], event_shape=[]
const diag_mvn = new Independent(base, 1); // batch_shape=[], event_shape=[3]
diag_mvn.log_prob(torch.tensor([0, 1, 2])); // Sum of individual log_probs