From cc7093268846b7fb9f8bb94e0ec45f0822c7fe54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Tom=C3=A1s=20Collins?= Date: Sat, 26 Jun 2021 20:54:57 -0400 Subject: [PATCH 1/2] p007 swift --- .../p007-Categorical-Cross-Entropy-Loss.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Swift/p007-Categorical-Cross-Entropy-Loss.swift diff --git a/Swift/p007-Categorical-Cross-Entropy-Loss.swift b/Swift/p007-Categorical-Cross-Entropy-Loss.swift new file mode 100644 index 0000000..a84709f --- /dev/null +++ b/Swift/p007-Categorical-Cross-Entropy-Loss.swift @@ -0,0 +1,18 @@ +/* +Calculating the loss with Categorical Cross Entropy +Associated with YT NNFS tutorial: https://www.youtube.com/watch?v=dEXPMQXoiLc +*/ + +import Foundation + +var softmax_output: [Double] = [0.7, 0.1, 0.2] +var target_output: [Double] = [1, 0, 0] + +var loss = -(log(softmax_output[0]) * target_output[0] + + log(softmax_output[1]) * target_output[1] + + log(softmax_output[2]) * target_output[2]) + +print(loss) + +print(-log(0.7)) +print(-log(0.5)) \ No newline at end of file From d1a7d2072d689dffed7653c919d192f9c1e0fac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Tom=C3=A1s=20Collins?= Date: Sat, 26 Jun 2021 20:58:32 -0400 Subject: [PATCH 2/2] eof --- Swift/p007-Categorical-Cross-Entropy-Loss.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Swift/p007-Categorical-Cross-Entropy-Loss.swift b/Swift/p007-Categorical-Cross-Entropy-Loss.swift index a84709f..eedb9b2 100644 --- a/Swift/p007-Categorical-Cross-Entropy-Loss.swift +++ b/Swift/p007-Categorical-Cross-Entropy-Loss.swift @@ -15,4 +15,4 @@ var loss = -(log(softmax_output[0]) * target_output[0] + print(loss) print(-log(0.7)) -print(-log(0.5)) \ No newline at end of file +print(-log(0.5))