# **Direct sampling and Gibbs sampler**


```python
#joblib
import pandas as pd
import numpy as np
import random
import matplotlib.pyplot as plt
from tqdm import tqdm
```

**Direct sampling**

- Let´s say we have the following regression model:
    \begin{align}
    y_{i} = \beta x_{i} + u_{i},{\ \ u}_{{i\ }}\sim\ N\ (0,\ \sigma^{2})
    \end{align}
- with $\beta\sim\ N\left( \beta_{0},\ \tau^{2} \right)$ prior distribution. how can we get posterior mean and equal-tail-probability credible set for $|\beta|$?

- We know that follows a normal distrubution with the following form: 
\begin{align}
\beta|Y,X\ \sim\ N\ (\frac{\frac{1}{\sigma^{2}}\ \sum_{i = 1}^{N}{y_{i}x_{i} + \frac{1}{\tau^{2}}\ \beta_{0}}}{\frac{1}{\sigma^{2}}\ \sum_{i = 1}^{N}{x_{i}^{2} + \frac{1}{\tau^{2}}}} ,\frac{1}{\frac{1}{\sigma^{2}}\ \sum_{i = 1}^{N}{x_{i}^{2} + \frac{1}{\tau^{2}}}})
\end{align}
-Lets asume $\tau=100$, $\sigma^{2}$=1, $\beta_{0}$=0, $\beta$=-1 and N=200

- The first thing we need to do is simulate data of $y_{i}$ and $x_{i}$. To ensure your results are replicated define a random state seed


```python
rng = np.random.RandomState(2088888)
```

- Next, use numpy to simulate $x_{i}$ and $u_{i}$


```python
X=rng.normal(0, 1, size=(200, 1))
u=rng.normal(0, 1, size=(200, 1))
```

- To simulate $y_{i}$ use $x_{i}$, $u_{i}$ and $\beta$=-1


```python
B_real=-1
Y=((X)*B_real)+u
```

$\sum_{i = 1}^{N}$

- Let´s define:
Z= $\sum_{i = 1}^{N}$ $y_{i}$ $x_{i}$ and $\sum_{i = 1}^{N}$ \ \{x_{i}^{2}


```python
Z=Y.T.dot(X)
H=X.T.dot(X)
```

- Replacing $\tau$, $\sigma^{2}$ and $\beta_{0}$ we get:
\begin{align}
\beta|Y,X\ \sim\ N\ (\frac{\sum_{i = 1}^{N}{y_{i}x_{i} }}{\sum_{i = 1}^{N}{x_{i}^{2} + \frac{1}{10000}}} ,\frac{1}{\sum_{i = 1}^{N}{x_{i}^{2} + \frac{1}{10000}}})
\end{align}
-With this expresion we can simulate $\beta$


```python
mu=(Z)/(H+(1/10000))
sigma=(1)/(H+(1/10000))
```


```python
B=rng.normal(mu, sigma, size=(1000, 1))
```


```python
B.mean()
```




    -1.0319834982208982




```python
abs(B).mean()
```




    1.0319834982208982



- As we can see, the estimated values of $|\beta|$ and $\beta$ are realy close to the expected values


```python
fig, ax = plt.subplots()
kwargs = dict(histtype=u'step', alpha=0.3,  bins=40)
ax.hist(B, **kwargs)


##fig.savefig("histogramas.png")
```

- How to get the 90\% equal-tail-probability interval?


```python
np.quantile(B, 0.05)
```




    -1.0394009533421218




```python
np.quantile(B, 0.95)
```




    -1.0245718340759258




```python
NS=[100,1000,10000,100000,1000000,10000000]
error=[]
X=rng.normal(0, 1, size=(100, 1))
u=rng.normal(0, 1, size=(100, 1))
B_real=-1
Y=((X)*B_real)+u
Z=Y.T.dot(X)
H=X.T.dot(X)
mu=(Z)/(H+(1/10000))
sigma=(1)/(H+(1/10000))
for i in tqdm(NS):
    B=rng.normal(mu, sigma, size=(int(i), 1))
    er=(np.var(B))
    error.append(e)
    
    
```

    100%|██████████| 6/6 [00:00<00:00, 12.94it/s]



```python
data=pd.DataFrame({'N':NS,'Error':error})
```


```python
data
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>N</th>
      <th>Error</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>100</td>
      <td>[[[0.6747704158906617], [1.754946011980568], [...</td>
    </tr>
    <tr>
      <th>1</th>
      <td>1000</td>
      <td>[[[0.6747704158906617], [1.754946011980568], [...</td>
    </tr>
    <tr>
      <th>2</th>
      <td>10000</td>
      <td>[[[0.6747704158906617], [1.754946011980568], [...</td>
    </tr>
    <tr>
      <th>3</th>
      <td>100000</td>
      <td>[[[0.6747704158906617], [1.754946011980568], [...</td>
    </tr>
    <tr>
      <th>4</th>
      <td>1000000</td>
      <td>[[[0.6747704158906617], [1.754946011980568], [...</td>
    </tr>
    <tr>
      <th>5</th>
      <td>10000000</td>
      <td>[[[0.6747704158906617], [1.754946011980568], [...</td>
    </tr>
  </tbody>
</table>
</div>



# Gibbs Sampler


```python
rng = np.random.RandomState(2083)
```


```python
X=rng.normal(0, 1, size=(100, 1))
u=rng.normal(0, 1, size=(100, 1))
B_real=-1
Y=((X)*B_real)+u
```


```python
fig, ax = plt.subplots()
ax.scatter(X,Y, c="g", alpha=0.5, marker=r'$\clubsuit$',
            label="Luck") 
ax.set(xlabel='X', ylabel='Y',
       )
ax.grid()

```


```python
b0=0
a=np.array([10])
b=np.array([20])
e=(Y-X*b0)**2
err=sum(e)
```


```python
def betan(sigma,y,x):
    s_x2 =X.T.dot(X)
    s_xy =Y.T.dot(X)
    w=(1/sigma)*s_x2 + 1
    w =1/w
    m=((1/sigma)*sum(s_xy))*w
    m= np.array([m])
    w = np.array([w])
    beta=rng.normal(m,w)
    return(beta)
```


```python
betas=[]
sigmas=[]
iss=[]
errores=[]
a_hat=a+(100/2)
for i in tqdm(range(1,10000)):
    iss.append(i)
    b_hat=(b+((1/2)*(err)))**-1
    sigma=(np.random.gamma(a_hat,b_hat))**-1
    sigmas.append(sigma)
    beta=betan(sigma,Y,X)
    betas.append(beta)
    e=(Y-X*beta)**2
    err=sum(e[0])
    errores.append(err)
```

    100%|██████████| 9999/9999 [00:01<00:00, 9127.60it/s]



```python
sigmas
```




    [array([1.72036496]),
     array([0.80701561]),
     array([1.07260655]),
     array([1.49958048]),
     array([1.35737701]),
     array([1.04539949]),
     array([1.05670326]),
     array([1.04625815]),
     array([1.25033067]),
     array([1.10056949]),
     array([1.14216154]),
     array([1.42339043]),
     array([1.15904972]),
     array([1.11367708]),
     array([1.16522577]),
     array([0.9916628]),
     array([1.10330534]),
     array([0.95643999]),
     array([1.10249686]),
     array([1.06797095]),
     array([1.36777608]),
     array([1.21580106]),
     array([1.1272341]),
     array([0.97388426]),
     array([0.99377065]),
     array([1.32439873]),
     array([1.2134125]),
     array([1.01225643]),
     array([0.96191934]),
     array([0.99388509]),
     array([0.94061475]),
     array([1.11375575]),
     array([1.14936869]),
     array([1.00505033]),
     array([1.11237765]),
     array([1.01713792]),
     array([1.05270148]),
     array([1.10638634]),
     array([1.1118846]),
     array([1.34489722]),
     array([1.18239799]),
     array([0.9879391]),
     array([1.04937029]),
     array([1.00289813]),
     array([1.19058577]),
     array([1.17600928]),
     array([1.13388039]),
     array([0.89294727]),
     array([1.00564253]),
     array([0.9554071]),
     array([1.09825488]),
     array([1.4479174]),
     array([1.15826623]),
     array([1.12896177]),
     array([1.19851426]),
     array([1.03171467]),
     array([1.35645479]),
     array([1.2160356]),
     array([1.34869027]),
     array([0.99302592]),
     array([1.01012823]),
     array([1.17633169]),
     array([0.9969785]),
     array([1.12500527]),
     array([1.0044463]),
     array([1.07058449]),
     array([1.41600507]),
     array([1.25124354]),
     array([1.03651649]),
     array([1.26144712]),
     array([1.24701425]),
     array([0.91589185]),
     array([1.28957595]),
     array([1.12989958]),
     array([1.08932107]),
     array([0.99581523]),
     array([1.06886315]),
     array([1.25415701]),
     array([1.32933746]),
     array([0.98918362]),
     array([0.86981723]),
     array([1.25339163]),
     array([0.78895798]),
     array([1.31946042]),
     array([1.05969035]),
     array([1.02615731]),
     array([0.77996491]),
     array([0.96818038]),
     array([1.14528206]),
     array([1.15187657]),
     array([1.39250842]),
     array([1.26278185]),
     array([1.06746236]),
     array([1.26259791]),
     array([1.14064691]),
     array([1.17752908]),
     array([1.28400003]),
     array([0.96482719]),
     array([1.28963483]),
     array([0.99613328]),
     array([1.50544679]),
     array([1.04857099]),
     array([0.90313341]),
     array([1.09933443]),
     array([1.14231916]),
     array([1.39981792]),
     array([1.23041742]),
     array([1.12483664]),
     array([1.42145589]),
     array([0.83508491]),
     array([1.29996483]),
     array([1.06522584]),
     array([1.17534133]),
     array([1.04851705]),
     array([1.00157686]),
     array([0.87122944]),
     array([1.0251992]),
     array([1.22029015]),
     array([0.90789504]),
     array([1.02606084]),
     array([1.04128071]),
     array([1.03464585]),
     array([1.12034006]),
     array([1.51416085]),
     array([1.06803705]),
     array([1.19408991]),
     array([0.95769964]),
     array([1.10548094]),
     array([0.95148792]),
     array([1.21163668]),
     array([1.18145969]),
     array([0.84475613]),
     array([1.10803747]),
     array([0.95514433]),
     array([1.31221988]),
     array([1.05907891]),
     array([0.89085463]),
     array([1.54322324]),
     array([0.98263083]),
     array([1.22174367]),
     array([0.99427148]),
     array([1.05920903]),
     array([1.24428153]),
     array([0.98865867]),
     array([0.99210236]),
     array([1.32731839]),
     array([1.10506228]),
     array([1.16852126]),
     array([1.32299323]),
     array([1.1307449]),
     array([1.30984103]),
     array([1.10559174]),
     array([1.00685393]),
     array([1.37524575]),
     array([1.33697895]),
     array([1.32874273]),
     array([1.48919253]),
     array([0.98365455]),
     array([0.83540749]),
     array([1.07802411]),
     array([1.10225552]),
     array([1.15312227]),
     array([1.09931334]),
     array([1.15449477]),
     array([1.03874846]),
     array([1.2391276]),
     array([1.07859161]),
     array([1.26860575]),
     array([1.02379946]),
     array([1.31112874]),
     array([1.02638383]),
     array([1.25330338]),
     array([0.98060191]),
     array([1.49891537]),
     array([1.10803536]),
     array([1.11673858]),
     array([0.98290463]),
     array([0.99165024]),
     array([0.95873278]),
     array([0.95393296]),
     array([1.14086988]),
     array([0.8832514]),
     array([1.13652279]),
     array([1.06338043]),
     array([1.16813228]),
     array([1.14207644]),
     array([1.03937894]),
     array([1.00335703]),
     array([1.26345728]),
     array([1.32231744]),
     array([1.2328331]),
     array([0.9192916]),
     array([1.10311254]),
     array([1.27864895]),
     array([0.99248007]),
     array([1.27845426]),
     array([1.15941023]),
     array([1.1535098]),
     array([1.05358636]),
     array([1.09036392]),
     array([0.95183432]),
     array([1.20546145]),
     array([1.11293562]),
     array([1.26240549]),
     array([1.17332285]),
     array([1.32788089]),
     array([1.09699982]),
     array([1.01761178]),
     array([1.1457253]),
     array([1.28314464]),
     array([1.44196999]),
     array([1.31810828]),
     array([0.93372573]),
     array([1.10066124]),
     array([1.1561479]),
     array([1.03044472]),
     array([1.10024183]),
     array([1.10239395]),
     array([1.43007084]),
     array([0.99356331]),
     array([1.27950388]),
     array([1.16330421]),
     array([1.09195105]),
     array([1.25888139]),
     array([1.05197518]),
     array([1.3259991]),
     array([0.89370361]),
     array([1.19989558]),
     array([1.17490402]),
     array([1.00248005]),
     array([1.07253706]),
     array([1.13035199]),
     array([1.40579095]),
     array([0.97547525]),
     array([1.00321526]),
     array([1.07300329]),
     array([1.07939468]),
     array([0.98052727]),
     array([0.95009462]),
     array([1.03365819]),
     array([1.12412506]),
     array([1.36382899]),
     array([1.22713611]),
     array([1.05572474]),
     array([1.14265216]),
     array([1.18036292]),
     array([1.1219162]),
     array([1.18016588]),
     array([1.05924815]),
     array([0.99031636]),
     array([0.967632]),
     array([1.09323209]),
     array([0.97629563]),
     array([1.20096257]),
     array([1.02935403]),
     array([1.22260443]),
     array([1.07148025]),
     array([1.04258608]),
     array([1.20319838]),
     array([0.82085364]),
     array([1.13753584]),
     array([1.11326901]),
     array([1.05062562]),
     array([1.09738473]),
     array([1.19847874]),
     array([0.94241483]),
     array([1.23812915]),
     array([1.12854059]),
     array([1.09017883]),
     array([1.30477985]),
     array([1.3120268]),
     array([1.04178603]),
     array([1.10394097]),
     array([0.9827014]),
     array([1.42988179]),
     array([1.01756947]),
     array([1.17600773]),
     array([0.99079444]),
     array([1.09908496]),
     array([1.34767494]),
     array([1.2221068]),
     array([1.14955096]),
     array([1.38335239]),
     array([1.29728112]),
     array([1.06360318]),
     array([1.1935365]),
     array([1.00635531]),
     array([1.08610722]),
     array([1.21153344]),
     array([1.06701332]),
     array([0.86398234]),
     array([0.9415822]),
     array([0.91704315]),
     array([0.92551138]),
     array([1.0854179]),
     array([0.9263984]),
     array([1.37480741]),
     array([1.33236697]),
     array([1.02993276]),
     array([1.42872551]),
     array([1.09177564]),
     array([1.18206134]),
     array([0.8873302]),
     array([0.9623032]),
     array([1.04760258]),
     array([1.20295049]),
     array([1.20911378]),
     array([1.14743061]),
     array([1.09129922]),
     array([0.93562512]),
     array([1.08127169]),
     array([1.21738107]),
     array([1.37905502]),
     array([1.33814474]),
     array([1.45385191]),
     array([1.48935294]),
     array([1.29780008]),
     array([0.98741904]),
     array([1.3650767]),
     array([1.20816437]),
     array([0.95652006]),
     array([1.1449674]),
     array([0.98945729]),
     array([1.23043825]),
     array([0.99955451]),
     array([1.17304557]),
     array([1.14440278]),
     array([0.87432868]),
     array([1.48553909]),
     array([1.11679672]),
     array([1.07230332]),
     array([1.24457917]),
     array([1.48936271]),
     array([0.9928689]),
     array([1.2161276]),
     array([1.15377147]),
     array([0.96041795]),
     array([1.29005808]),
     array([1.0943813]),
     array([1.19230899]),
     array([1.10627883]),
     array([0.90059415]),
     array([1.24089868]),
     array([1.15860191]),
     array([1.20345052]),
     array([0.90498358]),
     array([1.20666036]),
     array([1.04842459]),
     array([1.1037361]),
     array([1.11790157]),
     array([0.99688629]),
     array([1.03618182]),
     array([1.05380509]),
     array([1.37942894]),
     array([1.00208188]),
     array([0.88185819]),
     array([1.39007871]),
     array([1.12726604]),
     array([1.10890335]),
     array([0.88778853]),
     array([0.92640056]),
     array([1.27942798]),
     array([1.2142068]),
     array([1.04856012]),
     array([1.02418329]),
     array([1.51834008]),
     array([1.25113059]),
     array([1.08042263]),
     array([1.06913747]),
     array([1.45269716]),
     array([1.16922528]),
     array([1.05209484]),
     array([1.08918938]),
     array([1.28097274]),
     array([1.062971]),
     array([1.07570924]),
     array([1.3507307]),
     array([1.20818824]),
     array([1.05060429]),
     array([1.25113978]),
     array([1.10472557]),
     array([1.01666893]),
     array([1.00982365]),
     array([1.04761029]),
     array([1.08558329]),
     array([0.96771461]),
     array([1.13874134]),
     array([0.98435543]),
     array([1.29266815]),
     array([1.25026967]),
     array([1.22196037]),
     array([1.23104063]),
     array([1.15537352]),
     array([1.15021773]),
     array([1.20579697]),
     array([0.8719873]),
     array([1.14386146]),
     array([1.23598068]),
     array([1.24422809]),
     array([1.09674881]),
     array([1.22018422]),
     array([0.96601722]),
     array([1.50145796]),
     array([1.02356769]),
     array([1.17872349]),
     array([1.25712066]),
     array([1.13828836]),
     array([0.96759646]),
     array([1.12924406]),
     array([0.94149907]),
     array([0.95247977]),
     array([0.92597804]),
     array([1.05498826]),
     array([1.07363002]),
     array([1.37193452]),
     array([1.38851629]),
     array([1.02134692]),
     array([1.35688343]),
     array([1.02161171]),
     array([1.16370225]),
     array([1.14933021]),
     array([1.06995307]),
     array([1.16666266]),
     array([1.27261507]),
     array([1.13503333]),
     array([1.17465477]),
     array([1.04116325]),
     array([1.18815979]),
     array([1.06018519]),
     array([1.10203636]),
     array([1.04132247]),
     array([0.93324699]),
     array([1.15830322]),
     array([1.37024149]),
     array([0.98407417]),
     array([1.17143817]),
     array([1.28184586]),
     array([1.28530617]),
     array([1.03029263]),
     array([1.20033284]),
     array([1.14695994]),
     array([0.88536326]),
     array([0.98450021]),
     array([1.16629047]),
     array([1.27309608]),
     array([1.16985876]),
     array([1.16719068]),
     array([1.04180206]),
     array([1.12277445]),
     array([1.01980586]),
     array([1.18042625]),
     array([1.13464497]),
     array([1.27244637]),
     array([1.23365667]),
     array([1.41324542]),
     array([1.08460898]),
     array([1.12284237]),
     array([1.4290614]),
     array([1.09387249]),
     array([0.95904418]),
     array([1.20745665]),
     array([1.12796978]),
     array([1.09439285]),
     array([1.23153844]),
     array([1.03625383]),
     array([1.28924288]),
     array([0.95408305]),
     array([0.86975994]),
     array([1.29679106]),
     array([1.46930876]),
     array([1.00690404]),
     array([0.98714941]),
     array([1.05828786]),
     array([1.02816609]),
     array([0.93570168]),
     array([1.08891623]),
     array([1.27466227]),
     array([1.14702031]),
     array([1.20465529]),
     array([1.41870842]),
     array([1.27214852]),
     array([1.18720731]),
     array([1.07946914]),
     array([1.14364689]),
     array([1.17688695]),
     array([1.17487731]),
     array([1.1090341]),
     array([1.17633065]),
     array([1.16178005]),
     array([1.12001973]),
     array([1.45726793]),
     array([1.4998685]),
     array([0.98760732]),
     array([1.17326736]),
     array([0.94542343]),
     array([0.97734989]),
     array([1.12016624]),
     array([1.13248024]),
     array([1.08930032]),
     array([1.10397593]),
     array([1.15797442]),
     array([0.95182501]),
     array([1.24566484]),
     array([1.07993226]),
     array([0.86904261]),
     array([1.10666314]),
     array([1.29950379]),
     array([1.45147657]),
     array([1.19173636]),
     array([1.30357895]),
     array([0.98383694]),
     array([1.20518028]),
     array([1.29411703]),
     array([1.08705689]),
     array([1.32303601]),
     array([1.41465645]),
     array([1.03063058]),
     array([1.01847487]),
     array([1.0372013]),
     array([1.37011427]),
     array([0.99047299]),
     array([1.11535291]),
     array([1.25500233]),
     array([0.95834864]),
     array([1.15726732]),
     array([1.00379501]),
     array([1.20279071]),
     array([1.50108352]),
     array([1.15413558]),
     array([1.19232102]),
     array([0.94730582]),
     array([1.02448244]),
     array([1.18751472]),
     array([1.19782716]),
     array([0.98417332]),
     array([0.83614611]),
     array([0.93854807]),
     array([0.93984404]),
     array([1.22407578]),
     array([1.04287073]),
     array([1.007274]),
     array([1.23845877]),
     array([1.00885901]),
     array([0.98516618]),
     array([1.19657691]),
     array([1.19406322]),
     array([1.02806428]),
     array([1.23489539]),
     array([1.09751847]),
     array([1.23372766]),
     array([1.27528154]),
     array([1.14468607]),
     array([1.13785067]),
     array([0.99175396]),
     array([1.2732345]),
     array([1.00900914]),
     array([1.10048105]),
     array([0.89110239]),
     array([1.05840146]),
     array([1.07817969]),
     array([1.2182579]),
     array([0.90210107]),
     array([1.06359961]),
     array([1.10103111]),
     array([1.31033664]),
     array([1.44039848]),
     array([1.05226238]),
     array([1.1749312]),
     array([1.1446131]),
     array([1.02086415]),
     array([1.01236342]),
     array([0.95321558]),
     array([1.23171365]),
     array([1.12284781]),
     array([1.15180726]),
     array([1.24915785]),
     array([0.86138045]),
     array([1.10808093]),
     array([1.13624872]),
     array([0.92347229]),
     array([1.13136359]),
     array([1.01441066]),
     array([0.90575544]),
     array([1.06957431]),
     array([1.18355855]),
     array([1.06920656]),
     array([0.95456407]),
     array([1.14951523]),
     array([1.0320905]),
     array([1.27912697]),
     array([0.94603786]),
     array([0.92720719]),
     array([0.97698657]),
     array([0.96289961]),
     array([1.18280322]),
     array([0.82116149]),
     array([1.12204145]),
     array([1.17174245]),
     array([1.01923323]),
     array([1.27515451]),
     array([0.94663483]),
     array([1.04710217]),
     array([1.53670633]),
     array([1.47838645]),
     array([1.21486387]),
     array([1.3088677]),
     array([1.14774901]),
     array([1.07524139]),
     array([1.02988731]),
     array([1.17517983]),
     array([1.01117996]),
     array([1.10279162]),
     array([1.11911474]),
     array([1.24960883]),
     array([1.21530523]),
     array([1.18896248]),
     array([1.39129012]),
     array([0.97316629]),
     array([0.98034377]),
     array([1.24394143]),
     array([1.16391086]),
     array([1.17116036]),
     array([1.42484944]),
     array([1.37302486]),
     array([1.03607811]),
     array([1.14248884]),
     array([1.2712563]),
     array([1.14627933]),
     array([1.12390665]),
     array([1.09714656]),
     array([1.102957]),
     array([1.39963664]),
     array([1.14983001]),
     array([1.19314998]),
     array([1.44954222]),
     array([1.19889592]),
     array([1.16221452]),
     array([1.43471479]),
     array([0.92980865]),
     array([1.19641107]),
     array([1.49753065]),
     array([1.12322902]),
     array([1.10530747]),
     array([1.18442006]),
     array([1.06722585]),
     array([0.98982144]),
     array([1.07047088]),
     array([1.37095442]),
     array([1.03460773]),
     array([0.95119486]),
     array([1.04637503]),
     array([1.19441223]),
     array([1.01226835]),
     array([1.00868032]),
     array([1.08418238]),
     array([1.22363546]),
     array([0.94977924]),
     array([1.36204535]),
     array([1.3389134]),
     array([1.00573205]),
     array([1.13137148]),
     array([0.98819336]),
     array([1.38218074]),
     array([1.22778052]),
     array([1.14825995]),
     array([1.13402637]),
     array([1.16157524]),
     array([1.18916851]),
     array([1.04738954]),
     array([1.1676527]),
     array([1.05686218]),
     array([0.9705767]),
     array([1.12127743]),
     array([1.04197837]),
     array([0.98459965]),
     array([0.99169449]),
     array([1.21741705]),
     array([0.92886525]),
     array([1.1271329]),
     array([1.04433937]),
     array([1.20851291]),
     array([0.96849403]),
     array([1.10318121]),
     array([1.1602433]),
     array([1.1121802]),
     array([1.14885748]),
     array([1.19183325]),
     array([1.07576139]),
     array([1.41316785]),
     array([1.02603416]),
     array([1.03567483]),
     array([0.86325382]),
     array([1.42752306]),
     array([0.99766147]),
     array([1.18505464]),
     array([0.95556446]),
     array([1.22603366]),
     array([1.08254221]),
     array([1.09210065]),
     array([1.02006005]),
     array([1.16654684]),
     array([1.25343372]),
     array([1.02727443]),
     array([0.98302657]),
     array([1.08053853]),
     array([1.05087973]),
     array([1.40761524]),
     array([1.28867653]),
     array([0.96603873]),
     array([0.98812685]),
     array([1.1955966]),
     array([1.16750478]),
     array([0.9560709]),
     array([1.17002928]),
     array([1.10188657]),
     array([1.12319172]),
     array([0.97479771]),
     array([1.1332606]),
     array([1.33575736]),
     array([1.23602427]),
     array([1.09797409]),
     array([1.01146197]),
     array([0.91126516]),
     array([0.94630449]),
     array([0.92461665]),
     array([1.08502749]),
     array([1.17432298]),
     array([1.1229744]),
     array([1.13277428]),
     array([1.25242058]),
     array([1.11269598]),
     array([1.18667882]),
     array([0.767775]),
     array([1.06613439]),
     array([1.44234372]),
     array([1.18581329]),
     array([1.2366756]),
     array([1.16502331]),
     array([1.65337252]),
     array([0.98075916]),
     array([1.29682616]),
     array([1.21444886]),
     array([1.38862616]),
     array([1.68249729]),
     array([1.25780885]),
     array([1.23174387]),
     array([0.97928997]),
     array([1.17142897]),
     array([0.87069204]),
     array([1.1201931]),
     array([1.33538274]),
     array([1.17734389]),
     array([1.44477391]),
     array([1.34384324]),
     array([1.12640496]),
     array([1.36213899]),
     array([1.1325046]),
     array([1.16972126]),
     array([1.01827793]),
     array([1.28925807]),
     array([0.97388322]),
     array([1.23846594]),
     array([0.96783686]),
     array([1.15907569]),
     array([1.29193933]),
     array([1.02822106]),
     array([1.1065023]),
     array([1.05806668]),
     array([1.14542717]),
     array([1.20205285]),
     array([1.09709007]),
     array([1.06745805]),
     array([1.30273377]),
     array([0.94081941]),
     array([1.51625681]),
     array([0.81649019]),
     array([1.41478188]),
     array([1.32350065]),
     array([1.07464624]),
     array([1.16095038]),
     array([0.89485709]),
     array([1.25010615]),
     array([1.02930939]),
     array([1.01876398]),
     array([1.0637675]),
     array([0.93950511]),
     array([1.23984221]),
     array([1.33913643]),
     array([1.1732603]),
     array([0.84884568]),
     array([1.01653208]),
     array([1.15808134]),
     array([1.0010315]),
     array([1.21108608]),
     array([1.19858619]),
     array([1.33837966]),
     array([0.94529008]),
     array([0.99559162]),
     array([1.20881036]),
     array([1.38481828]),
     array([1.25160887]),
     array([1.26786633]),
     array([1.12718467]),
     array([1.16292636]),
     array([1.27472323]),
     array([0.99478177]),
     array([1.18813241]),
     array([1.24561429]),
     array([1.06790497]),
     array([1.11325078]),
     array([1.10738303]),
     array([1.24184529]),
     array([1.07826074]),
     array([1.05855985]),
     array([1.18137702]),
     array([1.31457241]),
     array([1.26789397]),
     array([0.99572349]),
     array([0.96955712]),
     array([1.36488074]),
     array([1.12392507]),
     array([1.28503589]),
     array([1.12750805]),
     array([1.04882192]),
     array([1.14494008]),
     array([1.23430537]),
     array([0.99195413]),
     array([0.97070404]),
     array([1.19553769]),
     array([1.14882887]),
     array([0.83335946]),
     array([1.07365787]),
     array([1.05682321]),
     array([1.34267165]),
     array([1.12484092]),
     array([1.26664807]),
     array([1.26113747]),
     array([0.97479445]),
     array([0.93801036]),
     array([0.97691996]),
     array([1.16869048]),
     array([1.09125677]),
     array([1.08083036]),
     array([0.83048556]),
     array([1.10376757]),
     array([1.21224126]),
     array([1.04626475]),
     array([1.30179197]),
     array([1.06915527]),
     array([1.31260276]),
     array([1.05064733]),
     array([1.11960792]),
     array([1.30999094]),
     array([1.16534859]),
     array([0.76223998]),
     array([1.14681803]),
     array([1.43391362]),
     array([1.20170564]),
     array([1.08758028]),
     array([0.92951415]),
     array([1.13372317]),
     array([1.21120544]),
     array([0.91219532]),
     array([1.07729618]),
     array([1.29193653]),
     array([1.41218849]),
     array([1.05341554]),
     array([1.18014157]),
     array([1.08907431]),
     array([0.92914212]),
     array([1.18293264]),
     array([1.02475452]),
     array([1.15155587]),
     array([1.17144973]),
     array([1.54734025]),
     array([1.17831019]),
     array([1.13260645]),
     array([1.51303787]),
     array([1.14207514]),
     array([1.21381426]),
     array([1.07202268]),
     array([1.07464455]),
     array([1.1240553]),
     array([0.96118868]),
     array([1.11493695]),
     array([1.06676614]),
     array([1.36629187]),
     array([1.31653114]),
     array([1.06051092]),
     array([1.14955859]),
     array([1.08236884]),
     array([1.15764832]),
     array([1.0035414]),
     array([1.35157633]),
     array([1.04686368]),
     array([1.12657557]),
     array([0.76345751]),
     array([1.13139328]),
     array([1.2315244]),
     array([1.18207829]),
     array([1.02627802]),
     array([1.67985595]),
     array([1.09722499]),
     array([1.23597462]),
     array([1.1138924]),
     array([1.26326393]),
     array([1.32477867]),
     array([1.09753934]),
     array([1.32792589]),
     array([1.15014599]),
     array([1.28192139]),
     array([0.85962869]),
     array([1.06318473]),
     array([1.09286343]),
     array([0.96760509]),
     array([1.07944982]),
     array([1.02323719]),
     array([1.34293491]),
     array([1.28934558]),
     array([1.36188742]),
     array([1.2300171]),
     array([1.11349589]),
     array([1.20167369]),
     array([1.27525949]),
     array([1.00497042]),
     array([1.47399202]),
     array([1.14890652]),
     array([1.03419129]),
     array([1.19412113]),
     array([0.85472331]),
     array([1.07548403]),
     array([1.30064442]),
     array([1.47983774]),
     array([1.33060846]),
     array([1.14972672]),
     array([1.0853062]),
     array([1.09486753]),
     array([1.18674513]),
     array([1.01402023]),
     array([1.25243346]),
     array([0.98591831]),
     array([1.23478082]),
     array([0.97346049]),
     array([1.19204108]),
     array([1.20032251]),
     array([1.03500508]),
     array([1.14529286]),
     array([1.10916384]),
     array([0.94758934]),
     array([1.12243583]),
     array([1.11407481]),
     array([0.91313027]),
     array([1.39385337]),
     array([1.20066421]),
     array([1.02278782]),
     array([1.09899978]),
     array([1.22450938]),
     array([1.22040255]),
     array([0.8797686]),
     array([1.00816777]),
     array([0.89723916]),
     array([1.11874003]),
     array([1.03788324]),
     array([1.26309062]),
     array([1.14006135]),
     array([1.36109737]),
     array([1.21784725]),
     array([0.86838913]),
     array([1.19316398]),
     array([1.21293826]),
     array([1.12172267]),
     array([1.17174753]),
     array([1.29488283]),
     array([1.26748115]),
     array([1.14929796]),
     array([1.03422303]),
     array([1.24247125]),
     array([1.41581777]),
     array([1.07400957]),
     array([1.22956441]),
     array([0.98130226]),
     array([1.10720911]),
     array([1.02173318]),
     array([0.89959506]),
     array([1.24064446]),
     array([1.29335262]),
     array([1.19202272]),
     array([0.98652951]),
     array([1.08627895]),
     array([1.23032306]),
     array([1.23313581]),
     array([1.23898654]),
     array([0.96723191]),
     array([1.20048155]),
     array([1.12916055]),
     array([1.04923982]),
     array([1.11660915]),
     array([0.98020072]),
     array([1.13896366]),
     array([1.04241074]),
     ...]




```python
betass=[]
for i in tqdm(betas):
    betass.append(float(i))
```

    100%|██████████| 9999/9999 [00:00<00:00, 1670337.97it/s]



```python
sigmass=[]
for i in tqdm(sigmas):
    sigmass.append(float(i))
```

    100%|██████████| 9999/9999 [00:00<00:00, 1672469.52it/s]



```python
fig, ax = plt.subplots()
kwargs = dict(histtype=u'step', alpha=0.3,  bins=40)
ax.hist(sigmass, **kwargs)
```


```python
fig, ax = plt.subplots()
kwargs = dict(histtype=u'step', alpha=0.3,  bins=40)
ax.hist(betass, **kwargs)
```


```python
fig, ax = plt.subplots()
ax.scatter(iss,sigmass, c="g", alpha=0.5, marker=r'$\clubsuit$',
            label="Luck") 
ax.set(xlabel='i', ylabel='Sigma',
       )
ax.grid()

```


```python
fig, ax = plt.subplots()
ax.scatter(iss,betass, c="g", alpha=0.5, marker=r'$\clubsuit$',
            label="Luck") 
ax.set(xlabel='i', ylabel='Beta')
ax.grid()

```


```python

```

699920366156e508ca102d2cc570a41d6f7b51d2
ipynb
Jupyter Notebook
e-ta6_Direct_sampling_and_Gibbs_sampler/e-ta6_Direct_sampling_and_Gibbs_sampler.ipynb
Lorena-Rojas/e-TA
04c798fa4a65012175d0035ac593a7b812deece9
MIT
e-ta6_Direct_sampling_and_Gibbs_sampler/e-ta6_Direct_sampling_and_Gibbs_sampler.ipynb
Lorena-Rojas/e-TA
04c798fa4a65012175d0035ac593a7b812deece9
MIT
e-ta6_Direct_sampling_and_Gibbs_sampler/e-ta6_Direct_sampling_and_Gibbs_sampler.ipynb
Lorena-Rojas/e-TA
04c798fa4a65012175d0035ac593a7b812deece9
MIT
2021-08-18T22:58:57.000Z
2021-12-05T14:54:44.000Z
Qwen/Qwen-72B
1. YES
2. YES