A probabilistic artificial intelligence project that predicts the likelihood of individuals carrying a specific gene and exhibiting a related trait.
The program uses family relationships, known traits, genetic inheritance rules, and Bayesian probability to calculate probability distributions for every person in a family dataset.
- Predicts the probability of having 0, 1, or 2 copies of a gene
- Predicts the probability of exhibiting a genetic trait
- Supports parent-child inheritance relationships
- Handles known and unknown trait information
- Calculates joint probabilities across all possible family configurations
- Normalizes probability distributions
- Processes multiple CSV family datasets
- Uses only Python’s standard library
- Bayesian Inference
- Conditional Probability
- Joint Probability
- Probability Distributions
- Probabilistic Reasoning
- Genetic Inheritance Modeling
- Enumeration-Based Inference
- Python 3
- CSV data processing
- Standard Python Library
.
├── data/
│ ├── family0.csv
│ ├── family1.csv
│ └── family2.csv
├── heredity.py
├── requirements.txt
├── .gitignore
├── LICENSE
└── README.md
Each CSV file contains the following fields:
name,mother,father,trait
Example:
name,mother,father,trait
Harry,Lily,James,
James,,,1
Lily,,,0The trait value can be:
1— the person has the trait0— the person does not have the trait- Empty — the trait is unknown
Clone the repository:
git clone https://github.com/ambertiwary27/ai-heredity.gitMove into the project directory:
cd ai-heredityNo external libraries are required.
Run the program with any provided family dataset:
python3 heredity.py data/family0.csvpython3 heredity.py data/family1.csvpython3 heredity.py data/family2.csvHarry:
Gene:
2: 0.0092
1: 0.4557
0: 0.5351
Trait:
True: 0.2665
False: 0.7335
James:
Gene:
2: 0.1976
1: 0.5106
0: 0.2918
Trait:
True: 1.0000
False: 0.0000
Lily:
Gene:
2: 0.0036
1: 0.0136
0: 0.9827
Trait:
True: 0.0000
False: 1.0000
The program evaluates every possible combination of:
- Individuals who may have one copy of the gene
- Individuals who may have two copies of the gene
- Individuals who may exhibit the trait
For every valid configuration, it calculates the joint probability based on:
- Unconditional gene probabilities
- Parent-to-child gene transmission
- Mutation probability
- Conditional trait probability
The resulting probabilities are accumulated and normalized so that each distribution sums to 1.
A child receives one gene copy from each parent.
The probability of passing the gene depends on how many copies the parent has:
| Gene Copies | Probability of Passing Gene |
|---|---|
| 2 | 0.99 |
| 1 | 0.50 |
| 0 | 0.01 |
The small probability for a parent with zero copies represents genetic mutation.
This project demonstrates:
- Modeling uncertainty using probability
- Applying Bayesian reasoning
- Calculating joint probabilities
- Using conditional probabilities
- Performing exhaustive probabilistic inference
- Normalizing probability distributions
- Modeling real-world inheritance relationships
The concepts demonstrated in this project are relevant to:
- Genetic risk analysis
- Medical decision-support systems
- Bayesian networks
- Diagnostic systems
- Family inheritance modeling
- Probabilistic expert systems
This project is educational and should not be used for real medical diagnosis.
This project was developed as part of Harvard University’s CS50’s Introduction to Artificial Intelligence with Python.
Amber Kumar Tiwary
- GitHub: https://github.com/ambertiwary27
If you found this project useful, consider giving the repository a star.