A mixture density network (MDN) is a network whose output layer parameterises a Gaussian mixture over a scalar target:
The network itself is not part of this task: you receive its raw outputs for a batch of examples and compute everything a training loop and a predictor need.
Implement mdn_outputs(y, gate_logits, mu, s, link="softplus"):
y: targets, shape (N,). gate_logits (), mu () and s (raw scale outputs) all have shape (N, K).link="softplus", or when link="exp".Return a dict with:
"nll": the mean over the batch of , as a float. It must stay finite even when is so far from every component that each density underflows to zero in floating point."resp": posterior responsibilities , shape (N, K)."mean": the mixture mean , shape (N,)."mode": the prediction of the most probable expert a priori, with (lowest index on ties), shape (N,)."grad_logits" and "grad_mu": the gradients of the mean NLL with respect to gate_logits and mu, shape (N, K) each.