# Apply multivariate normal log-likelihood find the posterior distribution

**URL:** <https://discourse.pymc.io/t/apply-multivariate-normal-log-likelihood-find-the-posterior-distribution/2586>\
**Category:** Questions\
**Created:** [January 25, 2019, 1:09pm UTC](https://discourse.pymc.io/t/apply-multivariate-normal-log-likelihood-find-the-posterior-distribution/2586 "2019-01-25T13:09:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hoaithanhbk\_281113](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/hoaithanhbk_281113/32/4603_2.png) [@Hoaithanhbk\_281113](https://discourse.pymc.io/u/Hoaithanhbk_281113)\
**Post date:** [January 25, 2019, 1:09pm UTC](https://discourse.pymc.io/t/apply-multivariate-normal-log-likelihood-find-the-posterior-distribution/2586/1 "2019-01-25T13:09:16Z")

</div>

Dear everyone,  
I have a question about using multivariate log-likelihood find the posterior.  
I have 3 input parameter: each input has 20 value.

nodes1 = np.array([0.05675, 0.05934, 0.05633, 0.0557 , 0.05702, 0.06401, 0.06322, 0.06571, 0.06099, 0.05832, 0.06196, 0.06463, 0.05507, 0.06351, 0.06287, 0.06122, 0.05407, 0.05985, 0.05774,0.06015])  
nodes2 = np.array([0.9486, 0.9095, 0.9856, 0.9318, 1.0477, 1.0489,1.0663, 0.9184, 0.9646, 1.0345, 1.0168, 1.0565, 0.9727, 0.9907, 0.9277, 0.9548, 1.0933, 1.0751,1.0026, 1.0231])  
nodes3 = np.array([51.813, 54.279, 52.659, 51.197 , 46.629, 49.791, 48.581, 54.799, 46.413, 47.078, 52.367, 48.204, 50.389, 45.402, 47.893, 50.796 , 49.332, 53.323, 53.713, 45.757])

I perform the experiment for each group of 3 corresponding input values : example (node1\_1,node2\_1,node3\_1) have a output value (0.0204232).  
I repeated the experiment with 20 times. I have the 20 corresponding output values.  
evals = np.array([0.0204232,0.0205054,0.0204971,0.0204463,0.0206686,0.0206678,0.0206883,0.0204627,0.020426,0.0206532,0.0206322,0.020677,0.0204431,0.0205319,0.0204508,0.0204115,0.020721,0.0206988,0.0206179,0.0206418])

Now, I want to use the multivariate normal log-likelihood to consider posterior distribution P(node1, node2,node3| evals). How to find the posterior distribution? If it is not enough condition to find it what do things need to find the posterior distribution?  
please get me your recommendation.  
thank you.

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [January 25, 2019, 4:23pm UTC](https://discourse.pymc.io/t/apply-multivariate-normal-log-likelihood-find-the-posterior-distribution/2586/2 "2019-01-25T16:23:29Z")

</div>

> [@Hoaithanhbk\_281113](#):
>
> I perform the experiment for each group of 3 corresponding input values : example (node1\_1,node2\_1,node3\_1) have a output value (0.0204232).

What is the function `example` here? Is it a linear function or something?

---

<div class="post-metadata">

**Author:** ![Hoaithanhbk\_281113](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/hoaithanhbk_281113/32/4603_2.png) [@Hoaithanhbk\_281113](https://discourse.pymc.io/u/Hoaithanhbk_281113)\
**Post date:** [January 25, 2019, 4:38pm UTC](https://discourse.pymc.io/t/apply-multivariate-normal-log-likelihood-find-the-posterior-distribution/2586/3 "2019-01-25T16:38:54Z")

</div>

It was just got the output from a experiment. Can not consider linear or not.

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [January 25, 2019, 8:21pm UTC](https://discourse.pymc.io/t/apply-multivariate-normal-log-likelihood-find-the-posterior-distribution/2586/4 "2019-01-25T20:21:42Z")

</div>

So in a way in an experiment you observed (node1\_1,node2\_1,node3\_1) _and_ output value right?

---

<div class="post-metadata">

**Author:** ![Hoaithanhbk\_281113](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/hoaithanhbk_281113/32/4603_2.png) [@Hoaithanhbk\_281113](https://discourse.pymc.io/u/Hoaithanhbk_281113)\
**Post date:** [January 25, 2019, 8:42pm UTC](https://discourse.pymc.io/t/apply-multivariate-normal-log-likelihood-find-the-posterior-distribution/2586/5 "2019-01-25T20:42:10Z")

</div>

I have the values group of parameters (node1\_i,node2\_i,node3\_i) i is from 1 to 20. I have the corresponding output values.

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [January 28, 2019, 8:58am UTC](https://discourse.pymc.io/t/apply-multivariate-normal-log-likelihood-find-the-posterior-distribution/2586/6 "2019-01-28T08:58:46Z")

</div>

Right, so IIUC in a way you are interested in the function that maps the values group of parameters (node1\_i,node2\_i,node3\_i) to the ouput value ouput\_i right? I would start with a linear regression, something like: `y = pm.Normal('observed', tt.dot(np.asarray([node1, node2, node3]), beta), sd=sigma, observed=output)`, with `beta` and `sigma` as the free parameters.

---

<div class="post-metadata">

**Author:** ![Hoaithanhbk\_281113](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/hoaithanhbk_281113/32/4603_2.png) [@Hoaithanhbk\_281113](https://discourse.pymc.io/u/Hoaithanhbk_281113)\
**Post date:** [January 28, 2019, 10:28am UTC](https://discourse.pymc.io/t/apply-multivariate-normal-log-likelihood-find-the-posterior-distribution/2586/7 "2019-01-28T10:28:16Z")

</div>

maybe don’t have the solution for my problem. So now I assume that the node 1, node 2, node 3 have uniform distributions. they are **the linear regression** with output value. How to apply multivariate normal log-likelihood to find the posterior distribution?  
detail :  
nodes1: uniform distribution (0.054,0.066),  
nodes2: uniform distribution (0.9,1.1)  
nodes3: unifrom distribution (45,55)  
I use the chaospy which is package to frist generation to have 20 input values.

nodes1 = np.array([0.05675, 0.05934, 0.05633, 0.0557 , 0.05702, 0.06401, 0.06322, 0.06571, 0.06099, 0.05832, 0.06196, 0.06463, 0.05507, 0.06351, 0.06287, 0.06122, 0.05407, 0.05985, 0.05774,0.06015])  
nodes2 = np.array([0.9486, 0.9095, 0.9856, 0.9318, 1.0477, 1.0489,1.0663, 0.9184, 0.9646, 1.0345, 1.0168, 1.0565, 0.9727, 0.9907, 0.9277, 0.9548, 1.0933, 1.0751,1.0026, 1.0231])  
nodes3 = np.array([51.813, 54.279, 52.659, 51.197 , 46.629, 49.791, 48.581, 54.799, 46.413, 47.078, 52.367, 48.204, 50.389, 45.402, 47.893, 50.796 , 49.332, 53.323, 53.713, 45.757])

from the input I have 20 output values:  
evals=np.array([0.0204232,0.0205054,0.0204971,0.0204463,0.0206686,0.0206678,0.0206883,0.0204627,0.020426,0.0206532,0.0206322,0.020677,0.0204431,0.0205319,0.0204508,0.0204115,0.020721,0.0206988,0.0206179,0.0206418])

The main problem want to use the multivariate normal log-likelihood find the parameter posterior distribution (node1,node2,node3). (now assume that it is the linear regression)  
please help me. Thanks you

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [January 28, 2019, 11:21am UTC](https://discourse.pymc.io/t/apply-multivariate-normal-log-likelihood-find-the-posterior-distribution/2586/8 "2019-01-28T11:21:38Z")

</div>

I think you _really_ need to be more specific of what is the mapping between your input (in this case node1, node2, node3) and your output (in this case evals), otherwise we are just talking in circle. Do you use chaospy that takes the 20\*3 input values and gives you 20 output values? And you want to infer the posterior distribution of the 3 input parameters now given the 20 observed (output values)?

---

<div class="post-metadata">

**Author:** ![Hoaithanhbk\_281113](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/hoaithanhbk_281113/32/4603_2.png) [@Hoaithanhbk\_281113](https://discourse.pymc.io/u/Hoaithanhbk_281113)\
**Post date:** [January 28, 2019, 12:48pm UTC](https://discourse.pymc.io/t/apply-multivariate-normal-log-likelihood-find-the-posterior-distribution/2586/9 "2019-01-28T12:48:24Z")

</div>

I can use the chaospy to samples 10000 output values. but can not use chaospy that take 20\*3 input.

---

<div class="post-metadata">

**Author:** ![Hoaithanhbk\_281113](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/hoaithanhbk_281113/32/4603_2.png) [@Hoaithanhbk\_281113](https://discourse.pymc.io/u/Hoaithanhbk_281113)\
**Post date:** [February 8, 2019, 9:37am UTC](https://discourse.pymc.io/t/apply-multivariate-normal-log-likelihood-find-the-posterior-distribution/2586/10 "2019-02-08T09:37:36Z")

</div>

Hi you, I have just estimate the function between (node1,node2,node3) and output.  
this is the function:  
output = -1.2422069376608758q0^2+0.010979502286122458q0q1+0.005065108695132867q1^2-0.0003998832861218647q0q2+0.16015398278991752q0-0.00013362145005939259q1q2+2.0112165363058473e-06q2^2-0.0020280971401678734q1-4.0276945348026916e-05q2+0.01657469140501759

with (node1 is q0, node2 is q1, node3 is q2)  
how to find the posterior distribution of the each parameter (node1, node2,node3)?  
thanks you

---

<div class="post-metadata">

**Author:** ![lucianopaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/lucianopaz/32/2186_2.png) [@lucianopaz](https://discourse.pymc.io/u/lucianopaz)\
**Post date:** [February 8, 2019, 5:36pm UTC](https://discourse.pymc.io/t/apply-multivariate-normal-log-likelihood-find-the-posterior-distribution/2586/11 "2019-02-08T17:36:59Z")

</div>

Is this something like what you need?

```python
a = -1.2422069376608758
b = 0.010979502286122458
c = 0.005065108695132867
d = 0.0003998832861218647
e = 0.16015398278991752
f = 0.00013362145005939259
g = 2.0112165363058473e-06
h = 0.0020280971401678734
i = 4.0276945348026916e-05
j = 0.01657469140501759

with pm.Model():
    q0 = pm.Uniform('nodes 1', 0.054, 0.066)
    q1 = pm.Uniform('nodes2', 0.9, 1.1)
    q2 = pm.Uniform('nodes3', 45, 55)
    mu = a * q0 **2 + b * q0 * q1+ c * q1** 2- d * q0 * q2+ e * q0 - f * q1 * q2+ g * q2**2 - h * q1 - i * q2 + j
    pm.Normal('observed', mu, 0.1, observed=observed)
    trace = pm.sample()
    pm.traceplot(trace)

```
