# Mamba-IVP: Modeling EHR Time Series with Initial Value Problem Solvers


## Requirements

IVP-VAE has tested using Python 3.10 and Conda environment management tool.

To have consistent libraries and their versions, you can install needed dependencies 
for this project running the following command:

```
conda env create -f environment.yml
```

Because some dependent libraries are constantly being updated and changed, in order to ensure the successful execution of the code, we added two historical versions of the dependent libraries ([torchdiffeq](https://github.com/rtqichen/torchdiffeq) and [stribor](https://github.com/mbilos/stribor)) in the "*libs*" folder.

## Datasets

We used 3 public EHR datasets in the experiments. MIMIC-IV and eICU need users to register as a credentialed user and sign a data use agreement on the PhysioNet Platform (https://physionet.org/), to obtain the access. PhysioNet 2012 can be freely obtained without registration.


### MIMIC-IV

- **Obtain**: We used MIMIC-IV v1.0, which can be downloaded from https://physionet.org/content/mimiciv/1.0/. 

- **Preprocess**: The preprocessing programs can be found in folder "*preprocess/pre_mimic4*". They were adapted from the repository of [Neural Flow](https://github.com/mbilos/neural-flows-experiments/tree/master/nfe/experiments/gru_ode_bayes/data_preproc).

### eICU

- **Obtain**: We used eICU v2.0, which can be downloaded from https://physionet.org/content/eicu-crd/2.0/.

- **Preprocess**: The preprocessing programs can be found in folder "*preprocess/pre_eicu*". They were developed upon a [previous work](https://github.com/mostafaalishahi/eICU_Benchmark).

### PhysioNet 2012

- **Obtain**: We used PhysioNet 2012 v1.0, which can be downloaded from https://physionet.org/content/challenge-2012/1.0.0/. 

- **Preprocess**: The automatic downloading and preprocessing code is in file "*experiments/data_physionet12.py*". This file was built upon a [previous program](https://github.com/mbilos/neural-flows-experiments/blob/master/nfe/experiments/latent_ode/physionet.py).

## Running the code

With Neural ODEs or Neural Flows as the IVP solver, there are two variants of IVP-VAE, i.e. IVP-VAE-ODE and IVP-VAE-Flow. Taking PhysioNet 2012 as an example, we show how to run IVP-VAE models for forecasting and classification tasks. 

Run IVP-VAE-ODE on PhysioNet 2012 dataset for time series forecasting:

```
python main.py --random-state 1 --ml-task extrap --ivp-solver ode --combine-methods kl_weighted --data p12 --time-scale constant --time-max 2880
```

Run IVP-VAE-Flow on PhysioNet 2012 dataset for time series forecasting:

```
python main.py --random-state 1 --ml-task extrap --ivp-solver resnetflow --combine-methods kl_weighted --data p12 --time-scale constant --time-max 2880
```

Run IVP-VAE-ODE on PhysioNet 2012 dataset for time series classification:

```
python main.py --random-state 1 --ml-task biclass --ivp-solver ode --data p12 --time-max 1439 --ratio-ce 100
```

Run IVP-VAE-Flow on PhysioNet 2012 dataset for time series classification:

```
python main.py --random-state 1 --ml-task biclass --ivp-solver resnetflow --data p12 --time-max 1439 --ratio-ce 100
```


## License

IVP-VAE is licensed under the MIT License.

## Acknowledgement
We appreciate the following baseline works for their valuable code and data for irregular time series analysis:

https://github.com/YuliaRubanova/latent_ode

https://github.com/mbilos/neural-flows-experiments

https://github.com/edebrouwer/gru_ode_bayes

https://github.com/mims-harvard/Raindrop

https://github.com/reml-lab/mTAN

https://github.com/boschresearch/Continuous-Recurrent-Units
