Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 38f1dfa

Browse files
committedSep 4, 2024
graph show the pytorch softmax => how to use Mathematica express it ?
1 parent 85ad93e commit 38f1dfa

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed
 

‎relu_graph.png

457 KB
Loading

‎softmax_3dgraph.png

429 KB
Loading

‎softmax_graph.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
(* graph show the pytorch softmax => how to use Mathematica express it ? \text{softmax}(x_i) = \frac{e^{x_i}}{\sum_{j} e^{x_j}} *)
3+
4+
softmax[x_List] := Exp[x]/Total[Exp[x]]
5+
6+
7+
input = {1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0};
8+
output = softmax[input]
9+
10+
11+
BarChart[output, ChartLabels -> input,
12+
ChartStyle -> Blue,
13+
PlotLabel -> "Softmax Function",
14+
AxesLabel -> {"Input", "Softmax Output"}]
15+
16+
17+
(* plot softmax function *)
18+
19+
Plot[Evaluate[softmax[{x, 2, 3, 4}]], {x, -5, 5},
20+
PlotLegends -> {"softmax[{x, 2, 3, 4}]"},
21+
PlotRange -> All, AxesLabel -> {"x", "softmax output"},
22+
PlotLabel -> "Softmax Function"]
23+
24+
25+
Plot3D[Evaluate[softmax[{x, y, 2}][[1]]], {x, -5, 5}, {y, -5, 5},
26+
PlotRange -> All, AxesLabel -> {"x", "y", "softmax output"},
27+
PlotLabel -> "Softmax Function"]
28+

‎softmax_graph.png

355 KB
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.