forked from gabrielachirila/PMP-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex2_partial.py
25 lines (23 loc) · 933 Bytes
/
ex2_partial.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
import arviz as az
import pymc as pm
#1.
#generez 100 de timpi medii de asteptare folosind o distributie poissson
timpi_de_asteptare = stats.poisson.rvs(20.0, size=100)
for x in timpi_de_asteptare:
alfa = pm.Normal('alfa', mu=0, sigma=10)
beta = pm.Normal('beta', mu=0, sigma=1)
timpi_generati = pm.Deterministic('niu', x * beta + alfa)
#2.
with pm.Model() as model_regression:
timpi_de_asteptare = stats.poisson.rvs(20.0, size=100)
for x in timpi_de_asteptare:
alfa = pm.Normal('alfa', mu=0, sigma=10)
beta = pm.Normal('beta', mu=0, sigma=1)
eps = pm.HalfCauchy('eps', 5)
niu = pm.Deterministic('niu', x * beta + alfa)
idata = pm.sample(2000, tune=2000, return_inferencedata=True)
az.plot_trace(idata, var_names=['alfa', 'beta', 'eps'])
plt.show()