# nnsvs.mdn

## Layers

class nnsvs.mdn.MDNLayer(in_dim, out_dim, num_gaussians=30, dim_wise=False)[source]

Mixture Density Network layer

The input maps to the parameters of a Mixture of Gaussians (MoG) probability distribution, where each Gaussian has out_dim dimensions and diagonal covariance. If dim_wise is True, features for each dimension are modeld by independent 1-D GMMs instead of modeling jointly. This would workaround training difficulty especially for high dimensional data.

Implementation references: 1. Mixture Density Networks by Mike Dusenberry https://mikedusenberry.com/mixture-density-networks 2. PRML book https://www.microsoft.com/en-us/research/people/cmbishop/prml-book/ 3. sagelywizard/pytorch-mdn https://github.com/sagelywizard/pytorch-mdn 4. sksq96/pytorch-mdn https://github.com/sksq96/pytorch-mdn

in_dim

the number of dimensions in the input

Type

int

out_dim

the number of dimensions in the output

Type

int

num_gaussians

the number of mixture component

Type

int

dim_wise

whether to model data for each dimension separately

Type

bool

forward(minibatch)[source]

Forward for MDN

Parameters

minibatch (torch.Tensor) – tensor of shape (B, T, D_in) B is the batch size and T is data lengths of this batch, and D_in is in_dim.

Returns

Tensor of shape (B, T, G) or (B, T, G, D_out)

Log of mixture weights. G is num_gaussians and D_out is out_dim.

torch.Tensor: Tensor of shape (B, T, G, D_out)

the log of standard deviation of each Gaussians.

torch.Tensor: Tensor of shape (B, T, G, D_out)

mean of each Gaussians

Return type

torch.Tensor

## Loss

 `mdn_loss` Calculates the error, given the MoG parameters and the target.

## Inference

 `mdn_get_most_probable_sigma_and_mu` Return the mean and standard deviation of the Gaussian component whose weight coefficient is the largest as the most probable predictions. `mdn_get_sample` Sample from mixture of the Gaussian component whose weight coefficient is the largest as the most probable predictions.