Thanks a lot. I see it now 
by the way the smoothing part is not needed right? or is it ? since if I put that variable in that last formula,
it will be differentiable, and we should be able to apply gradients to it right?
Edit:
Oh I got it  no need for the explanation here. thanks a gazillion times 
by the way do I still need to add the loss in the training loop myself or will it automatically get tuned?
Update 2 :
Got my second answer as well. there is no need to manually add their values to the loss in the training loop. everything is done automatically