# CHAPTER 6: ARTIFICIAL INTELLIGENCE

## 6.1 INTRODUCTION TO AI

### 6.1.1 Definition

**Artificial Intelligence:** The ability of computers to perform tasks that usually only humans would be able to do (decision-making, speech recognition, etc.).

**Machine Learning (ML):** A subfield of AI where computers learn to perform tasks without being explicitly programmed. Uses historical training data to produce a model for predictions.

**Deep Learning (DL):** A subset of ML where computers learn using neural networks similar to human brain function.

### 6.1.2 Types of Machine Learning

**Supervised Learning:**

- Trained on labelled data
- Known inputs and outputs
- Model learns from examples
- Used for classification and regression

**Unsupervised Learning:**

- Trained on unlabelled data
- Finds hidden patterns
- Groups similar data
- Used for clustering

**Reinforcement Learning:**

- Reward-based system
- Agent learns from actions
- Not given specific instructions
- Learns from trial and error

### 6.1.3 Classification, Regression, and Clustering

**Classification:**

- Split data into predefined groups
- Example: Spam/not spam email

**Regression:**

- Predict value based on explanatory variable
- Used for forecasting
- Examples: Weather, sales, prices

**Clustering:**

- Split data into groups based on features
- Groups not predefined
- Used for pattern discovery

---

## 6.2 ARTIFICIAL NEURAL NETWORKS

### 6.2.1 Structure

**Layers:**

1. **Input Layer:** Accepts inputs in various formats
2. **Hidden Layers:** Perform calculations, find patterns
3. **Output Layer:** Provides results

**Nodes:**

- Connected to nodes in adjacent layers
- Each connection has weight
- Data passes through network

### 6.2.2 Back Propagation

**Definition:** "Backward propagation of errors" - standard method for training neural networks.

**Process:**

1. Input data fed to network
2. Network generates output
3. Output compared to expected result
4. Error calculated
5. Error propagated backwards through network
6. Weights adjusted
7. Process repeated until acceptable error

### 6.2.3 Graph Theory in AI

**Graph Components:**

- **Nodes:** Fundamental units (represent objects)
- **Edges:** Lines connecting nodes (represent relationships)

**Real-World Uses:**

- Social media (users as nodes, friendships as edges)
- Google Maps (locations as nodes, roads as edges)

**In AI:**

- Represent ANN structure
- Find paths in problem solving
- Algorithms examine graphs

---

## 6.3 GRAPH SEARCH ALGORITHMS

### 6.3.1 Dijkstra's Algorithm

**Purpose:** Find shortest path between nodes in weighted graph.

**How It Works:**

1. Start at initial node
2. Calculate distances to all connected nodes
3. Select node with smallest distance
4. Update distances through that node
5. Repeat until destination reached

**Limitations:**

- No heuristics (searches all directions)
- Inefficient on large networks
- Cannot handle negative weights

### 6.3.2 A\* Algorithm

**Purpose:** Informed search algorithm using heuristics to find shortest path efficiently.

**Formula:**

<div class="sc-zOxLx iJoNFs code-block" id="bkmrk-%3Ctext%3E-f-%3D-g-%2B-h" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; position: relative; width: 647px; min-width: 35ch;"><div class="sc-cgHfjM iurpwe" style="box-sizing: border-box; font-weight: bold; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px 10px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; display: flex; align-items: center; color: rgb(0, 0, 0); font-size: 14px; line-height: 1; border-top-left-radius: 8px; border-top-right-radius: 8px; height: 34px; background-color: rgb(238, 238, 238);">&lt;TEXT&gt;</div><div class="sc-iQqcaB jMJkfu" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; position: sticky; top: 28px; z-index: 10;"><div class="sc-kcLKEh sc-dntSTA sc-dFVmKS sc-fcSHUR kIsGeY jNoXSY cklChQ kmrhIw code-toolbar" style="box-sizing: border-box; font-weight: normal; border: none; margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; width: auto; height: 24px; flex: 0 0 auto; inset: auto 0.5rem 0.3rem auto; opacity: 0; border-radius: 4px; gap: 4px; display: flex; justify-content: flex-start; align-items: center; flex-direction: row; position: absolute; background-color: rgb(238, 238, 238); transition: opacity 0.2s; transform: translateZ(0px); will-change: opacity;">  
</div></div><div class="sc-fpikKz lhQggy split-view-wrapper" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; display: flex; border-radius: 0px 0px 8px 8px;"><div class="shiki one-light code-viewer source-view shiki-light" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; font-family: "', 'Cascadia Code', 'Fira Code", Consolas, Menlo, Courier, monospace; line-height: initial; --color-scrollbar-thumb: rgba(0, 0, 0, 0.15); --color-scrollbar-thumb-hover: rgba(0, 0, 0, 0.2); flex: 1 1 auto; width: 647px; border-radius: inherit; background-color: rgb(250, 250, 250); color: rgb(56, 58, 66);"><div class="sc-jCWzJg ednTDb shiki-scroller" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0.5em 0px 0.5em 1em; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; display: block; overflow: auto hidden; position: relative; border-radius: inherit; --gutter-width: 0ch; font-size: 13px;"><div class="shiki-list" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; height: 21px; width: 634px; position: relative;"><div style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; position: absolute; top: 0px; left: 0px; width: 634px; transform: translateY(0px);"><div data-index="0" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent;"><div class="line" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; display: flex; align-items: flex-start; width: 634px; line-height: 21px; contain: none; will-change: auto;"><span class="line-content" style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px 1em 0px 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; white-space: pre; flex: 1 1 0%;"><span style="box-sizing: border-box; font-weight: normal; border: 0px solid oklch(0.92 0.004 286.32); margin: 0px; padding: 0px; outline-color: oklab(0.705 0.00415142 -0.0144141 / 0.5); -webkit-tap-highlight-color: transparent; white-space: pre; overflow-wrap: normal;">F = G + H</span></span></div></div></div></div></div></div></div></div>- G: Movement cost from start
- H: Heuristic (estimated cost to goal)
- F: Total estimated cost

**Advantages over Dijkstra:**

- Uses heuristics to guide search
- More efficient
- Finds goal faster