Skip to content

Commit 90c7bd9

Browse files
authored
Merge pull request #140 from codeharborhub/dev-1
added content for calculus
2 parents e5c08eb + 28173a1 commit 90c7bd9

File tree

4 files changed

+281
-0
lines changed

4 files changed

+281
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: "Combinatorics - The Art of Counting"
3+
sidebar_label: Combinatorics
4+
description: "Mastering permutations, combinations, and counting principles essential for understanding probability, feature engineering, and model complexity."
5+
tags: [combinatorics, permutations, combinations, counting, discrete-math, mathematics-for-ml]
6+
---
7+
8+
**Combinatorics** is the study of counting, arrangement, and combination of elements within sets. In Machine Learning, we use combinatorics to estimate the size of a hypothesis space, calculate probabilities, and understand the complexity of feature interactions.
9+
10+
## 1. Fundamental Principles of Counting
11+
12+
Before diving into complex formulas, we must understand the two basic rules that govern all counting.
13+
14+
### A. The Multiplication Rule (Product Rule)
15+
If one task can be performed in $n$ ways and a second task can be performed in $m$ ways, then there are $n \times m$ ways to perform both tasks.
16+
17+
**ML Example:** If you have 3 types of optimizers and 4 different learning rates to test, you have $3 \times 4 = 12$ total hyperparameter configurations.
18+
19+
### B. The Addition Rule (Sum Rule)
20+
If one task can be performed in $n$ ways and another task in $m$ ways, and these tasks cannot be done at the same time, there are $n + m$ ways to choose one task.
21+
22+
## 2. Factorials ($n!$)
23+
24+
The factorial of a non-negative integer $n$ is the product of all positive integers less than or equal to $n$. It represents the number of ways to arrange $n$ distinct objects in a line.
25+
26+
$$
27+
n! = n \times (n-1) \times (n-2) \times \dots \times 1
28+
$$
29+
30+
31+
## 3. Permutations vs. Combinations
32+
33+
The most important distinction in combinatorics is whether the **order** of selection matters.
34+
35+
### A. Permutations (Order Matters)
36+
A permutation is an arrangement of items where the sequence is important. The number of ways to choose $r$ items from a set of $n$ items is:
37+
38+
$$
39+
P(n, r) = \frac{n!}{(n-r)!}
40+
$$
41+
42+
**Example:** Selecting a "First Place" and "Second Place" winner from a group of 10.
43+
44+
### B. Combinations (Order Does NOT Matter)
45+
A combination is a selection of items where the sequence is irrelevant. The number of ways to choose $r$ items from a set of $n$ items is:
46+
47+
$$
48+
C(n, r) = \binom{n}{r} = \frac{n!}{r!(n-r)!}
49+
$$
50+
51+
**ML Example (Feature Selection):** If you have 10 available features and you want to select a subset of 3 to train your model, there are $\binom{10}{3} = \frac{10!}{3!7!} = 120$ possible feature combinations.
52+
53+
## 4. Combinatorics in Machine Learning
54+
55+
### A. Hyperparameter Tuning (Grid Search)
56+
When performing a Grid Search, the number of models you need to train is the product of the number of values for each hyperparameter. If you have 5 hyperparameters with 10 values each, you are searching a space of $10^5$ combinations.
57+
58+
### B. Random Forests and Bagging
59+
In Random Forests, we often select a random subset of features for each split in a tree. Combinatorics allows us to calculate how many unique trees can be generated from a given feature set.
60+
61+
### C. Evaluation Metrics
62+
When calculating the **Confusion Matrix** (Precision, Recall), we are essentially counting occurrences of discrete events (True Positives, False Positives), which is rooted in combinatorial counting.
63+
64+
### D. Overfitting and Model Complexity
65+
The more "complex" a model is, the larger its **Hypothesis Space** (the set of all possible functions it can learn). Combinatorics helps quantify this space. If a decision tree has many possible splits, the number of possible tree structures grows factorially, increasing the risk of overfitting.
66+
67+
## 5. Binomial Coefficients and Pascal’s Triangle
68+
69+
The combination formula $\binom{n}{r}$ is also known as the **Binomial Coefficient**. It appears in the Binomial Distribution, which is fundamental to understanding binary classification error rates.
70+
71+
---
72+
73+
With the ability to count possibilities, we can now move to Graph Theory to see how these discrete elements can be connected to form complex networks.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: "Graph Theory Basics"
3+
sidebar_label: Graph Theory
4+
description: "Exploring the fundamentals of graph theory, including nodes, edges, adjacency matrices, and their applications in neural networks and Knowledge Graphs."
5+
tags: [graph-theory, discrete-math, networks, adjacency-matrix, mathematics-for-ml, gnn]
6+
---
7+
8+
In Machine Learning, we often need to model relationships between entities. **Graph Theory** provides the mathematical framework for representing and analyzing networks of interconnected data, from the structure of a Neural Network to the relationships in a social media dataset.
9+
10+
## 1. What is a Graph?
11+
12+
A graph $G = (V, E)$ consists of two sets:
13+
* **Vertices (Nodes) $V$:** The entities or points in the network (e.g., users, neurons, cities).
14+
* **Edges $E$:** The connections between the nodes (e.g., friendships, synaptic weights, roads).
15+
16+
## 2. Types of Graphs
17+
18+
The nature of the relationship determines the type of graph used:
19+
20+
| Type | Description | ML Application |
21+
| :--- | :--- | :--- |
22+
| **Undirected** | Edges have no direction (A-B is same as B-A). | Collaborative Filtering (User-Item similarity). |
23+
| **Directed (Digraph)** | Edges point from one node to another ($A \to B$). | **Neural Networks** (Information flows forward). |
24+
| **Weighted** | Edges have numerical values assigned to them. | **Weights in a Neural Network** or distances. |
25+
| **Cyclic / Acyclic** | Whether you can follow edges to return to a start node. | **Directed Acyclic Graphs (DAGs)** are used in computation pipelines. |
26+
27+
## 3. Representing Graphs Mathematically
28+
29+
To process graphs with algorithms, we must represent them as numbers or matrices.
30+
31+
### A. Adjacency Matrix
32+
A square matrix where the entry $A_{ij}$ is 1 if there is an edge between node $i$ and node $j$, and 0 otherwise.
33+
34+
* **Symmetric:** For undirected graphs.
35+
* **Asymmetric:** For directed graphs.
36+
37+
### B. Adjacency List
38+
A collection of lists where each node has a list of the other nodes it is connected to. This is more memory-efficient for **sparse graphs** (where most nodes aren't connected).
39+
40+
## 4. Graph Theory in Machine Learning
41+
42+
### A. Neural Network Architecture
43+
A Neural Network is a directed, weighted graph. The neurons are nodes, and the weights are the directed edges. Training the network is essentially updating the weights (edge values) of this graph.
44+
45+
### B. Knowledge Graphs
46+
Companies like Google and Meta use Knowledge Graphs to store facts about the world. Entities (like "Albert Einstein") are nodes, and relationships (like "Born In") are edges. This allows for advanced reasoning and semantic search.
47+
48+
### C. Graph Neural Networks (GNNs)
49+
GNNs are a class of deep learning models designed to perform inference on data described by graphs. They are used for:
50+
* **Molecular Discovery:** Atoms are nodes, bonds are edges.
51+
* **Fraud Detection:** Detecting suspicious patterns in transaction networks.
52+
* **Recommendation Systems:** Predicting new edges (purchases) between User nodes and Item nodes.
53+
54+
## 5. Key Graph Algorithms
55+
56+
* **Shortest Path (Dijkstra’s):** Used in routing and logistics.
57+
* **PageRank:** The original algorithm behind Google Search, which ranks nodes based on their "importance" in the network.
58+
* **Community Detection:** Finding clusters of nodes that are more densely connected to each other than to the rest of the network (Clustering).
59+
60+
---
61+
62+
This concludes our module on Discrete Mathematics. You now have the tools for logic, counting, and networking. Next, we enter the final and most critical pillar of ML mathematics: Probability and Statistics.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: "Logic and Boolean Algebra"
3+
sidebar_label: Logic
4+
description: "Exploring propositional logic, logical operators, and Boolean algebra as the basis for decision-making algorithms and binary classification."
5+
tags: [logic, boolean-algebra, discrete-math, truth-tables, decision-trees, binary-logic]
6+
---
7+
8+
At the most granular level, computers and Machine Learning algorithms operate on **Logic**. Whether it's a Decision Tree splitting data based on a condition or a Neural Network using a step function, **Propositional Logic** and **Boolean Algebra** are the tools used to formalize these decisions.
9+
10+
## 1. Propositional Logic
11+
12+
A **proposition** is a declarative statement that is either **True (T)** or **False (F)**. In ML, we often use propositions to evaluate features.
13+
14+
* **Example Proposition ($P$):** "The house has more than 3 bedrooms."
15+
* **Example Proposition ($Q$):** "The price is less than $500,000."
16+
17+
### Logical Operators
18+
We combine propositions using logical operators to create complex decision boundaries.
19+
20+
| Operator | Symbol | Meaning | ML Context |
21+
| :--- | :--- | :--- | :--- |
22+
| **AND** | $\land$ | Both must be true. | Feature A > 10 **AND** Feature B < 5. |
23+
| **OR** | $\lor$ | At least one must be true. | If Category is "Dog" **OR** "Cat", then "Pet". |
24+
| **NOT** | $\neg$ | Reverses the value. | If **NOT** (Missing Value). |
25+
| **XOR** | $\oplus$ | Exactly one is true. | Binary features that are mutually exclusive. |
26+
27+
## 2. Truth Tables
28+
29+
A truth table lists all possible combinations of inputs and the resulting output. This is the simplest way to visualize a discrete function.
30+
31+
**Example: The AND ($\land$) Operator**
32+
33+
| $P$ | $Q$ | $P \land Q$ |
34+
| :--- | :--- | :--- |
35+
| T | T | **T** |
36+
| T | F | F |
37+
| F | T | F |
38+
| F | F | F |
39+
40+
## 3. Boolean Algebra in Machine Learning
41+
42+
Boolean Algebra is the branch of mathematics that deals with variables that have two values: $\{0, 1\}$.
43+
44+
### A. Binary Classification
45+
In binary classification, our target variable $y$ is a Boolean. We use logic to determine the threshold:
46+
If $P(\text{Class}=1) > 0.5$, then **True**, else **False**.
47+
48+
### B. Decision Trees
49+
Decision Trees are essentially a nested series of logical "IF-THEN-ELSE" statements. Each node in the tree evaluates a logical proposition to route the data down the correct branch.
50+
51+
### C. Logic Gates in Neural Networks
52+
Early models of artificial neurons (the McCulloch-Pitts neuron) were designed to mimic logic gates. By adjusting weights and thresholds, a single neuron can be made to act as an AND gate or an OR gate.
53+
54+
## 4. Conditional and Bi-conditional Logic
55+
56+
* **Implication ($P \implies Q$):** "If $P$, then $Q$." This forms the basis of Rule-Based Systems and Expert Systems.
57+
* **Equivalence ($P \iff Q$):** "$P$ if and only if $Q$." This is used to define identical behaviors in different models.
58+
59+
:::tip Logic and Regularization
60+
In some forms of logic-based learning, we use **Inductive Logic Programming (ILP)** to learn formal rules from data, rather than just adjusting numerical weights.
61+
:::
62+
63+
## 5. Boolean Minimization
64+
In large-scale systems, we use Boolean Algebra laws (like De Morgan's Laws) to simplify complex logical expressions. This is similar to how we optimize code or simplify mathematical models to make them more efficient.
65+
66+
* **De Morgan's Law 1:** $\neg(P \land Q) \iff (\neg P \lor \neg Q)$
67+
* **De Morgan's Law 2:** $\neg(P \lor Q) \iff (\neg P \land \neg Q)$
68+
69+
---
70+
71+
Now that we understand sets and the logic to navigate them, we can explore Graph Theory, which is how we model complex relationships and networks.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
title: "Sets and Relations"
3+
sidebar_label: Sets & Relations
4+
description: "Exploring the fundamentals of Set Theory and Relations, and how these discrete structures underpin data categorization and recommendation systems in Machine Learning."
5+
tags: [discrete-math, sets, relations, mathematics-for-ml, logic, data-structures]
6+
---
7+
8+
Discrete Mathematics deals with distinct, separated values rather than continuous ranges. **Set Theory** is the language we use to group these values, and **Relations** describe how these groups interact. In Machine Learning, these concepts are vital for everything from defining probability spaces to building database schemas for training data.
9+
10+
## 1. Set Theory Fundamentals
11+
12+
A **Set** is an unordered collection of distinct objects, called elements.
13+
14+
### Notation
15+
* $A = \{1, 2, 3\}$ : A set containing numbers 1, 2, and 3.
16+
* $x \in A$ : $x$ is an element of set $A$.
17+
* $\emptyset$ : An empty set.
18+
* $\mathbb{R}, \mathbb{Z}, \mathbb{N}$ : Sets of Real numbers, Integers, and Natural numbers.
19+
20+
:::tip Common Sets in ML
21+
* **$\mathbb{R}$ (Real Numbers):** Used for continuous features like height, price, or weight.
22+
* **$\mathbb{Z}$ (Integers):** Used for count-based data (e.g., number of clicks).
23+
* **$\{0, 1\}$ (Binary Set):** The standard output set for binary classification.
24+
* **$\{C_1, C_2, \dots, C_k\}$ (Categorical Set):** The labels for multi-class classification.
25+
:::
26+
27+
### Key Operations
28+
The interaction between sets is often visualized using **Venn Diagrams**.
29+
30+
* **Union ($A \cup B$):** Elements in $A$, or $B$, or both. (Equivalent to a logical `OR`).
31+
* **Intersection ($A \cap B$):** Elements present in both $A$ and $B$. (Equivalent to a logical `AND`).
32+
* **Difference ($A \setminus B$):** Elements in $A$ that are not in $B$.
33+
* **Complement ($A^c$):** Everything in the universal set that is *not* in $A$.
34+
35+
:::tip Sets in ML
36+
In classification tasks, the **Label Space** is a set. For a cat/dog classifier, the set of possible outputs is $Y = \{\text{Cat}, \text{Dog}\}$. When evaluating models, we often look at the **Intersection** of predicted labels and true labels to calculate accuracy.
37+
:::
38+
39+
## 2. Cartesian Products
40+
41+
The Cartesian Product of two sets $A$ and $B$, denoted $A \times B$, is the set of all possible ordered pairs $(a, b)$.
42+
43+
$$
44+
A \times B = \{ (a, b) \mid a \in A \text{ and } b \in B \}
45+
$$
46+
47+
If $A$ represents "Users" and $B$ represents "Movies," $A \times B$ represents every possible interaction between every user and every movie. This is the foundation of **Utility Matrices** in Recommender Systems.
48+
49+
## 3. Relations
50+
51+
A **Relation** $R$ from set $A$ to set $B$ is simply a subset of the Cartesian product $A \times B$. It defines a relationship between elements of the two sets.
52+
53+
### Types of Relations
54+
In ML, we specifically look for certain properties in relations:
55+
* **Reflexive:** Every element is related to itself.
56+
* **Symmetric:** If $a$ is related to $b$, then $b$ is related to $a$ (e.g., "Similarity" in clustering).
57+
* **Transitive:** If $a \to b$ and $b \to c$, then $a \to c$.
58+
59+
### Binary Relations and Graphs
60+
Relations are often represented as **Directed Graphs**. If $(a, b) \in R$, we draw an arrow from node $a$ to node $b$.
61+
62+
## 4. Why this matters in Machine Learning
63+
64+
### A. Data Preprocessing
65+
When we perform "One-Hot Encoding" or handle categorical variables, we are mapping elements from a discrete set of categories into a numerical space.
66+
67+
### B. Knowledge Graphs
68+
Modern AI often uses **Knowledge Graphs** (like those powering Google Search). These are massive sets of entities connected by relations (e.g., `(Paris, is_capital_of, France)`).
69+
70+
### C. Formal Logic in AI
71+
Sets and relations form the basis of predicate logic, which is used in "Symbolic AI" and for defining constraints in optimization problems.
72+
73+
---
74+
75+
Now that we can group objects into sets and relate them, we need to understand the logic that allows us to make valid inferences from these groups.

0 commit comments

Comments
 (0)