From 42d2baf86cba0a30f84962b25e16a874943504d1 Mon Sep 17 00:00:00 2001 From: aevrane <36012343+aevrane@users.noreply.github.com> Date: Fri, 9 Sep 2022 21:29:59 -0700 Subject: [PATCH] Create P.7 Calculating Loss with Categorical Cross-Entropy.cs --- ...ing Loss with Categorical Cross-Entropy.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Unity & C#/P.7 Calculating Loss with Categorical Cross-Entropy.cs diff --git a/Unity & C#/P.7 Calculating Loss with Categorical Cross-Entropy.cs b/Unity & C#/P.7 Calculating Loss with Categorical Cross-Entropy.cs new file mode 100644 index 0000000..ca0b30b --- /dev/null +++ b/Unity & C#/P.7 Calculating Loss with Categorical Cross-Entropy.cs @@ -0,0 +1,24 @@ +using UnityEngine; + +public class Script7 : MonoBehaviour +{ + public float[] softMaxOutput; + public float loss; + public float negativeMathLogPoint7 = -Mathf.Log(0.7f); + public float negativeMathLogPoint5 = -Mathf.Log(0.5f); + // Start is called before the first frame update + void Start() + { + softMaxOutput = new float[] { 0.7f, 0.1f, 0.2f }; + } + + // Update is called once per frame + void Update() + { + // Set boundary for softmax result between 0 and 1, so you can mess around with values + // in the inspector for the first value and see how the results for loss change + softMaxOutput[0] = Mathf.Clamp(softMaxOutput[0], 0, 1); + // Dynamically Calculate loss. + loss = -Mathf.Log(softMaxOutput[0]); + } +}