# PT-VCP

This project implements **PT-VCP** method for both classification and regression tasks, including ImageNet classification, ordinary regression experiments, and Conformalized Quantile Regression (CQR). The code of classification task is modified from [1], and the regression part is from [2].

##  Project Structure

```
classification_task/      # Classification-related code (ImageNet experiments)
  ├── cvg_len_cls.py    # Classification experiments
  ├── conformal_procedure.py      # Implementation of conformal prediction procedure for classification
  ├── interval_stability_cls.py   # Interval stability experiments for classification
  ├── utils.py                    # Utility functions for classification
  ├── cvg_len_result/             # Coverage and length results for various models (classification)
  └── std_results/                # Standard baseline results

ordinary_regression_task/ # Ordinary regression experiments and simulations
  ├── ordinary_regression_FitModel.py  # Model training / fit routines for ordinary regression
  ├── ordinary_regmodel.py             # Model definitions and helpers
  ├── ordinary_regression_ablation.py  # Ablation / simulation experiments
  ├── ordinary_regression_cvg.py       # Coverage experiments and scripts
  ├── interval_stability.py            # Interval stability experiments (regression)
  ├── datasets/                        # Small example datasets / data loaders for regression
  ├── cvg_result/                      # Coverage results for ordinary regression
  └── interval_stability_results/      # Interval stability outputs

cqr/                     # CQR-related code (Conformalized Quantile Regression)
  ├── cqr_ablation.py           # Ablation experiments for CQR
  ├── cqr_FitModel.py           # Model fitting and training for CQR
  ├── Stability_cqr.py          # Stability experiments for regression intervals (CQR)
  ├── interval_stability_results.csv
  └── cqrfile/                  # CQR helper modules and models
      ├── helper.py
      └── torch_models.py

other/                   
  └── README.md               # (this file)
```

##  Requirements

- Python >= 3.8
- PyTorch >= 1.10
- NumPy, SciPy, Pandas, Matplotlib
- (Optional) tqdm, scikit-learn

##  Usage

### 1) Classification Task (ImageNet)
Due to the large size of the ImageNet dataset, the **ImageNet validation set** (`imagenet_val`) is **not included** in this repository.

Example:
```bash
cd classification_task
python cvg_len_cls.py
```

Outputs will be written into `classification_task/cvg_len_result/` and `classification_task/std_results/`.

### 2) Ordinary Regression Task (simulations & real-data experiments)
This folder contains ordinary regression experiments, simulation scripts, model fitting, and coverage/stability evaluations.

Run coverage / experiment scripts:
```bash
cd ordinary_regression_task
python ordinary_regression_cvg.py            # coverage experiments
python ordinary_regression_ablation.py      # ablation / simulation experiments
python ordinary_regression_FitModel.py      # train/fit models (if needed)
```

Results (coverage, interval stability, group coverage) are saved under:
```
ordinary_regression_task/cvg_result/
ordinary_regression_task/interval_stability_results/
ordinary_regression_task/group_coverage_result/
```

There are also example simulation scripts such as `simulation_guassian.py`(failure case) and `simulation_subgaussian.py` you can run to reproduce parts of the paper's experiments.

### 3) CQR (Conformalized Quantile Regression)
Run CQR ablation or stability experiments:
```bash
cd cqr
python cqr_ablation.py
python Stability_cqr.py
```

CQR outputs and CSV results are under `cqr/interval_stability_results.csv` and the `cqr/` subfolders.

##  Results

- Classification: `classification_task/cvg_len_result/`, `classification_task/std_results/`
- Ordinary regression: `ordinary_regression_task/cvg_result/`, `ordinary_regression_task/interval_stability_results/`, `ordinary_regression_task/group_coverage_result/`
- CQR: `cqr/interval_stability_results.csv` and related folders

##  Notes

- If you intend to reproduce experiments end-to-end, please ensure you have the correct dataset paths and the same dependency versions as used by the authors.
- Large datasets (ImageNet) must be downloaded separately due to size and licensing.
- Some scripts expect trained model checkpoints under `model/` or `classification_task/model/`

##  References

- [1] Angelopoulos, A. N., Bates, S., Jordan, M., & Malik, J. (2021). *Uncertainty Sets for Image Classifiers using Conformal Prediction*. International Conference on Learning Representations (ICLR). [Link](https://openreview.net/forum?id=eNdiU_DbM9)  
- [2] Romano, Y., Patterson, E., & Candès, E. (2019). *Conformalized Quantile Regression*. Advances in Neural Information Processing Systems (NeurIPS). [Link](https://arxiv.org/abs/1905.03222)

