Leanpub Header

Skip to main content

How AI works

How AI works
This book is 100% completeLast updated on 2026-11-18

Learn how AI really works: 184 algorithms, from k-means to Transformers, with every equation explained and two hand-solved examples each.

Minimum price

$29.00

$39.00

You pay

Author earns

$

Also available for 2 book credits with a Reader Membership

PDF
About

About

About the Book

AI is not magic. It is a set of clear, ingenious algorithms, and you can understand every one of them.

Most books about AI either skip the mathematics or assume you already know it. How AI Works does neither. It starts from zero (numbers, sums, vectors, probability, slopes) and climbs, one small step at a time, to the algorithms inside today's AI systems: search and planning, Bayesian networks and Kalman filters, regression, decision trees and gradient boosting, neural networks, Transformers, diffusion models, large language models, retrieval-augmented generation and reinforcement learning.

Every one of the 184 algorithms is explained the same way:

  • At a glance: the field, the year, the inventors and the idea in one line.
  • The idea in plain words: an everyday picture before any formula.
  • Every equation explained: each symbol defined, each formula read aloud in plain English.
  • At least two worked examples, solved by hand: small data sets, every intermediate number shown. Nothing is hidden or "left as an exercise".
  • Where you meet it in AI: which real systems use the algorithm, and for what.

A special focus on clustering. Grouping data without labels is one of the quiet workhorses of AI. The book explains 47 clustering algorithms and 26 ways to judge a clustering, then maps 119 places where clustering works inside modern AI: vector-database indexes, image and audio tokenisers, mixture-of-experts routing, self-supervised learning, data deduplication and single-cell biology.

What you get

  • 812 pages, 53 chapters in 12 parts, fully hyperlinked PDF (7 x 10 in)
  • 184 algorithms explained in full, each with at least two step-by-step examples
  • Catalogues of all 362 clustering algorithms and 1,276 AI algorithm entries, with links to the full explanations
  • Six chapters of mathematics from zero, a guide to every symbol and the Greek alphabet
  • An index of more than 650 terms

Every number is checked. Each number in each worked example was recomputed by a separate computer program before it went into the book.

What you will learn

  • Read any AI formula: sums, vectors, matrices, probabilities, gradients, each symbol explained from zero.
  • Understand how neural networks learn: backpropagation, optimizers, normalisation and initialisation.
  • See inside Transformers and LLMs: attention, sampling, beam search, RLHF, DPO and the KV cache.
  • Know how search engines and vector databases find things: BM25, PageRank, HNSW, IVF and RAG.
  • Master clustering: 47 algorithms, 26 quality measures, and 119 places it works inside real AI systems.
  • Recognise which algorithm fits which problem, and what its numbers mean.

Who this book is for

  • Complete beginners who want to understand AI properly, not just use it.
  • Students of computer science, data science, engineering or economics who need the mathematics explained.
  • Software developers moving into machine learning and AI engineering.
  • Product managers, analysts and technical leaders who must judge AI systems.
  • Teachers looking for small, fully worked examples to use in class.

No programming and no prior mathematics are required, just basic arithmetic, a pencil, paper and curiosity. When you finish, AI will no longer be a black box: you will know what happens inside, number by number.

Author

About the Author

Krzysztof Kołek

I'm a Full-stack .Net developer with over five years of commercial experience as a .Net developer. I'm happy to help with every problem that you are facing :)

Contents

Table of Contents

  • Preface
  • How to Read This Book
  • Part I. Mathematics from Zero
    • 1. Numbers, Variables and Functions
    • 2. The Language of Symbols
    • 3. Vectors and Distances
    • 4. Matrices
    • 5. Probability and Statistics
    • 6. Slopes and Gradients: Calculus for Learning
  • Part II. The Map of Artificial Intelligence
    • 7. What AI Is and How Machines Learn
  • Part III. Classical AI: Search, Games, Logic and Planning
    • 8. Search: Finding Paths and Solutions
    • 9. Games: Thinking Ahead Against an Opponent
    • 10. Logic and Reasoning
    • 11. Planning and Control
  • Part IV. Reasoning under Uncertainty
    • 12. Probabilistic Reasoning and Causality
  • Part V. Machine Learning
    • 13. Regression: Learning to Predict Numbers
    • 14. Classification: Learning to Decide
    • 15. Decision Trees and Ensembles
    • 16. Measuring How Well a Model Works
    • 17. Learning without Labels
  • Part VI. Clustering: The Core and Common Algorithms
    • 18. What Clustering Is
    • 19. Centroid-Based Clustering: the k-Means Family
    • 20. Vector Quantization: Clustering as Compression
    • 21. Soft, Robust and Categorical Clustering
    • 22. Hierarchical Clustering
    • 23. Density-Based Clustering
    • 24. Model-Based Clustering
    • 25. Graph-Based Clustering and Community Detection
    • 26. Neural and Deep Clustering
    • 27. Clustering with Labels, Time, Sequences and Pixels
  • Part VII. How Good Are the Clusters?
    • 28. Choosing the Number of Clusters
    • 29. Internal Validity Indices
    • 30. Cluster Tendency, Hierarchy Fit and Stability
    • 31. External Indices: Comparing with Known Answers
    • 32. Validity for Fuzzy and Graph Clusterings
  • Part VIII. Neural Networks and Deep Learning
    • 33. Artificial Neurons and Networks
    • 34. How Neural Networks Learn
    • 35. Convolutional Networks
    • 36. Networks with Memory: Recurrent Networks
    • 37. Attention and Transformers
    • 38. Graph Neural Networks
  • Part IX. Generative AI, Language Models and Retrieval
    • 39. Generative Models
    • 40. Language Processing Foundations
    • 41. Large Language Models
    • 42. Search, Retrieval and RAG
    • 43. Self-Supervised, Few-Shot and Federated Learning
  • Part X. Learning by Trial, Error and Evolution
    • 44. Reinforcement Learning
    • 45. Evolutionary and Swarm Algorithms
  • Part XI. AI in the Real World
    • 46. Computer Vision Building Blocks
    • 47. Speech and Audio
    • 48. Recommender Systems
    • 49. Time Series and Forecasting
    • 50. Explaining Model Decisions
    • 51. Making Models Small and Fast
    • 52. AI for Science
  • Part XII. Clustering Inside AI
    • 53. Clustering Inside AI: The Complete Map
  • Appendices
    • A. Catalog of All 362 Clustering Algorithms
    • B. Catalog of All 1,276 AI Algorithm Entries
    • C. Notation and Symbols
  • Index
  • How This Book Was Made

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub