Distributions
This module contains functionality related to distributions.
base
Distribution
Base class for all distributions.
This class should be subclassed by other distributions when you want to use ground truth scores, denoisers, noise predictors, or velocity estimators.
Each distribution implementation provides methods to compute various vector fields related to the diffusion process, such as denoising (x0), noise prediction (eps), velocity estimation (v), and score estimation.
Source code in src/diffusionlab/distributions/base.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
batch_dist_params(N, dist_params)
staticmethod
Add a batch dimension to the distribution parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
N
|
int
|
The number of samples in the batch. |
required |
dist_params
|
Dict[str, Tensor]
|
A dictionary of parameters for the distribution. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Tensor]
|
A dictionary of parameters for the distribution, with a batch dimension added. |
Source code in src/diffusionlab/distributions/base.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
eps(x_t, t, diffusion_process, batched_dist_params, dist_hparams)
classmethod
Computes the noise predictor E[eps | x_t] at a given time t and input x_t, under the data model
x_t = alpha(t) * x_0 + sigma(t) * eps
where x_0 is drawn from the data distribution, and eps is drawn independently from N(0, I). This is stateless for the same reason as the denoiser method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_t
|
Tensor
|
The input tensor, of shape (N, D), where D is the shape of each data. |
required |
t
|
Tensor
|
The time tensor, of shape (N, ). |
required |
diffusion_process
|
DiffusionProcess
|
The diffusion process whose forward and reverse dynamics determine the time-evolution of the vector fields corresponding to the distribution. |
required |
batched_dist_params
|
Dict[str, Tensor]
|
A dictionary of batched parameters for the distribution. Each parameter is of shape (N, *P) where P is the shape of the parameter. |
required |
dist_hparams
|
Dict[str, Any]
|
A dictionary of hyperparameters for the distribution. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The prediction of eps, of shape (N, *D). |
Note
The batched_dist_params dictionary contains BATCHED tensors, i.e., the first dimension is the batch dimension.
Source code in src/diffusionlab/distributions/base.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
sample(N, dist_params, dist_hparams)
classmethod
Draws N i.i.d. samples from the data distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
N
|
int
|
The number of samples to draw. |
required |
dist_params
|
Dict[str, Tensor]
|
A dictionary of parameters for the distribution. |
required |
dist_hparams
|
Dict[str, Any]
|
A dictionary of hyperparameters for the distribution. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
A tuple (samples, metadata), where samples is a tensor of shape (N, *D) and metadata is any additional information. |
Any
|
For example, if the distribution has labels, the metadata is a tensor of shape (N, ) containing the labels. |
Tuple[Tensor, Any]
|
Note that the samples are always placed on the CPU. |
Source code in src/diffusionlab/distributions/base.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|
score(x_t, t, diffusion_process, batched_dist_params, dist_hparams)
classmethod
Computes the score estimator grad_x log p(x_t, t) at a given time t and input x_t, under the data model
x_t = alpha(t) * x_0 + sigma(t) * eps
where x_0 is drawn from the data distribution, and eps is drawn independently from N(0, I). This is stateless for the same reason as the denoiser method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_t
|
Tensor
|
The input tensor, of shape (N, D), where D is the shape of each data. |
required |
t
|
Tensor
|
The time tensor, of shape (N, ). |
required |
diffusion_process
|
DiffusionProcess
|
The diffusion process whose forward and reverse dynamics determine the time-evolution of the vector fields corresponding to the distribution. |
required |
batched_dist_params
|
Dict[str, Tensor]
|
A dictionary of batched parameters for the distribution. Each parameter is of shape (N, *P) where P is the shape of the parameter. |
required |
dist_hparams
|
Dict[str, Any]
|
A dictionary of hyperparameters for the distribution. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The prediction of grad_x log p(x_t, t), of shape (N, *D). |
Note
The batched_dist_params dictionary contains BATCHED tensors, i.e., the first dimension is the batch dimension.
Source code in src/diffusionlab/distributions/base.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
|
v(x_t, t, diffusion_process, batched_dist_params, dist_hparams)
classmethod
Computes the velocity estimator E[d/dt x_t | x_t] at a given time t and input x_t, under the data model
x_t = alpha(t) * x_0 + sigma(t) * eps
where x_0 is drawn from the data distribution, and eps is drawn independently from N(0, I). This is stateless for the same reason as the denoiser method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_t
|
Tensor
|
The input tensor, of shape (N, D), where D is the shape of each data. |
required |
t
|
Tensor
|
The time tensor, of shape (N, ). |
required |
diffusion_process
|
DiffusionProcess
|
The diffusion process whose forward and reverse dynamics determine the time-evolution of the vector fields corresponding to the distribution. |
required |
batched_dist_params
|
Dict[str, Tensor]
|
A dictionary of batched parameters for the distribution. Each parameter is of shape (N, *P) where P is the shape of the parameter. |
required |
dist_hparams
|
Dict[str, Any]
|
A dictionary of hyperparameters for the distribution. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The prediction of d/dt x_t, of shape (N, *D). |
Note
The batched_dist_params dictionary contains BATCHED tensors, i.e., the first dimension is the batch dimension.
Source code in src/diffusionlab/distributions/base.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
validate_hparams(dist_hparams)
classmethod
Validate the hyperparameters for the distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dist_hparams
|
Dict[str, Any]
|
A dictionary of hyperparameters for the distribution. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Throws
AssertionError: If the parameters are invalid, the assertion fails at exactly the point of failure.
Source code in src/diffusionlab/distributions/base.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
validate_params(possibly_batched_dist_params)
classmethod
Validate the parameters for the distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
possibly_batched_dist_params
|
Dict[str, Tensor]
|
A dictionary of parameters for the distribution. Each value is a PyTorch tensor, possibly having a batch dimension. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Throws
AssertionError: If the parameters are invalid, the assertion fails at exactly the point of failure.
Source code in src/diffusionlab/distributions/base.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
x0(x_t, t, diffusion_process, batched_dist_params, dist_hparams)
classmethod
Computes the denoiser E[x_0 | x_t] at a given time t and input x_t, under the data model
x_t = alpha(t) * x_0 + sigma(t) * eps
where x_0 is drawn from the data distribution, and eps is drawn independently from N(0, I).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_t
|
Tensor
|
The input tensor, of shape (N, D), where D is the shape of each data. |
required |
t
|
Tensor
|
The time tensor, of shape (N, ). |
required |
diffusion_process
|
DiffusionProcess
|
The diffusion process whose forward and reverse dynamics determine the time-evolution of the vector fields corresponding to the distribution. |
required |
batched_dist_params
|
Dict[str, Tensor]
|
A dictionary of batched parameters for the distribution. Each parameter is of shape (N, *P) where P is the shape of the parameter. |
required |
dist_hparams
|
Dict[str, Any]
|
A dictionary of hyperparameters for the distribution. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The prediction of x_0, of shape (N, *D). |
Note
The batched_dist_params dictionary contains BATCHED tensors, i.e., the first dimension is the batch dimension.
Source code in src/diffusionlab/distributions/base.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
empirical
EmpiricalDistribution
Bases: Distribution
An empirical distribution, i.e., the uniform distribution over a dataset. Formally, the distribution is defined as:
mu(B) = (1/N) * sum_(i=1)^(N) delta(x_i in B)
where x_i is the ith data point in the dataset, and N is the number of data points.
Distribution Parameters
- None
Distribution Hyperparameters
- labeled_data: A DataLoader of data which spawns the empirical distribution, where each data sample is a (data, label) tuple. Both data and label are PyTorch tensors.
Note
- This class has no sample() method as it's difficult to sample randomly from a DataLoader. In practice, you can sample directly from the DataLoader and apply filtering there.
Source code in src/diffusionlab/distributions/empirical.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
validate_hparams(dist_hparams)
classmethod
Validate the hyperparameters for the empirical distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dist_hparams
|
Dict[str, Any]
|
A dictionary of hyperparameters for the distribution. Must contain 'labeled_data' which is a DataLoader. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Throws
AssertionError: If the parameters are invalid.
Source code in src/diffusionlab/distributions/empirical.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
x0(x_t, t, diffusion_process, batched_dist_params, dist_hparams)
classmethod
Computes the denoiser E[x_0 | x_t] for an empirical distribution.
This method computes the denoiser by performing a weighted average of the dataset samples, where the weights are determined by the likelihood of x_t given each sample.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_t
|
Tensor
|
The input tensor, of shape (N, D), where D is the shape of each data. |
required |
t
|
Tensor
|
The time tensor, of shape (N, ). |
required |
diffusion_process
|
DiffusionProcess
|
The diffusion process. |
required |
batched_dist_params
|
Dict[str, Tensor]
|
A dictionary of batched parameters for the distribution. Not used for empirical distribution. |
required |
dist_hparams
|
Dict[str, Any]
|
A dictionary of hyperparameters for the distribution. Must contain 'labeled_data' which is a DataLoader. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The prediction of x_0, of shape (N, *D). |
Source code in src/diffusionlab/distributions/empirical.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
gmm
GMMDistribution
Bases: Distribution
A Gaussian Mixture Model (GMM) with K components. Formally, the distribution is defined as:
mu(B) = sum_(i=1)^(K) pi_i * N(mu_i, Sigma_i)(B)
where mu_i is the mean of the ith component, Sigma_i is the covariance matrix of the ith component, and pi_i is the prior probability of the ith component.
Distribution Parameters
- means: A tensor of shape (K, D) containing the means of the components.
- covs: A tensor of shape (K, D, D) containing the covariance matrices of the components.
- priors: A tensor of shape (K, ) containing the prior probabilities of the components.
Distribution Hyperparameters
- None
Source code in src/diffusionlab/distributions/gmm.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
sample(N, dist_params, dist_hparams)
classmethod
Source code in src/diffusionlab/distributions/gmm.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
validate_params(possibly_batched_dist_params)
classmethod
Source code in src/diffusionlab/distributions/gmm.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
x0(x_t, t, diffusion_process, batched_dist_params, dist_hparams)
classmethod
Computes the denoiser E[x_0 | x_t] for a GMM distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_t
|
Tensor
|
The input tensor, of shape (N, D). |
required |
t
|
Tensor
|
The time tensor, of shape (N, ). |
required |
diffusion_process
|
DiffusionProcess
|
The diffusion process. |
required |
batched_dist_params
|
Dict[str, Tensor]
|
A dictionary containing the batched parameters of the distribution. - means: A tensor of shape (N, K, D) containing the means of the components. - covs: A tensor of shape (N, K, D, D) containing the covariance matrices of the components. - priors: A tensor of shape (N, K) containing the prior probabilities of the components. |
required |
dist_hparams
|
Dict[str, Any]
|
A dictionary of hyperparameters for the distribution. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The prediction of x_0, of shape (N, D). |
Note
The batched_dist_params dictionary contains BATCHED tensors, i.e., the first dimension is the batch dimension.
Source code in src/diffusionlab/distributions/gmm.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
IsoGMMDistribution
Bases: Distribution
An isotropic (i.e., spherical variances) Gaussian Mixture Model (GMM) with K components. Formally, the distribution is defined as:
mu(B) = sum_(i=1)^(K) pi_i * N(mu_i, tau_i^2 * I_D)(B)
where mu_i is the mean of the ith component, tau is the standard deviation of the spherical variances, and pi_i is the prior probability of the ith component.
Distribution Parameters
- means: A tensor of shape (K, D) containing the means of the components.
- vars: A tensor of shape (K, ) containing the variances of the components.
- priors: A tensor of shape (K, ) containing the prior probabilities of the components.
Distribution Hyperparameters
- None
Source code in src/diffusionlab/distributions/gmm.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
|
sample(N, dist_params, dist_hparams)
classmethod
Draws N i.i.d. samples from the isotropic GMM distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
N
|
int
|
The number of samples to draw. |
required |
dist_params
|
Dict[str, Tensor]
|
A dictionary of parameters for the distribution. - means: A tensor of shape (K, D) containing the means of the components. - vars: A tensor of shape (K, ) containing the variances of the components. - priors: A tensor of shape (K, ) containing the prior probabilities of the components. |
required |
dist_hparams
|
Dict[str, Any]
|
A dictionary of hyperparameters for the distribution. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
A tuple (samples, labels), where samples is a tensor of shape (N, D) and labels is a tensor of shape (N, ) |
Tensor
|
containing the component indices from which each sample was drawn. |
Tuple[Tensor, Tensor]
|
Note that the samples are always placed on the CPU. |
Source code in src/diffusionlab/distributions/gmm.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
|
validate_params(possibly_batched_dist_params)
classmethod
Source code in src/diffusionlab/distributions/gmm.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
x0(x_t, t, diffusion_process, batched_dist_params, dist_hparams)
classmethod
Computes the denoiser E[x_0 | x_t] for an isotropic GMM distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_t
|
Tensor
|
The input tensor, of shape (N, D). |
required |
t
|
Tensor
|
The time tensor, of shape (N, ). |
required |
diffusion_process
|
DiffusionProcess
|
The diffusion process whose forward and reverse dynamics determine the time-evolution of the vector fields corresponding to the distribution. |
required |
batched_dist_params
|
Dict[str, Tensor]
|
A dictionary containing the batched parameters of the distribution. - means: A tensor of shape (N, K, D) containing the means of the components. - vars: A tensor of shape (N, K) containing the variances of the components. - priors: A tensor of shape (N, K) containing the prior probabilities of the components. |
required |
dist_hparams
|
Dict[str, Any]
|
A dictionary of hyperparameters for the distribution. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The prediction of x_0, of shape (N, D). |
Note
The batched_dist_params dictionary contains BATCHED tensors, i.e., the first dimension is the batch dimension.
Source code in src/diffusionlab/distributions/gmm.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
IsoHomoGMMDistribution
Bases: Distribution
An isotropic homoscedastic (i.e., equal spherical variances) Gaussian Mixture Model (GMM) with K components. Formally, the distribution is defined as:
mu(B) = sum_(i=1)^(K) pi_i * N(mu_i, tau^2 * I_D)(B)
where mu_i is the mean of the ith component, tau is the standard deviation of the spherical variances, and pi_i is the prior probability of the ith component.
Distribution Parameters
- means: A tensor of shape (K, D) containing the means of the components.
- var: A tensor of shape () containing the variances of the components.
- priors: A tensor of shape (K, ) containing the prior probabilities of the components.
Distribution Hyperparameters
- None
Source code in src/diffusionlab/distributions/gmm.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
|
sample(N, dist_params, dist_hparams)
classmethod
Draws N i.i.d. samples from the isotropic homoscedastic GMM distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
N
|
int
|
The number of samples to draw. |
required |
dist_params
|
Dict[str, Tensor]
|
A dictionary of parameters for the distribution. - means: A tensor of shape (K, D) containing the means of the components. - var: A tensor of shape () containing the shared variance of all components. - priors: A tensor of shape (K, ) containing the prior probabilities of the components. |
required |
dist_hparams
|
Dict[str, Any]
|
A dictionary of hyperparameters for the distribution. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
A tuple (samples, labels), where samples is a tensor of shape (N, D) and labels is a tensor of shape (N, ) |
Tensor
|
containing the component indices from which each sample was drawn. |
Tuple[Tensor, Tensor]
|
Note that the samples are always placed on the CPU. |
Source code in src/diffusionlab/distributions/gmm.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
|
validate_params(possibly_batched_dist_params)
classmethod
Source code in src/diffusionlab/distributions/gmm.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
|
x0(x_t, t, diffusion_process, batched_dist_params, dist_hparams)
classmethod
Computes the denoiser E[x_0 | x_t] for an isotropic homoscedastic GMM distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_t
|
Tensor
|
The input tensor, of shape (N, D). |
required |
t
|
Tensor
|
The time tensor, of shape (N, ). |
required |
diffusion_process
|
DiffusionProcess
|
The diffusion process whose forward and reverse dynamics determine the time-evolution of the vector fields corresponding to the distribution. |
required |
batched_dist_params
|
Dict[str, Tensor]
|
A dictionary containing the batched parameters of the distribution. - means: A tensor of shape (N, K, D) containing the means of the components. - var: A tensor of shape (N, ) containing the shared variance of all components. - priors: A tensor of shape (N, K) containing the prior probabilities of the components. |
required |
dist_hparams
|
Dict[str, Any]
|
A dictionary of hyperparameters for the distribution. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The prediction of x_0, of shape (N, D). |
Note
The batched_dist_params dictionary contains BATCHED tensors, i.e., the first dimension is the batch dimension.
Source code in src/diffusionlab/distributions/gmm.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
|
LowRankGMMDistribution
Bases: Distribution
A Gaussian Mixture Model (GMM) with K low-rank components. Formally, the distribution is defined as:
mu(B) = sum_(i=1)^(K) pi_i * N(mu_i, Sigma_i)(B)
where mu_i is the mean of the ith component, Sigma_i is the covariance matrix of the ith component, and pi_i is the prior probability of the ith component. Notably, Sigma_i is a low-rank matrix of the form
Sigma_i = A_i @ A_i^T
Distribution Parameters
- means: A tensor of shape (K, D) containing the means of the components.
- covs_factors: A tensor of shape (K, D, P) containing the tall factors of the covariance matrices of the components.
- priors: A tensor of shape (K, ) containing the prior probabilities of the components.
Distribution Hyperparameters
- None
Note
- The covariance matrices are not explicitly stored, but rather computed as Sigma_i = A_i @ A_i^T.
- The time and memory complexity is much lower in this class compared to the full GMM class, if and only if each covariance is low-rank (P << D).
Source code in src/diffusionlab/distributions/gmm.py
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 |
|
sample(N, dist_params, dist_hparams)
classmethod
Draws N i.i.d. samples from the low-rank GMM distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
N
|
int
|
The number of samples to draw. |
required |
dist_params
|
Dict[str, Tensor]
|
A dictionary of parameters for the distribution. - means: A tensor of shape (K, D) containing the means of the components. - covs_factors: A tensor of shape (K, D, P) containing the tall factors of the covariance matrices. - priors: A tensor of shape (K, ) containing the prior probabilities of the components. |
required |
dist_hparams
|
Dict[str, Any]
|
A dictionary of hyperparameters for the distribution. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
A tuple (samples, labels), where samples is a tensor of shape (N, D) and labels is a tensor of shape (N, ) |
Tensor
|
containing the component indices from which each sample was drawn. |
Tuple[Tensor, Tensor]
|
Note that the samples are always placed on the CPU. |
Source code in src/diffusionlab/distributions/gmm.py
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 |
|
validate_params(possibly_batched_dist_params)
classmethod
Source code in src/diffusionlab/distributions/gmm.py
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
|
x0(x_t, t, diffusion_process, batched_dist_params, dist_hparams)
classmethod
Computes the denoiser E[x_0 | x_t] for a low-rank GMM distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_t
|
Tensor
|
The input tensor, of shape (N, D). |
required |
t
|
Tensor
|
The time tensor, of shape (N, ). |
required |
diffusion_process
|
DiffusionProcess
|
The diffusion process whose forward and reverse dynamics determine the time-evolution of the vector fields corresponding to the distribution. |
required |
batched_dist_params
|
Dict[str, Tensor]
|
A dictionary containing the batched parameters of the distribution. - means: A tensor of shape (N, K, D) containing the means of the components. - covs_factors: A tensor of shape (N, K, D, P) containing the tall factors of the covariance matrices. - priors: A tensor of shape (N, K) containing the prior probabilities of the components. |
required |
dist_hparams
|
Dict[str, Any]
|
A dictionary of hyperparameters for the distribution. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
The prediction of x_0, of shape (N, D). |
Note
The batched_dist_params dictionary contains BATCHED tensors, i.e., the first dimension is the batch dimension. The covariance matrices are implicitly defined as Sigma_i = A_i @ A_i^T, where A_i is the ith factor.
Source code in src/diffusionlab/distributions/gmm.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 |
|