# Need help with example; Mixture Density Networks from Site

**URL:** <https://discourse.julialang.org/t/need-help-with-example-mixture-density-networks-from-site/81514>\
**Category:** Performance\
**Tags:** flux\
**Created:** [May 23, 2022, 1:49pm UTC](https://discourse.julialang.org/t/need-help-with-example-mixture-density-networks-from-site/81514 "2022-05-23T13:49:06Z")\
**Posts on this page:** 1\
**Showing post:** 19

<div class="post-metadata">

**Author:** ![Karthik-d-k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karthik-d-k/32/35438_2.png) [@Karthik-d-k](https://discourse.julialang.org/u/Karthik-d-k)\
**Post date:** [May 30, 2022, 4:14pm UTC](https://discourse.julialang.org/t/need-help-with-example-mixture-density-networks-from-site/81514/19 "2022-05-30T16:14:44Z")

</div>

Hey @HerAdri

I finally could able to solve something !!, thanks to @ToucheSir 😀where he mentioned in other post about how gradients are calculated in `Zygote` [here](https://discourse.julialang.org/t/methoderror-objects-of-type-float64-are-not-callable/81876/3).  
Taking that comment into consideration, i moved every calculations that needs to be tracked for backward pass into `gradient do block`  
so i changed the code as follows and it looks like for me it does the job (acc to me 😉) you should confirm if otherwise →

```julia
# lowest-level?
data = [(y, x)]

for epoch in 1:n_epochs
    
    # forward
    l = 0f0
    
    # backward
    gs = gradient(pars) do
        pi_out = model[:pi](y)
        sigma_out = model[:sigma](y)
        mu_out = model[:mu](y)
        l = mdn_loss(pi_out, sigma_out, mu_out, x)
    end
    Flux.update!(opt, pars, gs)

    if epoch % 1000 == 0
        println("Epoch: ", epoch, " loss: ", l)
    end
end

```

---

_[View the full topic](https://discourse.julialang.org/t/need-help-with-example-mixture-density-networks-from-site/81514)._
