softmax

#math
Softmax is a mathematical function that converts a vector of real numbers into a probability distribution. It is commonly used in machine learning and statistics, especially in tasks where you want to interpret the outputs of a model as probabilities.

Given an input vector (z=(z1,z2,,zk)) of ( k ) real numbers, the softmax function computes the output vector (σ(z)=(σ(z1),σ(z2),,σ(zk))) where each component (σ(zi)) is calculated as follows:

[σ(zi)=ezij=1kezj]

In other words:

[σ(zi)=eziez1+ez2++ezk]

Here's a step-by-step breakdown of how softmax works:

  1. Exponentiation: Compute the exponential of each element in the input vector ( z ). This results in a new vector .
(ez=(ez1,ez2,,ezk))
  1. Summation: Calculate the sum of all elements in the new vector (ez), denoted as (j=1kezj).

  2. Normalization: For each element (zi) in the input vector (z), divide (ezi) by the sum (j=1kezj) obtained in the previous step. This normalization ensures that the output vector (σ(z)) represents a valid probability distribution, where each element is between 0 and 1, and the sum of all elements is equal to 1.

The softmax function is useful in various machine learning tasks, including classification problems. It transforms the raw scores (logits) produced by a model into probabilities that can be interpreted as the model's confidence scores for each class. The class with the highest probability according to the softmax output is typically chosen as the predicted class.

In summary, softmax function is defined as:

σ(zi)=ezij=1kezj

for (i=1,2,,k), where (z=(z1,z2,,zk)) is the input vector and (σ(z)) is the output vector representing probabilities.