Up

Easy Ways to PyStan and PyMC3 in Windows

 

PyStan (The Python interface for Stan) and PyMC3 can be installed easily in Anaconda. Anaconda itself can be installed easily as explained in this Website.

Pystan can be installed by the conda command with the C++ compiler for the PyStan. PyMC3 can be used in Jupyter Notebook of Anaconda. In the following, first explain the case for PyStan, and then for PyMC3.

 

PyStan

PyStan can be installed easily in Anaconda. Anaconda can be installed easily as explained in this website.

In the virtual environment of Anaconda, PyStan can be installed by the conda command.

 

conda install pystan

 

When pystan is installed, the C++ compiler for the PyStan is also automatically installed.

When you write script, you need a text editor. The editor of Python IDLE is simple and easy. The Python IDLE editor is installed when you install Python from the website

 

https://www.python.org/

 

A new window of the editor can be opened by choosing the menu item gFile|NewFilef of Python IDLE.

Figure 1.1

 

The script, which should be saved before execution, can be executed by the command python in the virtual environment (Figure 1.2).

Figure 1.2

 

The script in Figure 1.3 is a sample one using the pystan module.

Figure 1.3

 

Run the script as shown in Figure 1.4

Figure 1.4

 

After the MCMC sampling ends, the posterior distribution of p will be displayed (Figure 1.5).

Figure 1.5

 

Close the window of Figure 1.5, the program ends.

The terminal window displays the following messages in the case of the script of Figure 1.3.

Figure 1.6

 

 

PyMC3

In Windows, PyMC3 can be used in Jupyter Notebook, which will be installed with Anaconda. If Jupyter is not installed, install it with the conda command

 

conda install jupyter

 

PyMC3 can be installed by the conda command. The following command installs PyMC3 with ArviZ, which will be used with PyMC3.

 

conda install pymc3 arviz

 

Open Jupyter Notebook, then write the script shown in Figure 2.1

Figure 2.1

 

Run the script in Figure 2.1, then you get the results shown in Figure 2.2

Figure 2.2

 

 

Up