FactorVAEObjective<T>
Models & Types · AiDotNet.LossFunctions
FactorVAE’s training objective: return reconstruction plus the KL divergence between the posterior and prior factor distributions.
Inheritance: LossFunctionBase<T> → FactorVAEObjective<T>
For Beginners
this model learns hidden “factors” that explain how a group of stocks move. During training it is allowed to peek at the future returns to work out what the factors must have been (the posterior). At prediction time the future is unknown, so it has to guess the factors from observable data alone (the prior). The KL term is what forces those two to agree, so the guess made without the future is close to the answer derived with it. Without it, the model would learn factors it can only recover by cheating, and would be useless at prediction time.
How It Works
Definition (Duan et al., AAAI 2022, section on prior-posterior learning):
L = L_recon(y_hat, y) + gamma * KL(q(z | y, x) || p(z | x)), where q is the posterior
factor distribution inferred with future returns and p the prior inferred without them. For
diagonal Gaussians the KL has the closed form
sum over factors of [ log(s_p/s_q) + (s_q^2 + (m_q - m_p)^2) / (2 s_p^2) - 1/2 ].
The KL is supplied by the model through a callback rather than recomputed here, because only the model knows its own prior/posterior heads. The callback returns a tape-connected scalar so the KL gradient reaches both heads; returning a detached value would leave the prior untrained and silently reduce this to plain reconstruction.
Constructors
| Constructor | Summary |
|---|---|
FactorVAEObjective(LossFunctionBase<T> reconstruction, Func<Tensor<T>> klProvider, double klWeight) |
Creates the objective. |
Methods
| Method | Summary |
|---|---|
T CalculateLoss(Vector<T> predicted, Vector<T> actual) |
Not supported. |
Tensor<T> ComputeTapeLoss(Tensor<T> predicted, Tensor<T> target) |