# mlai-textbooks

`pip install mlai-textbooks` → `import ml_ai_library`

Textbook ML/AI algorithms from **Bishop PRML** and **Norvig AIMA** — every
algorithm delegates to an established library as its numerical engine. No
hand-rolled subroutines.

| Module | Algorithms | Backed by |
|---|---|---|
| `bishop.linear_models` | Bayesian LR, Logistic IRLS, RVM | sklearn, numpy |
| `bishop.sampling` | Rejection, Importance, MH, Gibbs, Ensemble MCMC | emcee, scipy |
| `bishop.sequential` | Kalman Filter, RTS Smoother, Particle Filter | scipy.linalg, numpy |
| `bishop.mixture_models` | GMM, Bayesian GMM, K-Means | sklearn |
| `bishop.dimensionality` | PCA, Kernel PCA, Factor Analysis, t-SNE | sklearn |
| `bishop.kernel_methods` | GP Regression, SVM, Kernel PCA | sklearn |
| `bishop.neural_networks` | MLP, CNN, RNN, VAE, GAN | PyTorch |
| `norvig.search` | BFS, DFS, IDDFS, UCS, A\*, Greedy, Beam | networkx |
| `norvig.csp` | Backtracking, AC-3 | python-constraint2 |
| `norvig.logic` | PropKB (TELL/ASK), Unify, FOL-BC | sympy |
| `norvig.adversarial` | Minimax, Alpha-Beta, MCTS | mcts |
| `norvig.mdp` | Value Iteration, Policy Iteration | numpy |
| `norvig.nlp` | N-Gram LM, CYK Parser, Viterbi POS | nltk |
| `norvig.game_theory` | Nash Equilibria, Maximin, Dominant Strategy | nashpy |
| `norvig.planning` | STRIPS, HTN Planning | (pure Python) |
| `norvig.rl` | Q-Learning, SARSA, REINFORCE | gymnasium, PyTorch |
| `llm_agents.*` | ReAct, Planning, Logic, RL-Policy, Multi-Agent | litellm |

## Quick Start

```python
# A* search using networkx internally
from ml_ai_library.norvig.search import GraphProblem, astar_search
import networkx as nx
G = nx.DiGraph()
G.add_edge('A', 'B', weight=1); G.add_edge('B', 'C', weight=2)
node = astar_search(GraphProblem(G, 'A', 'C'))
print(node.solution())   # ['B', 'C']

# Nash equilibria via nashpy
from ml_ai_library.norvig.game_theory import NormalFormGame, nash_equilibria
import numpy as np
game = NormalFormGame(np.array([[3,0],[5,1]]), np.array([[3,5],[0,1]]))
print(nash_equilibria(game))

# Ensemble MCMC via emcee
from ml_ai_library.bishop.sampling import emcee_sample
samples = emcee_sample(lambda x: -0.5 * x @ x, ndim=2, n_steps=500)

# Kalman filter via scipy.linalg
from ml_ai_library.bishop.sequential import KalmanFilter
import numpy as np
kf = KalmanFilter(F=np.eye(2), H=np.eye(2),
                  Q=0.01*np.eye(2), R=0.1*np.eye(2),
                  x0=np.zeros(2), P0=np.eye(2))
means, covs = kf.filter(observations)

# LLM ReAct agent
from ml_ai_library.llm_agents.react_agent import ReActAgent
agent = ReActAgent(model="gpt-4o-mini")
print(agent.run("What is 2+2?"))
```

## License

MIT
