# How can I optimize recurrent networks in Flux?

**URL:** https://discourse.julialang.org/t/how-can-i-optimize-recurrent-networks-in-flux/34425
**Category:** Machine Learning
**Tags:** flux
**Created:** [February 10, 2020, 5:15pm UTC](https://discourse.julialang.org/t/how-can-i-optimize-recurrent-networks-in-flux/34425 "2020-02-10T17:15:45Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jmeeks29ig](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmeeks29ig/32/209205_2.png) [@jmeeks29ig](https://discourse.julialang.org/u/jmeeks29ig)
#### Post date: [February 10, 2020, 5:15pm UTC](https://discourse.julialang.org/t/how-can-i-optimize-recurrent-networks-in-flux/34425/1 "2020-02-10T17:15:45Z")

</div>

Hi,  
I posted a question in stackoverflow ([optimization - How can I optimize a recurrent network in Julia with Flux? - Stack Overflow](https://stackoverflow.com/questions/60123607/how-can-i-optimize-a-recurrent-network-in-julia-with-flux)) regarding the performance of Flux in using a recurrent neural network. I have been getting very slow computation results compared to similar code in Mathematica and think there is probably a lot I can do to optimize the timing, but I’m really not sure where to start. Any tips?

Here is the code:

net = Chain(LSTM(8,100), Dense(100,1))

function mapNetworkOverStocks(net, stocksInput)  
unFlattened = map(x → (output = net.(x); Flux.reset!(net); output), stocksInput)  
map(x → map(y → y[1], x), unFlattened)  
end

mapNetworkOverStocks(net, allStocksData)

The actual data (stock data) looks like the following:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/c/7ce98db7dd22460a1edc8ec8aa9e34edfefe9d75.png)
