Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR after Rebase #29

Merged
merged 26 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions Taweret/mix/trees.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Name: trees.py
Author: John Yannotty (yannotty.1@osu.edu)
Desc: Defines the tree mixing class, which is an interface for MixBART
Desc: Defines the tree mixing class, which is an interface for BART-BMM

Start Date: 10/05/22
Version: 1.0
Expand All @@ -15,6 +15,7 @@
import tempfile
import shutil
import os
import typing

import Taweret.core.setup

Expand All @@ -27,7 +28,7 @@

class Trees(BaseMixer):
# Overwrite base constructor
def __init__(self, model_dict, **kwargs):
def __init__(self, model_dict: dict, **kwargs):
'''
Constructor for the Trees mixing class.

Expand Down Expand Up @@ -131,7 +132,7 @@ def map(self):
'''
return super().map

# Done

@property
def posterior(self):
'''
Expand Down Expand Up @@ -184,9 +185,9 @@ def prior(self):

return hyper_params_dict

# DONE
def set_prior(self, ntree=1,ntreeh=1,k=2,power=2.0,base=0.95,overallsd=None, \
overallnu=10,inform_prior=True,tauvec=None,betavec=None):

def set_prior(self, ntree: int = 1,ntreeh:int = 1, k: float=2,power: float=2.0,base:float=0.95,overallsd:float=None, \
overallnu: int = 10,inform_prior: bool = True,tauvec: bool = None,betavec: bool = None):
'''
Sets the hyperparameters in the tree and terminal node priors. Also
specfies if an informative or non-informative prior will be used.
Expand Down Expand Up @@ -266,15 +267,15 @@ def prior_predict(self):
raise Exception("Not applicable for trees.")


def train(self,X, y, **kwargs):
def train(self,X: np.ndarray, y: np.ndarray, **kwargs):
'''
Train the mixed-model using a set of observations y at inputs x.

Parameters:
----------
X : np.ndarray
X : np.ndarray (n X p)
input parameter values.
y : np.1darray
y : np.ndarray (n X 1)
observed data at inputs X.
kwargs : dict
Dictionary of arguments
Expand Down Expand Up @@ -377,7 +378,7 @@ def train(self,X, y, **kwargs):
return res


def predict(self, X, ci = 0.95):
def predict(self, X: np.ndarray, ci: float = 0.95):
'''
Obtain posterior predictive distribution of the mixed-model at a set
of inputs X.
Expand Down Expand Up @@ -474,7 +475,7 @@ def predict(self, X, ci = 0.95):
return pred_post, pred_mean, pred_credible_interval, pred_sd


def predict_weights(self, X, ci = 0.95):
def predict_weights(self, X: np.ndarray, ci: float = 0.95):
'''
Obtain posterior distribution of the weight functions at a set
of inputs X.
Expand Down Expand Up @@ -548,14 +549,14 @@ def predict_weights(self, X, ci = 0.95):
posterior = self.wdraws
post_mean = self.wts_mean
post_sd = self.wts_sd
post_credible_interval = (self.wts_lower,self.wts_upper)
post_credible_interval = [self.wts_lower,self.wts_upper]

return posterior, post_mean, post_sd, post_credible_interval
return posterior, post_mean, post_credible_interval, post_sd


# -----------------------------------------------------------
# Plotting
def plot_prediction(self, xdim = 0):
def plot_prediction(self, xdim: int = 0):
'''
Plot the predictions of the mixed-model. The x-axis of this plot
can be any column of the design matrix X, which is passed into
Expand Down Expand Up @@ -592,7 +593,7 @@ def plot_prediction(self, xdim = 0):
plt.show()


def plot_weights(self, xdim = 0):
def plot_weights(self, xdim: int = 0):
'''
Plot the weight functions. The x-axis of this plot
can be any column of the design matrix X, which is passed into
Expand Down
92 changes: 92 additions & 0 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,95 @@ The pip installation is not available yet. We are working on it.
.. code-block:: bash

pip install Taweret

Installation
============

Taweret requires the following for for basic functionality.
- python
- numpy
- seaborn
- jupyter
- bilby
- ptemcee

Follow these steps to install Taweret from github.

.. code-block:: bash

git clone https://github.com/danOSU/Taweret.git
#If you want to use SMABA toy models please clone samba repo
#git clone https://github.com/asemposki/SAMBA.git
cd Taweret
conda env create -f environment.yml
conda activate test_env
cd doc/source/notebooks
jupyter notebook --browser=safari

You can look at the available notebooks in the directory and modify it for your own use case. If \
you need to add a new mixing method please refer to the **For Deveopers** section.

The pip instalation is not available yet. We are working on it.

.. code-block:: bash
pip install Taweret



Additional Requirements
-----------------------

Certain Taweret modules may require additional steps to properly setup an environment which can \
execute the code. These modules and their respective requirements are listed below.

**Tree**
^^^^^^^^^

The Trees module is a Python interface which calls and executes a number of Ubuntu packages in order \
to fit the mixing model and obtain the resulting predictions. This package is developed as a part of the \
Open Bayesian Trees Project (OpenBT)[1,2]. To install the Ubuntu package, please follow the steps below \
based on the operating system of choice.


**Linux:**

1. Download the OpenBT Ubuntu Linux 20.04 package:
.. code-block:: bash
$ wget -q https://github.com/jcyannotty/OpenBT/raw/main/openbt_mixing0.current_amd64-MPI_Ubuntu_20.04.deb


2. Install the package and result the library cache:
.. code-block:: bash
$ cd /location/of/downloaded/.deb
$ dpkg -i openbt_mixing0.current_amd64-MPI_Ubuntu_20.04.deb
$ ldconfig


**Mac OS/:X

1. Install the OS/X OpenMPI package by running the following `brew` commands in a terminal window:
.. code-block:: bash
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
$ brew install open-mpi

2. Download the OpenBT OSX binary package:

3. Install the OpenBT OSX package by double-clicking on the downloaded .pkg file and follow the on-screen instructions.


**Windows:**
OpenBT will run within the Windows 10 Windows Subsystem for Linux (WSL) environment. For instructions on installing WSL,\
please see [Ubuntu on WSL](https://ubuntu.com/wsl). We recommend installing the Ubuntu 20.04 WSL build. \
There are also instructions \
[here](https://wiki.ubuntu.com/WSL?action=subscribe&_ga=2.237944261.411635877.1601405226-783048612.1601405226#Installing_Packages_on_Ubuntu) \
on keeping your Ubuntu WSL up to date, or installing additional features like X support. Once you have \
installed the WSL Ubuntu layer, start the WSL Ubuntu shell from the start menu and then install the package:

.. code-block:: bash
$ cd /mnt/c/location/of/downloaded/.deb
$ dpkg -i openbt_mixing0.current_amd64-MPI_Ubuntu_20.04.deb


**OpenBT References**
[1. OpenBT Repository](https://bitbucket.org/mpratola/openbt/src/master/).
[2. OpenBT Repository with Model Mixing](https://github.com/jcyannotty/OpenBT).
182 changes: 180 additions & 2 deletions docs/source/notebooks/Trees_BMM_2D.ipynb

Large diffs are not rendered by default.

Loading