Tensorflow mix two multivariate distribution The Next CEO of Stack OverflowHow to merge two dictionaries in a single expression?Convert two lists into a dictionary in PythonLimiting floats to two decimal pointsHow do I concatenate two lists in Python?Creating a multivariate distributed matrix in python?Tensorflow: how to save/restore a model?TensorFlow not found using piptensorflow conv1d kernel size dimensionality errortf.einsum with unknown shapeTensorflow Implement Multivariate Student T diagonal distribution
Why does the UK parliament need a vote on the political declaration?
How did the Bene Gesserit know how to make a Kwisatz Haderach?
How does the mv command work with external drives?
How are problems classified in Complexity Theory?
Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis
What happened in Rome, when the western empire "fell"?
How to make a variable always equal to the result of some calculations?
What does "Its cash flow is deeply negative" mean?
Why did we only see the N-1 starfighters in one film?
Should I tutor a student who I know has cheated on their homework?
Do I need to enable Dev Hub in my PROD Org?
Unreliable Magic - Is it worth it?
Skipping indices in a product
Contours of a clandestine nature
On model categories where every object is bifibrant
If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?
Make solar eclipses exceedingly rare, but still have new moons
Which tube will fit a -(700 x 25c) wheel?
Extending anchors in TikZ
Workaholic Formal/Informal
How to count occurrences of text in a file?
Why do airplanes bank sharply to the right after air-to-air refueling?
How should I support this large drywall patch?
If the heap is initialized for security, then why is the stack uninitialized?
Tensorflow mix two multivariate distribution
The Next CEO of Stack OverflowHow to merge two dictionaries in a single expression?Convert two lists into a dictionary in PythonLimiting floats to two decimal pointsHow do I concatenate two lists in Python?Creating a multivariate distributed matrix in python?Tensorflow: how to save/restore a model?TensorFlow not found using piptensorflow conv1d kernel size dimensionality errortf.einsum with unknown shapeTensorflow Implement Multivariate Student T diagonal distribution
I would like to mix two multivariate distribution in tensorflow. For example:
import tensorflow_probability as tfp
import tensorflow as tf
import numpy as np
tfd = tfp.distributions
#mean,var,pi have the same shape(3,4).
mean = tf.convert_to_tensor(np.arange(12.0).reshape(3,4))
var = mean
dist = tfd.Normal(loc=mean,scale=var)
pi = tf.ones_like(mean)
mix = tfd.Mixture(cat = tfd.Categorical(probs=[pi,1-pi]),components=[dist,dist])
However, it got the error as follows:
ValueError: Dimensions 2 and 3 are not compatible
ValueError: Shapes (2, 3) and (3, 4) are not compatible
Can I mix two multivariate distribution in tensorflow?
python tensorflow tensorflow-probability
add a comment |
I would like to mix two multivariate distribution in tensorflow. For example:
import tensorflow_probability as tfp
import tensorflow as tf
import numpy as np
tfd = tfp.distributions
#mean,var,pi have the same shape(3,4).
mean = tf.convert_to_tensor(np.arange(12.0).reshape(3,4))
var = mean
dist = tfd.Normal(loc=mean,scale=var)
pi = tf.ones_like(mean)
mix = tfd.Mixture(cat = tfd.Categorical(probs=[pi,1-pi]),components=[dist,dist])
However, it got the error as follows:
ValueError: Dimensions 2 and 3 are not compatible
ValueError: Shapes (2, 3) and (3, 4) are not compatible
Can I mix two multivariate distribution in tensorflow?
python tensorflow tensorflow-probability
add a comment |
I would like to mix two multivariate distribution in tensorflow. For example:
import tensorflow_probability as tfp
import tensorflow as tf
import numpy as np
tfd = tfp.distributions
#mean,var,pi have the same shape(3,4).
mean = tf.convert_to_tensor(np.arange(12.0).reshape(3,4))
var = mean
dist = tfd.Normal(loc=mean,scale=var)
pi = tf.ones_like(mean)
mix = tfd.Mixture(cat = tfd.Categorical(probs=[pi,1-pi]),components=[dist,dist])
However, it got the error as follows:
ValueError: Dimensions 2 and 3 are not compatible
ValueError: Shapes (2, 3) and (3, 4) are not compatible
Can I mix two multivariate distribution in tensorflow?
python tensorflow tensorflow-probability
I would like to mix two multivariate distribution in tensorflow. For example:
import tensorflow_probability as tfp
import tensorflow as tf
import numpy as np
tfd = tfp.distributions
#mean,var,pi have the same shape(3,4).
mean = tf.convert_to_tensor(np.arange(12.0).reshape(3,4))
var = mean
dist = tfd.Normal(loc=mean,scale=var)
pi = tf.ones_like(mean)
mix = tfd.Mixture(cat = tfd.Categorical(probs=[pi,1-pi]),components=[dist,dist])
However, it got the error as follows:
ValueError: Dimensions 2 and 3 are not compatible
ValueError: Shapes (2, 3) and (3, 4) are not compatible
Can I mix two multivariate distribution in tensorflow?
python tensorflow tensorflow-probability
python tensorflow tensorflow-probability
edited Mar 21 at 18:23
MPękalski
2,14511729
2,14511729
asked Mar 21 at 16:46
MozzieMozzie
868
868
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Try if this solves your issue
import numpy as np
import tensorflow as tf
import tensorflow_probability as tfp
tfd = tfp.distributions
#mean,var,pi have the same shape(3,4).
mean = tf.convert_to_tensor(np.arange(12.0).reshape(3,4))
var = mean
dist = tfd.Normal(loc=-1., scale=0.1)
pi = tf.transpose(tf.ones_like(mean))
mix = tfd.Mixture(cat = tfd.Categorical(probs=[pi/3,
pi/3,
pi/3]),
components=[tfd.Normal(loc=mean,scale=var),
tfd.Normal(loc=mean,scale=var),
tfd.Normal(loc=mean,scale=var)]
)
mix.event_shape_tensor
output
<bound method Distribution.event_shape_tensor of <tfp.distributions.Mixture 'Mixture_11/' batch_shape=(3, 4) event_shape=() dtype=float64>>
Thanks for your help. It seems that it does not work if the components contain only two distributions. I'm not sure why it happens.mix = tfd.Mixture(cat = tfd.Categorical(probs=[pi/2,pi/2]),components=[dist,dist]). Thanks anyway.
– Mozzie
Mar 22 at 11:20
I think it might be because your mean/var are not square matrices.
– MPękalski
Mar 22 at 12:55
I think you are right. I found another solution for this. Instead of assigning the probability topi #shape(3,4), I assign it topi #shape(3,4,2). That means each element of the pi is a probability list eg.pi[0][0] = [0.5,0.5]. That works. Thanks a lot.
– Mozzie
Mar 22 at 13:36
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55285407%2ftensorflow-mix-two-multivariate-distribution%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try if this solves your issue
import numpy as np
import tensorflow as tf
import tensorflow_probability as tfp
tfd = tfp.distributions
#mean,var,pi have the same shape(3,4).
mean = tf.convert_to_tensor(np.arange(12.0).reshape(3,4))
var = mean
dist = tfd.Normal(loc=-1., scale=0.1)
pi = tf.transpose(tf.ones_like(mean))
mix = tfd.Mixture(cat = tfd.Categorical(probs=[pi/3,
pi/3,
pi/3]),
components=[tfd.Normal(loc=mean,scale=var),
tfd.Normal(loc=mean,scale=var),
tfd.Normal(loc=mean,scale=var)]
)
mix.event_shape_tensor
output
<bound method Distribution.event_shape_tensor of <tfp.distributions.Mixture 'Mixture_11/' batch_shape=(3, 4) event_shape=() dtype=float64>>
Thanks for your help. It seems that it does not work if the components contain only two distributions. I'm not sure why it happens.mix = tfd.Mixture(cat = tfd.Categorical(probs=[pi/2,pi/2]),components=[dist,dist]). Thanks anyway.
– Mozzie
Mar 22 at 11:20
I think it might be because your mean/var are not square matrices.
– MPękalski
Mar 22 at 12:55
I think you are right. I found another solution for this. Instead of assigning the probability topi #shape(3,4), I assign it topi #shape(3,4,2). That means each element of the pi is a probability list eg.pi[0][0] = [0.5,0.5]. That works. Thanks a lot.
– Mozzie
Mar 22 at 13:36
add a comment |
Try if this solves your issue
import numpy as np
import tensorflow as tf
import tensorflow_probability as tfp
tfd = tfp.distributions
#mean,var,pi have the same shape(3,4).
mean = tf.convert_to_tensor(np.arange(12.0).reshape(3,4))
var = mean
dist = tfd.Normal(loc=-1., scale=0.1)
pi = tf.transpose(tf.ones_like(mean))
mix = tfd.Mixture(cat = tfd.Categorical(probs=[pi/3,
pi/3,
pi/3]),
components=[tfd.Normal(loc=mean,scale=var),
tfd.Normal(loc=mean,scale=var),
tfd.Normal(loc=mean,scale=var)]
)
mix.event_shape_tensor
output
<bound method Distribution.event_shape_tensor of <tfp.distributions.Mixture 'Mixture_11/' batch_shape=(3, 4) event_shape=() dtype=float64>>
Thanks for your help. It seems that it does not work if the components contain only two distributions. I'm not sure why it happens.mix = tfd.Mixture(cat = tfd.Categorical(probs=[pi/2,pi/2]),components=[dist,dist]). Thanks anyway.
– Mozzie
Mar 22 at 11:20
I think it might be because your mean/var are not square matrices.
– MPękalski
Mar 22 at 12:55
I think you are right. I found another solution for this. Instead of assigning the probability topi #shape(3,4), I assign it topi #shape(3,4,2). That means each element of the pi is a probability list eg.pi[0][0] = [0.5,0.5]. That works. Thanks a lot.
– Mozzie
Mar 22 at 13:36
add a comment |
Try if this solves your issue
import numpy as np
import tensorflow as tf
import tensorflow_probability as tfp
tfd = tfp.distributions
#mean,var,pi have the same shape(3,4).
mean = tf.convert_to_tensor(np.arange(12.0).reshape(3,4))
var = mean
dist = tfd.Normal(loc=-1., scale=0.1)
pi = tf.transpose(tf.ones_like(mean))
mix = tfd.Mixture(cat = tfd.Categorical(probs=[pi/3,
pi/3,
pi/3]),
components=[tfd.Normal(loc=mean,scale=var),
tfd.Normal(loc=mean,scale=var),
tfd.Normal(loc=mean,scale=var)]
)
mix.event_shape_tensor
output
<bound method Distribution.event_shape_tensor of <tfp.distributions.Mixture 'Mixture_11/' batch_shape=(3, 4) event_shape=() dtype=float64>>
Try if this solves your issue
import numpy as np
import tensorflow as tf
import tensorflow_probability as tfp
tfd = tfp.distributions
#mean,var,pi have the same shape(3,4).
mean = tf.convert_to_tensor(np.arange(12.0).reshape(3,4))
var = mean
dist = tfd.Normal(loc=-1., scale=0.1)
pi = tf.transpose(tf.ones_like(mean))
mix = tfd.Mixture(cat = tfd.Categorical(probs=[pi/3,
pi/3,
pi/3]),
components=[tfd.Normal(loc=mean,scale=var),
tfd.Normal(loc=mean,scale=var),
tfd.Normal(loc=mean,scale=var)]
)
mix.event_shape_tensor
output
<bound method Distribution.event_shape_tensor of <tfp.distributions.Mixture 'Mixture_11/' batch_shape=(3, 4) event_shape=() dtype=float64>>
answered Mar 21 at 18:56
MPękalskiMPękalski
2,14511729
2,14511729
Thanks for your help. It seems that it does not work if the components contain only two distributions. I'm not sure why it happens.mix = tfd.Mixture(cat = tfd.Categorical(probs=[pi/2,pi/2]),components=[dist,dist]). Thanks anyway.
– Mozzie
Mar 22 at 11:20
I think it might be because your mean/var are not square matrices.
– MPękalski
Mar 22 at 12:55
I think you are right. I found another solution for this. Instead of assigning the probability topi #shape(3,4), I assign it topi #shape(3,4,2). That means each element of the pi is a probability list eg.pi[0][0] = [0.5,0.5]. That works. Thanks a lot.
– Mozzie
Mar 22 at 13:36
add a comment |
Thanks for your help. It seems that it does not work if the components contain only two distributions. I'm not sure why it happens.mix = tfd.Mixture(cat = tfd.Categorical(probs=[pi/2,pi/2]),components=[dist,dist]). Thanks anyway.
– Mozzie
Mar 22 at 11:20
I think it might be because your mean/var are not square matrices.
– MPękalski
Mar 22 at 12:55
I think you are right. I found another solution for this. Instead of assigning the probability topi #shape(3,4), I assign it topi #shape(3,4,2). That means each element of the pi is a probability list eg.pi[0][0] = [0.5,0.5]. That works. Thanks a lot.
– Mozzie
Mar 22 at 13:36
Thanks for your help. It seems that it does not work if the components contain only two distributions. I'm not sure why it happens.
mix = tfd.Mixture(cat = tfd.Categorical(probs=[pi/2,pi/2]),components=[dist,dist]). Thanks anyway.– Mozzie
Mar 22 at 11:20
Thanks for your help. It seems that it does not work if the components contain only two distributions. I'm not sure why it happens.
mix = tfd.Mixture(cat = tfd.Categorical(probs=[pi/2,pi/2]),components=[dist,dist]). Thanks anyway.– Mozzie
Mar 22 at 11:20
I think it might be because your mean/var are not square matrices.
– MPękalski
Mar 22 at 12:55
I think it might be because your mean/var are not square matrices.
– MPękalski
Mar 22 at 12:55
I think you are right. I found another solution for this. Instead of assigning the probability to
pi #shape(3,4), I assign it to pi #shape(3,4,2). That means each element of the pi is a probability list eg. pi[0][0] = [0.5,0.5]. That works. Thanks a lot.– Mozzie
Mar 22 at 13:36
I think you are right. I found another solution for this. Instead of assigning the probability to
pi #shape(3,4), I assign it to pi #shape(3,4,2). That means each element of the pi is a probability list eg. pi[0][0] = [0.5,0.5]. That works. Thanks a lot.– Mozzie
Mar 22 at 13:36
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55285407%2ftensorflow-mix-two-multivariate-distribution%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown