# mixture model from a factorized distribution

46 views

### Tanmoy Sanyal

Sep 26, 2021, 12:35:57 AM9/26/21
to TensorFlow Probability
Hi all,

I'm new to TFP, so this may be a stupid question.

I want to construct a mixture model out of a custom kernel which is a product distribution of three separate distributions. The random variable is a 7D vector x = (t1, t2, t3, r1, r2, r3, a), and is modelled as:

P(x | mu, sigma, r0, kr, a0, ka) = P_t (t | mu, sigma) P_r (r | r0, kr) P_a (a | a0, ka)

where t = (t1, t2, t3), r = (r1, r2, r3) in the above expression. mu is a 3D vector, sigma is a 3x3 diagonal covariance matrix, so can be expressed essentially as a 3D vector again.
r0 is a 3D vector. kr, ka, a0 are scalars.

I expressed the three factors as three different distributions according to my particular problem: P_t as a tfp.MultiVAriateNormalDiag, P_r as a tfp.VonMisesFisher and P_a as a tfp.VonMises distribution. Here's the code snippet:

# helper function to calculate a positive scale factor
def get_scale(dim=None, name="scale"):
init_val = 1.0 if dim is None else tf.ones(dim)
return tfp.util.TransformedVariable(init_val, bijector=tfb.Softplus(), name=name)

# factor definitions
P_t = tfd.MultivariateNormalDiag(loc=tf.Variable(tf.zeros(3), name="mu"),
scale_diag=get_scale(dim=3, name="sigma"),
name="prob_t")

P_r = tfd.VonMisesFisher(mean_direction=tf.Variable([1.0, 0.0, 0.0], name="r0"),
concentration=get_scale(dim=3, name="kr"),
name="prob_r")

P_a = tfd.VonMises(loc=tf.Variable(0.0, name="a0"),
concentration=get_scale(name="ka"),
name="prob_a")

Now I need a joint distribution P_tot = P_t * P_r * P_a, which I intend to use as the components_distribution in a tfd.MixtureSameFamily distribution.

But, I can't seem to find a way to define this composite product distribution P_tot. I read the "Factorial Mixture" notebook, but didn't help. Not sure if (and how) tfd.Indepndent can be used here to define P_tot as the product written above.

Any pointers would be awesome!

Thanks,
Tanmoy

### Brian Patton 🚀

Oct 20, 2021, 11:23:17 AM10/20/21
to Tanmoy Sanyal, TensorFlow Probability
I think you're probably looking for tfd.Blockwise, which stacks multiple independent distributions together into a vector valued event.

Brian Patton | Software Engineer | b...@google.com

--
You received this message because you are subscribed to the Google Groups "TensorFlow Probability" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tfprobabilit...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tfprobability/55482923-a49a-4eeb-bfa6-a675e5e1a63en%40tensorflow.org.