Skip to content

ElHachem02/Bayesian_AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bayesian AI Projects

This repository contains implementations of four Bayesian AI projects covering Gaussian Processes, Bayesian Deep Learning, Bayesian Optimization, and Reinforcement Learning.

Overview

This collection demonstrates various Bayesian machine learning techniques:

  • Project 01: Gaussian Process Regression for pollution prediction with uncertainty quantification
  • Project 02: SWAG (Stochastic Weight Averaging-Gaussian) for uncertainty-aware deep learning
  • Project 03: Constrained Bayesian Optimization for safe optimization
  • Project 04: Soft Actor-Critic (SAC) reinforcement learning algorithm

Project Structure

Bayesian_AI/
├── Project01/          # Gaussian Process Regression
├── Project02/          # SWAG for Deep Learning Uncertainty
├── Project03/          # Constrained Bayesian Optimization
└── Project04/          # Soft Actor-Critic RL

Project Details

Project 01: Gaussian Process Regression

Objective: Predict pollution concentrations using Gaussian Process Regression with uncertainty quantification.

Key Features:

  • Implements a Gaussian Process Regressor with custom kernel selection
  • Handles cost-sensitive predictions (higher cost for underprediction in city areas)
  • Uses Matern kernel with optimized hyperparameters
  • Includes extended evaluation with visualization capabilities

Technologies:

  • scikit-learn (GaussianProcessRegressor)
  • NumPy, Pandas
  • Matplotlib for visualization

Files:

  • solution.py: Main implementation with Model class
  • train_x.csv, train_y.csv: Training data
  • test_x.csv: Test features

How to Run:

cd Project01
docker build --tag task1 .
docker run --rm -v "$(pwd):/results" task1

Project 02: SWAG for Uncertainty Quantification

Objective: Implement SWA-Gaussian (SWAG) method for uncertainty quantification in deep learning, applied to image classification.

Key Features:

  • Implements both SWAG-diagonal and full SWAG methods
  • Bayesian Model Averaging (BMA) for prediction
  • Uncertainty-aware predictions with "don't know" option
  • Calibration using validation data
  • CNN architecture for image classification

Technologies:

  • PyTorch
  • NumPy
  • Matplotlib for visualization

Files:

  • solution.py: SWAGInference class implementation
  • util.py: Utility functions for calibration and evaluation
  • map_weights.pt: Pretrained MAP weights

How to Run:

cd Project02
# Follow Docker instructions or use runner.sh

Project 03: Constrained Bayesian Optimization

Objective: Implement constrained Bayesian optimization for safe optimization of a black-box function subject to safety constraints.

Key Features:

  • Dual Gaussian Process approach (one for objective, one for constraint)
  • Safe exploration with constraint satisfaction
  • Upper Confidence Bound (UCB) acquisition function with penalty terms
  • Handles safety-critical optimization scenarios

Technologies:

  • scikit-learn (GaussianProcessRegressor)
  • NumPy
  • SciPy (optimization)

Files:

  • solution.py: BO_algo class with acquisition function optimization

How to Run:

cd Project03
# Follow Docker instructions or use runner.sh

Project 04: Soft Actor-Critic (SAC)

Objective: Implement the Soft Actor-Critic reinforcement learning algorithm for continuous control tasks (Pendulum environment).

Key Features:

  • Actor-Critic architecture with stochastic policy
  • Twin Q-networks for value estimation
  • Entropy regularization for exploration
  • Replay buffer for off-policy learning
  • Soft target network updates

Technologies:

  • PyTorch
  • OpenAI Gym (classic_control)
  • NumPy

Files:

  • solution.py: Agent, Actor, Critic classes implementing SAC
  • utils.py: ReplayBuffer and environment utilities

How to Run:

cd Project04
# Follow Docker instructions or use runner.sh

Requirements

Each project has its own requirements.txt file. General dependencies include:

  • Project 01: numpy, scikit-learn, pandas, matplotlib
  • Project 02: torch, numpy, tqdm, matplotlib
  • Project 03: numpy, scikit-learn, scipy
  • Project 04: torch, gym, numpy, moviepy

Setup

Using Docker (Recommended)

Each project includes a Dockerfile for containerized execution:

# Example for Project 01
cd Project01
docker build --tag project01 .
docker run --rm -v "$(pwd):/results" project01

Local Setup

  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install project-specific requirements:
cd ProjectXX
pip install -r requirements.txt
  1. Run the solution:
python solution.py

Evaluation

Each project includes:

  • checker_client.py: Automated evaluation script
  • runner.sh: Execution script
  • results_check.byte: Encrypted results file (generated after running)

Notes

  • Projects use pytransform for code protection/obfuscation
  • Some projects include Jupyter notebooks (test.ipynb) for exploration
  • Extended evaluation modes can be enabled for additional visualizations
  • All projects are designed to run on standard hardware (laptops)

License

This repository contains course project implementations. Please refer to the course guidelines for usage and distribution policies.

About

4 implementations of projects of probabilistic_AI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •