# Need Help to implement my loss function

**URL:** https://discourse.julialang.org/t/need-help-to-implement-my-loss-function/81724
**Category:** Machine Learning
**Created:** [May 26, 2022, 2:13pm UTC](https://discourse.julialang.org/t/need-help-to-implement-my-loss-function/81724 "2022-05-26T14:13:40Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Hupdup](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@Hupdup](https://discourse.julialang.org/u/Hupdup)
#### Post date: [May 26, 2022, 2:13pm UTC](https://discourse.julialang.org/t/need-help-to-implement-my-loss-function/81724/1 "2022-05-26T14:13:40Z")

</div>

Hi  
I want to implement a loss function for the weight-update of the neural network in my Reinforcement learning (DQN) project. The Q Value of the next state should be estimated by my target network (yellow mark) wheras the value estimate of the current action shall be estimated by my main network, which I want to update. My Problem is, that I don’t know how I can check the estimate the value of a specific action for a given state (the red mark).

The loss function I want to implement:  
 ![loss function](https://global.discourse-cdn.com/julialang/original/3X/3/0/30bee8e37f15278f1bc9aca51827a3e43abf18f3.jpeg)

my implementation (which doesn’t work)  
 ![my implementation](https://global.discourse-cdn.com/julialang/original/3X/9/8/9804a7aab378a7631432be192d6f3decc5b6f3e1.jpeg)

do you know how to implement the current estimate for a given action? (= the output of the neural network at index a)

Thank you for your help!
