tensorflow / probability

Probabilistic reasoning and statistical analysis in TensorFlow
https://www.tensorflow.org/probability/
Apache License 2.0
4.26k stars 1.1k forks source link

Feature Request: Implement trainable probability vectors for mixture distributions #1257

Open prasanthcakewalk opened 3 years ago

prasanthcakewalk commented 3 years ago

Let's say we have a mixture model of the form P(x) = w1 P1(x) + w2 P2(x) + ... where the wi-s add up to 1.

Right now,

The way I got it to work was to create a custom model TrainableProbVector with one layer of trainable parameters. The model ignores its input and simply outputs the softmax of the parameters. But since keras models cannot not have inputs, it required some hacky coding to create a distribution that could both be trained, and be used like a regular distribution post-training.

Being able to create layers and/or models which don't have inputs will make this easier. A solution specific to tfp.Categorical and/or tfp.Mixture will also be great.

Thanks!

Strategy24 commented 8 months ago

As a hack you can make a constant input and pass it to a dense layer with softmax activation that will provide these probabilities.