How can I define my own loss function?

Benja: <p>Hi!. I am trying to define my own loss function. However I get an error when I try to compile my neural network and I do not understand why it brings that error. I have attached the model I am using for<br>
, the definition of my loss function and the error. Any advice will be helpful. Thanks!!<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/4/a/4a68986a8541b8d6dd1451947cc1c8f3dad17522.png" data-download-href="https://discuss.pytorch.org/uploads/default/4a68986a8541b8d6dd1451947cc1c8f3dad17522" title="Class"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/4/a/4a68986a8541b8d6dd1451947cc1c8f3dad17522_2_690x400.png" alt="Class" data-base62-sha1="aCfquOAeJfCNkFs7iEDAtycior8" width="690" height="400" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/4/a/4a68986a8541b8d6dd1451947cc1c8f3dad17522_2_690x400.png, https://discuss.pytorch.org/uploads/default/original/3X/4/a/4a68986a8541b8d6dd1451947cc1c8f3dad17522.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/4/a/4a68986a8541b8d6dd1451947cc1c8f3dad17522.png 2x" data-dominant-color="F6F6F6"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Class</span><span class="informations">1012×588 144 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/b/3/b3d86dd052d323ceef0cf10f3938a247ea5c3b90.png" data-download-href="https://discuss.pytorch.org/uploads/default/b3d86dd052d323ceef0cf10f3938a247ea5c3b90" title="Loss_Function"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/b/3/b3d86dd052d323ceef0cf10f3938a247ea5c3b90_2_690x148.png" alt="Loss_Function" data-base62-sha1="pEZaaS4xsBUhnL3tIvs0txHWhyg" width="690" height="148" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/b/3/b3d86dd052d323ceef0cf10f3938a247ea5c3b90_2_690x148.png, https://discuss.pytorch.org/uploads/default/optimized/3X/b/3/b3d86dd052d323ceef0cf10f3938a247ea5c3b90_2_1035x222.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/b/3/b3d86dd052d323ceef0cf10f3938a247ea5c3b90.png 2x" data-dominant-color="E9E9EA"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Loss_Function</span><span class="informations">1178×254 139 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/f/7/f711f583ebd157748204792a61ba5f0d9ee35b35.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/f711f583ebd157748204792a61ba5f0d9ee35b35" title="Error"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/f/7/f711f583ebd157748204792a61ba5f0d9ee35b35_2_690x312.jpeg" alt="Error" data-base62-sha1="zfGpyMPUgDGsdpV6AWYFhhYk2ih" width="690" height="312" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/f/7/f711f583ebd157748204792a61ba5f0d9ee35b35_2_690x312.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/f/7/f711f583ebd157748204792a61ba5f0d9ee35b35_2_1035x468.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/f/7/f711f583ebd157748204792a61ba5f0d9ee35b35_2_1380x624.jpeg 2x" data-dominant-color="F6F7F7"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Error</span><span class="informations">1920×870 116 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ParGG: <p>The error is in the definition of <code>Normal</code>. I guess that your <code>Normal</code> class has a typo in the argument <code>mean</code>.</p>