softmax_3d: Apply Softmax Function to a 3D Array

View source: R/activation_functions.R

softmax_3dR Documentation

Apply Softmax Function to a 3D Array

Description

This function applies the softmax transformation along the third dimension of a 3D array. The softmax function converts raw scores into probabilities such that they sum to 1 for each slice along the third dimension.

Usage

softmax_3d(x)

Arguments

x

A 3D array. The input array on which the softmax function will be applied.

Details

The softmax transformation is computed as:

\text{softmax}(x_{ijk}) = \frac{\exp(x_{ijk})}{\sum_{l} \exp(x_{ijl})}

This is applied for each pair of indices ⁠(i, j)⁠ across the third dimension (k).

The function processes the input array slice-by-slice for the first two dimensions ⁠(i, j)⁠, normalizing the values along the third dimension (k) for each slice.

Value

A 3D array of the same dimensions as x, where the values along the third dimension are transformed using the softmax function.

Examples

# Example: Apply softmax to a 3D array
x <- array(runif(24), dim = c(2, 3, 4)) # Random 3D array (2x3x4)
softmax_result <- softmax_3d(x)


bnns documentation built on April 3, 2025, 6:12 p.m.