AI

Basic Probability

Basic Probability #

Probability models uncertainty: what you don’t know yet, but want to reason about.

Key takeaway: Probability is a number between 0 and 1 that measures how likely an event is. The whole topic is about defining events clearly and applying a few core rules consistently.

Probability quantifies uncertainty: a number between 0 and 1.

  • 0 means: impossible
  • 1 means: certain

Terminology #

Random experiment #

A random experiment is an action whose outcome is not known in advance.

Neural Networks

Neural Networks #

  • A network of artificial neurons inspired by how neurons function in the human brain.
  • At its core - a mathematical model designed to process and learn from data.
  • Neural networks form the foundation of Deep Learning (involves training large and complex networks on vast amounts of data).

flowchart LR
 subgraph subGraph0["Input Layer"]
        I1(("Input 1"))
        I2(("Input 2"))
        I3(("Input 3"))
  end
 subgraph subGraph1["Hidden Layer"]
        H1(("Hidden 1"))
        H2(("Hidden 2"))
        H3(("Hidden 3"))
  end
 subgraph subGraph2["Output Layer"]
        O(("Output"))
  end
    I1 --> H1 & H2 & H3
    I2 --> H1 & H2 & H3
    I3 --> H1 & H2 & H3
    H1 --> O
    H2 --> O
    H3 --> O

    style I1 fill:#C8E6C9
    style I2 fill:#C8E6C9
    style I3 fill:#C8E6C9
    style H1 stroke:#2962FF,fill:#BBDEFB
    style H2 fill:#BBDEFB
    style H3 fill:#BBDEFB
    style O fill:#FFCDD2
    style subGraph0 stroke:none,fill:transparent
    style subGraph1 stroke:none,fill:transparent
    style subGraph2 stroke:none,fill:transparent

Structure of a Neural Network #

A typical neural network has three main layers:

Conditional Probability & Bayes’ Theorem

Conditional Probability & Bayes’ Theorem #

Probability often changes when we learn new information.

Conditional probability and Bayes’ theorem give a structured way to update beliefs using evidence.

Conditional probability updates probabilities after observing an event.

Bayes’ theorem lets you estimate a hidden cause from observed evidence.

Naïve Bayes turns Bayes’ theorem into a practical classifier by assuming conditional independence of features given the class.


flowchart TD

A[Conditional<br/>probability] -->|foundation| B[Bayes<br/>theorem]
D[Independent<br/>events] -->|implies| C[Independence]
C -->|simplifies| A

E[Prior] -->|with likelihood| B
F[Likelihood] -->|updates| H[Posterior]
G[Evidence] -->|normalises| B
B -->|yields| H

I[Naïve<br/>Bayes] -->|uses| B
J[Naïve<br/>assumption] -->|assumes| C
K[Features] -->|given class| J
L[Class] -->|conditions| J
I -->|predicts| M[Classification]
M -->|selects| L

style A fill:#90CAF9,stroke:#1E88E5,color:#000
style B fill:#90CAF9,stroke:#1E88E5,color:#000
style C fill:#90CAF9,stroke:#1E88E5,color:#000

style D fill:#CE93D8,stroke:#8E24AA,color:#000
style E fill:#CE93D8,stroke:#8E24AA,color:#000
style F fill:#CE93D8,stroke:#8E24AA,color:#000
style G fill:#CE93D8,stroke:#8E24AA,color:#000
style J fill:#CE93D8,stroke:#8E24AA,color:#000
style K fill:#CE93D8,stroke:#8E24AA,color:#000
style L fill:#CE93D8,stroke:#8E24AA,color:#000

style H fill:#C8E6C9,stroke:#2E7D32,color:#000
style I fill:#C8E6C9,stroke:#2E7D32,color:#000
style M fill:#C8E6C9,stroke:#2E7D32,color:#000


Quick summary #

  • Conditional probability: updates probability after an event is known.
  • Multiplication rule: computes joint probability from conditional parts.
  • Independence: tested using \( P(A\cap B)=P(A)P(B) \) .
  • Total probability: breaks a probability into weighted cases.
  • Bayes’ theorem: reverses conditioning to infer causes from evidence.

What’s next #

Probability Distributions
Move from events to random variables and distributions.

AI Stack

AI Stack #

The AI Stack describes the layers required to build an end-to-end AI system, from infrastructure at the bottom to user-facing applications at the top.

Different organisations represent the AI stack differently; this is a simplified conceptual view for learning.

Each layer depends on the one below it.


graph TB

    subgraph APP["Applications"]
        A[User Interfaces & Integrations]
    end

    subgraph ORCH["Orchestration"]
        O[Workflows • Agents • Control Logic]
    end

    subgraph DATA["Data"]
        D[Data Sources • Pipelines • Vector DBs]
    end

    subgraph MODEL["Models"]
        M[ML • DL • Foundation Models • LLMs]
    end

    subgraph INFRA["Infrastructure"]
        I[Cloud • On-prem • GPUs • Storage]
    end

    %% Styling
    style APP fill:#FFCCBC
    style ORCH fill:#90CAF9
    style DATA fill:#BBDEFB
    style MODEL fill:#C8E6C9
    style INFRA fill:#E1F5FE

    style A fill:#FFE0B2
    style O fill:#B3E5FC
    style D fill:#E3F2FD
    style M fill:#DCEDC8
    style I fill:#E1F5FE

1. Infrastructure #

The foundation that provides compute and storage.

Artificial Neuron and Perceptron

Artificial Neuron and Perceptron #

knowledge in neural networks is stored in connection weights, and learning means modifying those weights.


Biological Neuron #

A biological neuron is a specialised cell that processes and transmits information through electrical and chemical signals.

Core components:

  • Dendrites: receive signals from other neurons
  • Cell body (soma): processes incoming signals
  • Axon: transmits the output signal
  • Synapses: connection points between neurons

Biological intuition:

  • many inputs arrive to one neuron
  • one neuron can connect out to many neurons
  • massive parallelism enables fast perception and recognition

Artificial Neuron #

An artificial neuron is a simplified computational model inspired by biological neurons.

Intelligent Agents and Environments

Intelligent Agents and Environments #

An intelligent agent connects perception with action. It observes an environment through sensors, uses the information it receives to decide what to do, and affects the environment through actuators.

This page develops the core vocabulary for reasoning about intelligent agents: percepts, actions, rationality, performance measures, PEAS and the different properties an environment can have.

  • Intelligent Agents: Notion of Agents and Environments, Rationality
  • Nature of Environments, Structure of Agents

Learning Objectives #

  • explain the relationship between an agent and its environment
  • distinguish sensors, percepts, actions and actuators
  • explain percept sequences and the agent function
  • describe what makes an agent rational
  • distinguish rationality from omniscience
  • compare the five basic agent architectures
  • specify a task environment using PEAS
  • classify environments using standard AI properties
  • explain why environment properties affect agent design

Big Picture #

flowchart TD
    E["Environment"] -->|Percepts| S["Sensors"]
    S --> A["Agent"]
    A --> C["Actuators"]
    C -->|Actions| E

    style E fill:#E1F5FE
    style S fill:#FFF9C4
    style A fill:#C8E6C9
    style C fill:#EDE7F6

Think of an agent as a continuous loop: observe → decide → act → observe again. An action may change the environment, so the next observation may be different.

M2: Distributed ML Algorithms

M2: Distributed ML Algorithms #

This module applies parallel and distributed computing to ML algorithms. It examines how to divide computation, combine results, and balance communication against useful work during training.

Module coverage:

  • Parallel ML Algorithms: CNNs, gradient descent and SGD, SVM, k-means, k-nearest neighbours, decision trees, and random forests.
  • Distributed Training Strategies: data parallelism, model parallelism, pipeline parallelism, gradient checkpointing, and mixed-precision training.

Learning Objectives #

  • Decompose ML algorithms into independent and dependent work.
  • Explain how local results are aggregated and where communication is required.
  • Compare distributed execution through Hadoop and Spark.
  • Choose training strategies that address compute and memory constraints.

Pages #

ChapterPageMain focus
4Parallelisation of ML AlgorithmsProblem decomposition, ensembles, XGBoost, k-means, trees, forests, and SVM
5Communication-Aware Distributed MLCommunication overhead, distributed k-means and k-NN, model parallelism, and SGD
6Clusters, Hadoop, and SparkCluster frameworks, MapReduce k-means, distributed CNNs, and communication reduction
7Distributed Training StrategiesData, model, and pipeline parallelism, checkpointing, and mixed precision

Topic Outline #

4. Parallelisation of ML Algorithms #

  • Problem decomposition and parallelisation
  • Ensemble methods and XGBoost on CPUs
  • k-means
  • Distributed decision trees and random forests
  • Distributed implementations using Spark ML and XGBoost
  • Parallel SVM kernel computation using block-wise and MapReduce-style methods

5. Communication-Aware Distributed ML #

  • Communication overhead in distributed algorithms
  • Distributed k-means and model parallelism
  • k-NN: data partitioning, locality-sensitive hashing, and distributed indexing
  • KD-tree and Ball-tree indexing versus brute-force MapReduce
  • Accuracy–latency trade-offs in approximate k-NN
  • Gradient descent and SGD: mini-batch, synchronous, and asynchronous variants

6. Clusters, Hadoop, and Spark #

  • Cluster computing with Hadoop and Spark
  • Lloyd’s k-means algorithm in MapReduce
  • Mini-batch k-means and streaming variants
  • Convergence criteria and communication reduction through compressed updates
  • CNN data and model parallelism, including layer splitting and tensor slicing
  • Mixed precision, pipeline parallelism, and distributed training frameworks

7. Distributed Training Strategies ☆ #

  • Data parallelism
  • Model parallelism
  • Pipeline parallelism
  • Gradient checkpointing
  • Mixed-precision training

How This Module Connects #

Use M1: Foundations to interpret complexity and speedup. Continue to M3: Scale-Out Systems for the platforms and communication mechanisms that support larger training runs.

ML Workflow

Machine learning Workflow #

Data is the foundation of any machine learning system. Quality of data matters more than model complexity.

Role of Data #

Data determines:

  • What patterns the model can learn
  • How well it generalises
  • Whether bias or noise is introduced

Bad data → bad model (even with perfect algorithms).


Data Preprocessing, wrangling #

Raw data is never ready for training.

Data Issues

  • Noise
    • For objects, noise is an extraneous object
    • For attributes, noise refers to modification of original values
    • Use Log or Z Transfer to convert to mean
  • Outliers
    • Data objects with characteristics that are considerably different than most of the other data objects in the data set
    • Handle: Use IQR method
    • Find Lower and Upper Bound and replace Outlier with Lower or Upper Bound
  • Missing Values
    • Eliminate data objects or variables
    • Handle: Estimate missing values
      • Mean, Median or Mode
      • Prefer Median if there are missing outliers
    • Ignore the missing value during analysis
  • Duplicate Data
    • Major issue when merging data from heterogeneous sources
  • Inconsistent Codes
    • Find all Unique and transfer all inconsistent to

Data Preprocessing techniques

Multi-Armed Bandit Problem

Multi-Armed Bandit Problem #

The Multi-Armed Bandit (MAB) problem is the simplest setting for studying decision-making under uncertainty.

An agent repeatedly chooses one of \( k \) actions. Each action produces a numerical reward drawn from an unknown distribution. The objective is to maximise the expected total reward over time.

The central challenge is deciding when to exploit current knowledge and when to explore uncertain alternatives.
  • Multi-armed Bandit Problem - Motivation and Problem Statement
  • Incremental solution to the stationary & non-stationary MAB problems
  • Exploration vs. Exploitation trade-off
  • Bandit Gradient Algorithm as Stochastic Gradient Ascent
  • Associative Search

The k-Armed Bandit Problem ☆ #

At every time step:

Parallel and Distributed Algorithms

Parallel and Distributed Algorithms #

Parallelisation divides computational work into parts that can execute concurrently. The purpose is to reduce completion time or increase throughput, but the gain depends on how much work is genuinely independent and how much overhead is introduced.

Course coverage:

  1. Systems and performance: execution time, throughput, efficiency, and bottlenecks
  2. Speedup—approaches and issues: Amdahl’s Law, serial work, overhead, and load imbalance
  3. Data parallelism versus task parallelism versus request parallelism
  4. Scale-out clusters: communication cost and its impact on speedup

The worked algorithms also show how divide-and-conquer and matrix operations expose parallel work.