# TANGEM
You can see generated graph examples under `generated_graphs` folder. 

## Installation

We worked on a conda environment. You can follow the instructions below to install the library:

1. Create a conda environment
```bash
conda create -n dygg python=3.12
```

2. After activating environment, install PyTorch using pip (torch==2.4.0+cu124)
```bash
pip install torch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 --index-url https://download.pytorch.org/whl/cu124
```
3. Install other libraries
```bash
pip install -r requirements.txt
```

**Note**: Probably you will not need it but if you get any error related to orca, please follow instructions in GraphRNN github repo. You will simply compile cpp file in orca folder.

#

## Training of TANGEM

You can train TANGEM model using command below with args `graph-name` and `walk-type`.

```python
python train.py --graph-name pems04 --walk-type brn_plus
```
- `graph-name`: dataset name
  - Real-world datasets 
    - ibb1, ibb2, ibb3, ibb4, ibb5, ibb6
    - pems04, pems08
    - citeseer
  - Synthetic datasets (temporal features will be generated by heat diffusion process)
    - er_small, er_medium, er_large
    - ba_small, ba_medium, ba_large
    - community_small, community_medium, community_large
    - ego_small, ego_medium, ego_small

- `walk-type`
  - random: regular random walk
  - random_plus: temporal-aware random walk
  - brn: regular biased random walk
  - brn_plus: temporal-aware biased random walk

 
 After completion, the MMD scores will be calculated and generated graph topologies will be saved under `generated_figures` folder. You can change default training parameters from config (e.g., reduce 'max_iters' for shorter training). 

 - For CiteSeer graph, we used 'num_tokens', as 4000 (default is 1000). Other than this change, config file can remain as it is for all graphs.

## Ablation Study - Training for temporal traffic prediction

We share this part as a jupyter notebook. After completing Step-1, generated topologies will be saved as `gen_graphs.pkl`. Using `temporal_gen.ipynb`, you can choose one of generated topologies and then train ASTGCN model to generate temporal features. For example, the model will be trained on 1 week of traffic data and will predict 1 days of traffic flow data. 

#

![Alt text](./generated_graphs/pems04_generated.gif)

* You can find numerous generated graph figures and a GIF in the `generated_graphs` folder.
* `walk.py` and `walk_generation.py` contains required functionalities to generate walks on graphs.
* `evaluation.py` consists of **MMD** calculations and other functionalities used for evaluation
* `model.py` includes transformer model used in learning and generating graph topology.
* You can see baseline models under `baselines` folder. We used official implementations of GraphRNN, GRAN, DiGress and run them on Google Colab. Since Colab does not support tf 1.x, we created a conda environment to run NetGAN and run it locally.
 


