A python interface with Stan/PyStan Markov Chain Monte Carlo package
1.8K
https://morpho.readthedocs.io/en/latest/
Morpho is an analysis tool that organizes data inflow to and outflow from Stan, a platform for Bayesian statistical modeling and computation, and RooFit, a toolkit for modeling probability distributions. It is especially useful for
Morpho interfaces with Stan using PyStan, but it is designed to be employed by general Stan users (not only PyStan users).
Why morpho?
The following dependencies should be installed (via a package manager) before installing morpho 2:
We recommend installing morpho using pip inside a python virtual environment. Doing so will automatically install dependencies beyond the four listed above, including PyStan 2.17.
If necessary, install virtualenv, then execute:
# Use a flag for virtualenv to specify python3 if necessary: --python /path/to/python3
virtualenv ~/path/to/the/virtualenvironment
source ~/path/to/the/virtualenvironment/bin/activate #Activate the environment
pip install -U pip #Update pip to >= 7.0.0
cd ~/path/to/morpho
pip install .
# When done with morpho, use "bash deactivate" to exit the virtual environment
If you would like to modify your local installation of morpho (to add features or resolve any bugs), we recommend you use a Docker container instead of a python virtual environment. To do so:
docker run -v $(pwd):/my_morpho -v ~/morpho_share:/host -it project8/p8compute_dependencies
A new terminal prompter (for example, root@413ab10d7a8f:) should appear.
Source the setup file, and install morpho inside the container with the following commands:. $COMMON_BUILD_PREFIX/setup.sh
cd /my_morpho
pip3 install -e .
Local modifications to the morpho installation will then appear in the docker container. Files in ~/morpho_share will be available in the docker container in the /host folder.
If you develop new features or identify bugs, please open a GitHub issue.
If you prefer to install the latest version of morpho via docker, use the following commands. However, this does not allow morpho to be edited locally, so it cannot be used for development.
docker-compose run morpho. A new terminal prompter (for example, root@413ab10d7a8f:) should appear. Once inside the container, run source $MORPHO_BUILD_PREFIX/setup.sh to be able to access morpho and libraries.docker pull morpho/morpho.Morpho primarly reads a configuration file (.json or .yaml) written by the user (it can also be used via the python interface). The file defines the actions ("processors") the user wants to perform and the order in which these should be done. The file also specifies input parameters that the user may wish to change on a run-to-run basis, such as the desired number of Stan iterations, or Stan initialization and data-block values. See morpho's documentation for more information.
We recommend modeling the organization of your configuration files, Stan models and data files after the examples folder in morpho. Your directory structure should be of the form:
examples
|
+---functions_dir
| |
| +---Stan_funcs1.functions
| +---Stan_funcs2.functions
| +---Stan_funcs3.functions
|
+---analysis_dir1
| |
| +---data_dir
| | |
| | +---fileA.data
| | +---fileB.data
| |
| +---model_dir
| | |
| | +---modelA.stan
| | +---modelB.stan
| |
| +---scripts_dir
| |
| +---configA.yaml
| +---configB.yaml
|
+---analysis_dir2
| |
... ...
The files in the optional functions_dir directory contain Stan functions (written in the Stan language) that are used in multiple Stan models.
Once the relevant data, model and configuration files are at your disposal, run morpho by executing:
morpho --config /path/to/json_or_yaml_config_file --other_options
You can find and run an example in the examples directory:
morpho --config linear_fit/scripts/morpho_linear_fit.yaml
"Help will always be given to those who ask for it":
morpho --help
The morpho python API allows you to run custom and more modulable scripts. In a python script, the processors should be created, configured and run. Connections between processors are made by setting a internal varible of a processor (like "results" for PyStanSamplingProcessor) as the internal variable of another variable. Examples of such python scripts can be found in the examples folder:
python linear_fit/scripts/pystan_test.py
When compiling a model inside the docker container, it can happen that the model takes a long time (larger than 2-3 minutes) before crashing with a gcc error 4 message.
During this compilation, all the CPU available to docker will be used too.
This is due to a lack of memory available to the container (basically when running with 1 GB RAM).
To solve this, increase the RAM to ~4 GB.
Content type
Image
Digest
Size
1 GB
Last updated
about 5 years ago
docker pull project8/morpho