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










1















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?










share|improve this question




























    1















    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?










    share|improve this question


























      1












      1








      1








      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?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 21 at 18:23









      MPękalski

      2,14511729




      2,14511729










      asked Mar 21 at 16:46









      MozzieMozzie

      868




      868






















          1 Answer
          1






          active

          oldest

          votes


















          1














          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>>





          share|improve this answer























          • 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 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











          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
          );



          );













          draft saved

          draft discarded


















          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









          1














          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>>





          share|improve this answer























          • 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 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















          1














          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>>





          share|improve this answer























          • 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 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













          1












          1








          1







          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>>





          share|improve this answer













          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>>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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 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

















          • 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 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
















          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



















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해