Skip to content

Commit

Permalink
[proj2] implement Softmax
Browse files Browse the repository at this point in the history
  • Loading branch information
N0-man committed Jul 13, 2024
1 parent fa56365 commit db420bc
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 4 deletions.
132 changes: 131 additions & 1 deletion Project 2 Digit Recognition/mnist/mnist.ipynb

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions Project 2 Digit Recognition/mnist/part1/softmax.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,20 @@ def compute_probabilities(X, theta, temp_parameter):
Returns:
H - (k, n) NumPy array, where each entry H[j][i] is the probability that X[i] is labeled as j
"""
#YOUR CODE HERE
raise NotImplementedError
# Compute the scaled dot product: (n, d) dot (k, d).T -> (n, k)
scaled_scores = np.dot(X, theta.T) / temp_parameter

# Prevent numerical overflow by subtracting the max score from each score
scaled_scores -= np.max(scaled_scores, axis=1, keepdims=True)

# Exponentiate the adjusted scores
exp_scores = np.exp(scaled_scores)

# Normalize the scores to get probabilities: (n, k)
probabilities = exp_scores / np.sum(exp_scores, axis=1, keepdims=True)

# Transpose to match the expected output shape (k, n)
return probabilities.T

def compute_cost_function(X, Y, theta, lambda_factor, temp_parameter):
"""
Expand Down
Binary file added Unit 2/slides/Softmax/softmax_5_levels.pdf
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion catchup.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
- Homework: Homework 1 (write python for all problems)
- Project 1: Classification accuracy of each algorithm do not match with expectation (5,7,8 and 9)
- extra assignments at the end of Project 1 (9 Feature Engineering)
- Eigenvalues, Eigenvectors and Determinants (Unit 0 - Optional)
- Softmax 5 Prespective videos and notes (Project 2, section 4, "Multinomial (Softmax) Regression and Gradient Descent")

0 comments on commit db420bc

Please sign in to comment.