# README for Reproducing Experiments

This README provides step-by-step instructions for the review committee to reproduce the experiments in our paper. The process includes setting up the environment, preparing datasets, running the experiments, and visualizing the results.

## Overview

This project evaluates two algorithms, HybUCB-AR and HybElimUCB-RA, using both synthetic and real-world datasets (MovieLens 20M and Yelp). Follow the steps below to set up the environment and replicate our findings.

## Environment Setup

### 1. Prerequisites
Ensure you have Python 3.9 or later installed on your system. We recommend using a virtual environment to manage dependencies. Additionally, install `wget`, `unzip`, and `tar` for dataset downloading and extraction (e.g., `sudo apt install wget unzip tar` on Ubuntu). For visualization, ensure you have Jupyter Notebook installed to run `.ipynb` files (e.g., `pip install jupyter`).

### 2. Package Installation
The project relies on the following Python packages:
- `numpy`: For numerical computations.
- `tqdm`: For progress bars during data processing.
- `pandas`: For data manipulation and analysis.
- `random`: For random sampling (built-in Python module, no installation required).

Install the required packages using pip:

```bash
pip install numpy tqdm pandas jupyter
```

If you encounter any issues, ensure your pip version is up to date:

```bash
pip install --upgrade pip
```

## Dataset Preparation

We use two datasets for the real-world experiments: MovieLens 20M and Yelp. A Bash script is provided to automate the download and setup process.

### 1. Automated Data Setup
- **Script**: `setup_data.sh` (located in the project root directory).
- **Instructions**:
  1. Ensure you have write permissions in the project directory.
  2. Make the script executable:
     ```bash
     chmod +x setup_data.sh
     ```
  3. Run the script to download and process datasets:
     ```bash
     bash setup_data.sh
     ```
  4. The script will:
     - Download MovieLens 20M from [https://files.grouplens.org/datasets/movielens/ml-20m.zip](https://files.grouplens.org/datasets/movielens/ml-20m.zip) to the `data/` directory.
     - Attempt to download the Yelp dataset (`Yelp-JSON.zip`) from [https://business.yelp.com/external-assets/files/Yelp-JSON.zip](https://business.yelp.com/external-assets/files/Yelp-JSON.zip) using a User Agent. If the download fails, manually download `Yelp-JSON.zip` from the same link and place it in `data/`.
     - Unzip `Yelp-JSON.zip` into `data/`, which contains a PDF and a `yelp_dataset.tar` file in the `Yelp JSON` folder.
     - Further extract `yelp_dataset.tar` from `data/Yelp JSON/` to obtain `yelp_academic_dataset_review.json` in `data/`.
     - Process the Yelp dataset using `yelp_processing.py` to generate `data/yelp.csv`.
     - Extract `ratings.csv` (renamed to `movielens.csv`) and `yelp.csv` to `HybElimUCB-RA/real_data/` and `HybUCB-AR/real_data/`.

### 2. Manual Verification
After running the script, verify the following files exist:
- `data/ml-20m/ratings.csv`
- `data/yelp_academic_dataset_review.json`
- `HybElimUCB-RA/real_data/movielens.csv`
- `HybElimUCB-RA/real_data/yelp.csv`
- `HybUCB-AR/real_data/movielens.csv`
- `HybUCB-AR/real_data/yelp.csv`

## Code Execution

After dataset preparation, you can run the experiments and generate visualizations for either algorithm.

### 1. Running Experiments
Each algorithm (`HybUCB-AR` and `HybElimUCB-RA`) has its own folder containing a `src/` directory with a `train.sh` script to run the experiments.

- **Instructions**:
  1. Navigate to the desired algorithm folder (e.g., `HybElimUCB-RA`):
  2. Ensure the `train.sh` script is executable:
     ```bash
     chmod +x src/train.sh
     ```
  3. Run the experiment:
     ```bash
     bash train.sh
     ```
  4. Repeat the process for the other algorithm (`HybUCB-AR`) if needed.

The `train.sh` script will execute the experiment, including synthetic and real-world datasets, and save the results for further analysis.

### 2. Visualizing Results
Each algorithm folder contains a `plot.ipynb` Jupyter Notebook for generating visualizations of the experiment results.

- **Instructions**:
  1. Ensure you are in the algorithm folder (e.g., `HybElimUCB-RA`):
  2. Open the `plot.ipynb` file.
  3. Click "Run All" to execute all cells in the notebook.
  4. The visualizations will be generated and saved in the `output/` directory within the algorithm folder.
  5. Repeat the process for the other algorithm (`HybUCB-AR`) if needed.

- **Output Verification**:
  After running `plot.ipynb`, check the `output/` directory in each algorithm folder for the generated data figures.