Skip to content

Commit d967d48

Browse files
rishal-hurbansRishal Hurbans
authored andcommitted
LLMs (Ch11) and Generative Image Models (Ch12) initial code. Improved README files.
Update README.md Mostly working code. Clean up. Refactors. Comment fixes for LLMs. Print fixes for LLMs. Improved variable names in LLM. Clean up. Comment tweaks. Comment tweaks. README improvements. LLMs (Ch11), and Generative Image Models (Ch12) initial code. README improvements. LLMs (Ch11) and Generative Image Models (Ch12) initial code. Improved README files.
1 parent dd44e08 commit d967d48

31 files changed

Lines changed: 5679 additions & 7 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22

33
[Get Grokking Artificial Intelligence Algorithms at Manning Publications](https://www.manning.com/books/grokking-artificial-intelligence-algorithms?a_aid=gaia&a_bid=6a1b836a)
44

5+
Rather Learn by exploring the code notebook in your browser? Click here:
6+
7+
[![Open the interactive code notebook](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/rishal-hurbans/Grokking-Artificial-Intelligence-Algorithms-Notebook/blob/main/Grokking_Artificial_Intelligence_Algorithms_Notebook.ipynb)
8+
59
## Requirements
610
* Python 3.7.0+
711
* Pip 3
812

913
## Setup
1014
Make sure that you have Python 3.7.0+ installed. [Download Python here](https://www.python.org/downloads/).
15+
pip3 should be installed with Python 3.7.0+ on macOS and Windows. You may need to install pip3 seperately if you're using Linux.
16+
Use the ```sudo apt-get install python3-pip``` command if you're using Ubuntu or Debian Linux.
17+
Use the ```sudo yum install python3-pip``` command if you're using Fedora Linux.
1118

1219
Clone this repository.
1320

ch01-intuition_of_ai/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Intelligence is a mystery. Intelligence is a concept that has no agreed upon def
44
This directory does not contain any code since there are no specific algorithm implementations discussed in Chapter 1.
55

66
## Summary
7-
![Chapter 1 summary](readme_assets/Ch1-Summary.png)
7+
![Chapter 1 summary](readme_assets/Ch1-Summary.png)

ch02-search_fundamentals/README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,21 @@ Think about when you explore things you want to learn. Some might look at a wide
77
![BFS and DFS](readme_assets/Bfs-Dfs-Combined.png)
88

99
## Summary
10-
![Chapter 2 summary](readme_assets/Ch2-Summary.png)
10+
![Chapter 2 summary](readme_assets/Ch2-Summary.png)
11+
12+
## What's Included
13+
- Breadth-first Search (BFS) and Depth-first Search (DFS) on a simple maze.
14+
- Problem representation and state expansion basics.
15+
16+
## Key Scripts
17+
- `uninformed_search/maze_bfs.py`: BFS over a grid maze.
18+
- `uninformed_search/maze_dfs.py`: DFS over a grid maze.
19+
- `uninformed_search/maze_puzzle.py`: Maze definition and utilities.
20+
21+
## How To Run
22+
- From this folder:
23+
- `python3 uninformed_search/maze_bfs.py`
24+
- `python3 uninformed_search/maze_dfs.py`
25+
26+
## Notes
27+
- Compare traversal order and path length differences between BFS and DFS.

ch03-intelligent_search/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,23 @@ Min-max search aims to build a tree of possible outcomes based on moves that eac
1717

1818
## Summary
1919
![Chapter 3 summary](readme_assets/Ch3-Summary.png)
20+
21+
## What's Included
22+
- A* search with heuristic guidance on a maze.
23+
- Adversarial search with min‑max and alpha‑beta pruning.
24+
25+
## Key Scripts
26+
- `informed_search/maze_astar.py`: A* pathfinding example.
27+
- `adversarial_search/connect_puzzle.py`: Game state mechanics.
28+
- `adversarial_search/connect_ai.py`: Min‑max AI for Connect.
29+
- `adversarial_search/connect_ai_alpha_beta_pruning.py`: Alpha‑beta optimized AI.
30+
- `adversarial_search/connect_puzzle_game.py`: Simple playable loop.
31+
32+
## How To Run
33+
- A*:
34+
- `python3 informed_search/maze_astar.py`
35+
- Connect AI demo:
36+
- `python3 adversarial_search/connect_puzzle_game.py`
37+
38+
## Notes
39+
- Try varying search depth in the adversarial AI to observe strength vs. speed trade‑offs.

ch03-intelligent_search/adversarial_search/connect_ai_alpha_beta_pruning.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def minmax(connect, depth, min_or_max, move, alpha, beta):
3838
best_score = INFINITY_NEGATIVE * min_or_max
3939
best_max_move = -1
4040
# Get possible moves given the board size
41-
moves = random.sample(range(0, connect.board_size_y + 1), connect.board_size_x)
41+
# Sample all possible column slots along the X dimension
42+
moves = random.sample(range(0, connect.board_size_x), connect.board_size_x)
4243
for slot in moves:
4344
neighbor = copy.deepcopy(connect)
4445
move_outcome = neighbor.play_move(slot)

ch03-intelligent_search/adversarial_search/connect_puzzle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def execute_move(self, player, slot_number):
133133

134134
# Execute a move for a player if there's space in the slot and choose the player based on whose turn it is
135135
def play_move(self, slot):
136-
if 0 <= slot <= 4:
136+
if 0 <= slot < self.board_size_x:
137137
if not self.is_slot_full(slot):
138138
if self.player_turn == PLAYERS[PLAYER_AI]:
139139
self.execute_move(PLAYER_AI, slot)

ch04-evolutionary_algorithms/README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,20 @@ The example used is the Knapsack Problem. The Knapsack Problem has number of ite
77
![Knapsack encoding](readme_assets/Knapsack_Encoding.png)
88

99
## Summary
10-
![Chapter 4 summary](readme_assets/Ch4-Summary.png)
10+
![Chapter 4 summary](readme_assets/Ch4-Summary.png)
11+
12+
## What's Included
13+
- Brute‑force and Genetic Algorithm (GA) solutions to the Knapsack problem.
14+
- Binary encoding of solutions, fitness evaluation, crossover, and mutation.
15+
16+
## Key Scripts
17+
- `knapsack_brute_force.py`: Exhaustive enumeration of feasible packs.
18+
- `knapsack_genetic_algorithm.py`: GA search with configurable hyperparameters.
19+
20+
## How To Run
21+
- From this folder:
22+
- `python3 knapsack_brute_force.py`
23+
- `python3 knapsack_genetic_algorithm.py`
24+
25+
## Notes
26+
- Adjust population size, mutation rate, and generations to see convergence behavior.

ch05-advanced_evolutionary_approaches/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,17 @@
22
Nothing to see here. Refer to the code in ch04-evolutionary-algorithms.
33

44
## Summary
5-
![Chapter 5 summary](readme_assets/Ch5-Summary.png)
5+
![Chapter 5 summary](readme_assets/Ch5-Summary.png)
6+
7+
## What's Included
8+
- Conceptual pointers beyond the basic GA (selection strategies, elitism, hybridization).
9+
- Code examples continue in Chapter 4’s folder.
10+
11+
## Key Scripts
12+
- Refer to Chapter 4 (`ch04-evolutionary_algorithms`).
13+
14+
## How To Run
15+
- See Chapter 4 run instructions.
16+
17+
## Notes
18+
- Use this chapter as a springboard to experiment with GA variants in `ch04`.

ch06-swarm_intelligence-ants/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,20 @@ The Ant Colony Optimization algorithm is inspired by the behavior of ants moving
77

88
## Summary
99
![Chapter 6 summary](readme_assets/Ch6-Summary.png)
10+
11+
## What's Included
12+
- Ant Colony Optimization (ACO) on a set of attractions with distances.
13+
- Pheromone trails, evaporation, and probabilistic path construction.
14+
15+
## Key Scripts
16+
- `carnival_brute_force.py`: Exhaustive tour construction for small instances.
17+
- `carnival_aco.py`: ACO solver with pheromone updates and evaporation.
18+
- CSV data: `attractions-*.csv` distance matrices.
19+
20+
## How To Run
21+
- From this folder:
22+
- `python3 carnival_brute_force.py`
23+
- `python3 carnival_aco.py`
24+
25+
## Notes
26+
- Tweak parameters (alpha, beta, evaporation rate, ant count) to see convergence on different datasets.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"""Chapter 6: Swarm Intelligence (Ants) package init."""
2+

0 commit comments

Comments
 (0)