!pip install pymc3
Collecting pymc3
Downloading pymc3-3.11.2-py3-none-any.whl (869 kB)
|████████████████████████████████| 869 kB 20.9 MB/s
Requirement already satisfied: pandas>=0.24.0 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from pymc3) (1.2.4)
Collecting semver
Downloading semver-2.13.0-py2.py3-none-any.whl (12 kB)
Collecting theano-pymc==1.1.2
Downloading Theano-PyMC-1.1.2.tar.gz (1.8 MB)
|████████████████████████████████| 1.8 MB 45.0 MB/s
Requirement already satisfied: typing-extensions>=3.7.4 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from pymc3) (3.7.4.3)
Requirement already satisfied: dill in /shared-libs/python3.7/py/lib/python3.7/site-packages (from pymc3) (0.3.3)
Requirement already satisfied: scipy>=1.2.0 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from pymc3) (1.6.2)
Requirement already satisfied: cachetools>=4.2.1 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from pymc3) (4.2.1)
Collecting fastprogress>=0.2.0
Downloading fastprogress-1.0.0-py3-none-any.whl (12 kB)
Requirement already satisfied: numpy>=1.15.0 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from pymc3) (1.19.5)
Collecting patsy>=0.5.1
Downloading patsy-0.5.1-py2.py3-none-any.whl (231 kB)
|████████████████████████████████| 231 kB 78.5 MB/s
Collecting arviz>=0.11.0
Downloading arviz-0.11.2-py3-none-any.whl (1.6 MB)
|████████████████████████████████| 1.6 MB 56.4 MB/s
Requirement already satisfied: filelock in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from theano-pymc==1.1.2->pymc3) (3.0.12)
Collecting xarray>=0.16.1
Downloading xarray-0.17.0-py3-none-any.whl (759 kB)
|████████████████████████████████| 759 kB 44.3 MB/s
Collecting netcdf4
Downloading netCDF4-1.5.6-cp37-cp37m-manylinux2014_x86_64.whl (4.7 MB)
|████████████████████████████████| 4.7 MB 54.2 MB/s
Requirement already satisfied: packaging in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from arviz>=0.11.0->pymc3) (20.9)
Requirement already satisfied: setuptools>=38.4 in /root/venv/lib/python3.7/site-packages (from arviz>=0.11.0->pymc3) (54.1.2)
Requirement already satisfied: matplotlib>=3.0 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from arviz>=0.11.0->pymc3) (3.4.1)
Requirement already satisfied: pillow>=6.2.0 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from matplotlib>=3.0->arviz>=0.11.0->pymc3) (8.2.0)
Requirement already satisfied: cycler>=0.10 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from matplotlib>=3.0->arviz>=0.11.0->pymc3) (0.10.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from matplotlib>=3.0->arviz>=0.11.0->pymc3) (1.3.1)
Requirement already satisfied: python-dateutil>=2.7 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from matplotlib>=3.0->arviz>=0.11.0->pymc3) (2.8.1)
Requirement already satisfied: pyparsing>=2.2.1 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from matplotlib>=3.0->arviz>=0.11.0->pymc3) (2.4.7)
Requirement already satisfied: six in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from cycler>=0.10->matplotlib>=3.0->arviz>=0.11.0->pymc3) (1.15.0)
Requirement already satisfied: pytz>=2017.3 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from pandas>=0.24.0->pymc3) (2021.1)
Collecting cftime
Downloading cftime-1.4.1-cp37-cp37m-manylinux2014_x86_64.whl (313 kB)
|████████████████████████████████| 313 kB 73.8 MB/s
Building wheels for collected packages: theano-pymc
Building wheel for theano-pymc (setup.py) ... done
Created wheel for theano-pymc: filename=Theano_PyMC-1.1.2-py3-none-any.whl size=1529946 sha256=0d8c28eda5fb5b87ed5589157f5a0baa7f325cb8e101acc4e3488e87614b1213
Stored in directory: /root/.cache/pip/wheels/f3/af/8c/5dd7553522d74c52a7813806fc7ee1a9caa20a3f7c8fd850d5
Successfully built theano-pymc
Installing collected packages: cftime, xarray, netcdf4, theano-pymc, semver, patsy, fastprogress, arviz, pymc3
Successfully installed arviz-0.11.2 cftime-1.4.1 fastprogress-1.0.0 netcdf4-1.5.6 patsy-0.5.1 pymc3-3.11.2 semver-2.13.0 theano-pymc-1.1.2 xarray-0.17.0
WARNING: You are using pip version 21.0.1; however, version 21.1.1 is available.
You should consider upgrading via the '/root/venv/bin/python -m pip install --upgrade pip' command.
import numpy as np
import pymc3 as pm
import arviz as az
x = np.array([6.76, 6.93, 6.66, 6.56, 6.71, 6.91, 6.75, 6.66])
print('mean of x :', np.mean(x))
mean of x : 6.7425
print('standard deviation of x :', np.std(x))
standard deviation of x : 0.11808365678619547
# 8 is the sample size and z is the variable I am using for the standard deviation of means
z = np.std(x)/(np.sqrt(8))
print('standard deviation of the means :', z)
standard deviation of the means : 0.041748877230411846
sigma = np.std(x)
y = x + np.random.normal(size=len(x))*sigma
y
y.mean()
y.std()
N = 8
sem = sigma/np.sqrt(49*N)
sem
d = z/7
d
with pm.Model() as Difference:
mu1 = pm.Uniform("mu", lower=6.5, upper=7)
sigma1 = pm.Uniform("sigma1", lower=0, upper=1)
Obs = pm.Normal("x_obs", mu=mu1, sigma=sigma1, observed=x)
trace = pm.sample(1000, return_inferencedata=True)
print(az.summary(trace, kind="stats" ))
print(az.plot_trace(trace))
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma1, mu]
Sampling 2 chains for 1_000 tune and 1_000 draw iterations (2_000 + 2_000 draws total) took 4 seconds.
mean sd hdi_3% hdi_97%
mu 6.743 0.060 6.616 6.853
sigma1 0.156 0.057 0.075 0.252
[[<AxesSubplot:title={'center':'mu'}> <AxesSubplot:title={'center':'mu'}>]
[<AxesSubplot:title={'center':'sigma1'}>
<AxesSubplot:title={'center':'sigma1'}>]]
with pm.Model() as Difference:
mu1 = pm.Uniform("mu", lower=1, upper=392)
sigma1 = pm.Uniform("sigma1", lower=0, upper=1)
Obs = pm.Normal("x_obs", mu=mu1, sigma=sigma1, observed=x)
trace = pm.sample(1000, return_inferencedata=True)
print(az.summary(trace, kind="stats" ))
print(az.plot_trace(trace))
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma1, mu]
Sampling 2 chains for 1_000 tune and 1_000 draw iterations (2_000 + 2_000 draws total) took 5 seconds.
mean sd hdi_3% hdi_97%
mu 6.744 0.059 6.636 6.841
sigma1 0.153 0.055 0.080 0.247
[[<AxesSubplot:title={'center':'mu'}> <AxesSubplot:title={'center':'mu'}>]
[<AxesSubplot:title={'center':'sigma1'}>
<AxesSubplot:title={'center':'sigma1'}>]]
y2 = x + np.random.normal(size=(len(392))*sigma
y2
ValueError: operands could not be broadcast together with shapes (8,) (392,)