# How to define Deep Q learning loss function in Knet?

**URL:** <https://discourse.julialang.org/t/how-to-define-deep-q-learning-loss-function-in-knet/36439>\
**Category:** General Usage\
**Created:** [March 24, 2020, 12:11pm UTC](https://discourse.julialang.org/t/how-to-define-deep-q-learning-loss-function-in-knet/36439 "2020-03-24T12:11:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DeepQ](https://avatars.discourse-cdn.com/v4/letter/d/2bfe46/32.png) [@DeepQ](https://discourse.julialang.org/u/DeepQ)\
**Post date:** [March 24, 2020, 12:11pm UTC](https://discourse.julialang.org/t/how-to-define-deep-q-learning-loss-function-in-knet/36439/1 "2020-03-24T12:11:52Z")

</div>

I’am trying to implement a Deep Q learning loss function as part of my thesis. I’m trying to use Knet but I can’t find a simple example.

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [March 24, 2020, 1:59pm UTC](https://discourse.julialang.org/t/how-to-define-deep-q-learning-loss-function-in-knet/36439/2 "2020-03-24T13:59:33Z")

</div>

I’m not familiar with knet, but here’s at least a Julia implementation of Q learning with linear function approximation

> **[Recreational Research - Q-learning](https://sites.google.com/view/recreational-research/q-learning)**
>
> 2019-03-11: Updated to work with Julia 1.0

---

<div class="post-metadata">

**Author:** ![jbrea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbrea/32/3879_2.png) [@jbrea](https://discourse.julialang.org/u/jbrea)\
**Post date:** [March 24, 2020, 2:33pm UTC](https://discourse.julialang.org/t/how-to-define-deep-q-learning-loss-function-in-knet/36439/3 "2020-03-24T14:33:07Z")

</div>

[Here](https://juliareinforcementlearning.org/ReinforcementLearning.jl/latest/experiments/atari_dqn/) is an example with Flux, but I think it should be possible to simply replace the Flux-neural-net by a Knet-neural-net.
