# Complete Release Documentation

## Overview

This release contains the complete implementation of the Multi-Modal Medical Prediction framework with EXCAP (Efficient Adaptive Multi-modal Causal) architecture.

## Directory Structure

```
release/
├── README.md                          # Main documentation
├── requirements.txt                   # Python dependencies
├── setup.py                          # Installation script
├── COMPLETE_DOCUMENTATION.md         # This file
│
├── configs/                          # Configuration files
│   └── excap_model.yaml             # EXCAP model configuration
│
├── data/                            # Data directory (empty, data should be placed here)
│   └── cache/                       # Cache directory
│
├── datapress/                       # Data processing modules
│   ├── Aligned/                     # Aligned dataset implementations
│   │   ├── medical_dataset_with_los.py
│   │   ├── medical_dataset_wrapper.py
│   │   ├── medical_dataset.py
│   │   └── ...
│   └── cache_dataset.py
│
├── exp/                             # Experiment configurations
│   └── mimic_data/
│       └── exp_mortality_24h48h_los.yaml
│
├── model/                           # Model implementations
│   ├── EXCAP.py                     # Main EXCAP architecture
│   ├── factory.py                   # Model factory functions
│   ├── multi_task_wrapper.py        # Multi-task wrapper
│   ├── budget_controller.py        # Budget control
│   ├── common/                      # Common modules
│   │   └── features_and_fusion.py
│   ├── models/                      # Model implementations
│   │   ├── multimodal_model.py
│   │   └── trajectory_model.py
│   ├── modules/                     # Core modules
│   │   ├── dynamic_segmentation.py
│   │   └── causal_graph.py
│   ├── layers/                      # Network layers
│   │   ├── image_encoder.py
│   │   ├── text_encoder.py
│   │   ├── ts_encoder.py
│   │   ├── gma.py
│   │   └── ...
│   └── backbone/                    # Backbone components
│
├── training/                        # Training scripts
│   ├── train_EXCAP.py
│   └── advanced_loss_functions.py
│
├── utils/                            # Utility functions
│   ├── optim_factory.py             # Optimizer factory
│   └── metrics.py                   # Evaluation metrics
│
├── scripts/                          # Helper scripts
│   ├── check_dependencies.py       # Check missing files
│   ├── remove_chinese.py            # Remove Chinese comments
│   └── add_missing_files.sh         # Add missing files
│
└── train_mortality_los_complete.py   # Multi-task training script
```

## Installation

### 1. Install Dependencies

```bash
cd release
pip install -r requirements.txt
pip install -e .
```

### 2. Prepare Data

Place your data in the `data/` directory following the structure:
```
data/
├── MIMIC/
│   ├── index.json
│   ├── images/
│   └── reports/
└── cache/
```

### 3. Configure Paths

Update configuration files in `exp/mimic_data/` to point to your data paths.

## Quick Start

### Training Multi-Task Model

```bash
python train_mortality_los_complete.py \
    --gpu 0 \
    --epochs 20 \
    --lr 5e-5 \
    --batch_size 256 \
    --num_workers 1 \
    --max_samples 80000 \
    --experiment_name my_experiment
```

## Key Components

### 1. EXCAP Architecture

The EXCAP (Efficient Adaptive Multi-modal Causal) architecture is implemented in:
- `model/EXCAP.py` - Main architecture
- `model/modules/dynamic_segmentation.py` - Dynamic segmentation
- `model/modules/causal_graph.py` - Causal graph module
- `model/layers/gma.py` - Gated Multiscale Attention

### 2. Model Factory

The model factory (`model/factory.py`) provides:
- `create_multimodal_model()` - Create multimodal prediction model
- `create_traj_model()` - Create trajectory prediction model

### 3. Data Processing

Key data processing modules:
- `datapress/Aligned/medical_dataset_with_los.py` - LOS dataset
- `datapress/Aligned/medical_dataset_wrapper.py` - Dataset wrapper
- `datapress/cache_dataset.py` - Caching utilities

### 4. Training Scripts

Main training script:
- `train_mortality_los_complete.py` - Multi-task training (mortality + LOS)

## Configuration

### Model Configuration

Edit `configs/excap_model.yaml` or `exp/mimic_data/exp_mortality_24h48h_los.yaml`:

```yaml
model:
  shared_dim: 128
  image_dim: 128
  text_dim: 128
  ts_dim: 64
  static_dim: 10
  use_excap: true
  max_segments: 8
  segment_len: 64
```

### Training Configuration

Training parameters can be set via command line arguments or configuration files.

## Dependencies

All dependencies are listed in `requirements.txt`. Key dependencies:
- PyTorch >= 1.12.0
- torchvision >= 0.13.0
- numpy >= 1.21.0
- scikit-learn >= 1.0.0
- omegaconf >= 2.2.0
- tqdm >= 4.64.0

## Troubleshooting

### Import Errors

If you encounter import errors:

1. Check that all files are present:
   ```bash
   python scripts/check_dependencies.py
   ```

2. Ensure you're in the release directory:
   ```bash
   cd release
   python -c "from model.factory import create_multimodal_model; print('OK')"
   ```

### Missing Files

If files are missing, run:
```bash
bash scripts/add_missing_files.sh
```

### Path Issues

Update hardcoded paths in training scripts (see `FIX_HARDCODED_PATHS.md`).

## File Verification

Run the dependency checker:
```bash
python scripts/check_dependencies.py
```

This will verify:
- All required files are present
- Import dependencies are satisfied
- File structure is correct

## Code Quality

All Chinese comments and print statements have been removed from the codebase. The code is now:
- English-only comments
- English-only print statements
- Ready for international review

## Citation

If you use this code, please cite:

```bibtex
@article{excap2024,
  title={Multi-Modal Medical Prediction with Efficient Adaptive Causal Attention},
  author={Anonymous},
  journal={Anonymous},
  year={2024}
}
```

## License

This project is licensed under the MIT License.


