# Initialize Lux.jl NN parameters according to Lux.glorot\_normal

**URL:** https://discourse.julialang.org/t/initialize-lux-jl-nn-parameters-according-to-lux-glorot-normal/90293
**Category:** Machine Learning
**Created:** [November 15, 2022, 2:49pm UTC](https://discourse.julialang.org/t/initialize-lux-jl-nn-parameters-according-to-lux-glorot-normal/90293 "2022-11-15T14:49:53Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![MilesCB](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milescb/32/44347_2.png) [@MilesCB](https://discourse.julialang.org/u/MilesCB)
#### Post date: [November 15, 2022, 2:49pm UTC](https://discourse.julialang.org/t/initialize-lux-jl-nn-parameters-according-to-lux-glorot-normal/90293/1 "2022-11-15T14:49:53Z")

</div>

Hi all,

I would like to initialize the parameters of a Lux.jl neural network with something other than a random distribution; for instance with `Lux.glorot_normal`. I am using this network with `NeuralPDE.jl` with the following architecture:

```julia
dim = length(domains) 
activation = Lux.σ
nnodes = 10
chain = Lux.Chain(Lux.Dense(dim, nnodes, activation), 
            Lux.Dense(nnodes, 1)) 

ps = Lux.setup(Random.default_rng(), 
           chain)[1] |> Lux.ComponentArray .|> Float32

discretization = PhysicsInformedNN(chains, strategy, init_params=ps)
@time prob = discretize(pde_sys, discretization)

```

I’ve been looking through the documentation for `Lux` and `NeuralPDE` and can’t find anything to help. It seems like passing an argument to `Lux.setup` would solve the problem but I’m not sure what this argument would be.

Maybe this is not super desirable to include, but my network performance seems to be highly dependent on initial parameter choice.

Any help is very much appreciated!

---

<div class="post-metadata">

### Author: ![avikpal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/avikpal/32/6550_2.png) [@avikpal](https://discourse.julialang.org/u/avikpal)
#### Post date: [November 15, 2022, 8:10pm UTC](https://discourse.julialang.org/t/initialize-lux-jl-nn-parameters-according-to-lux-glorot-normal/90293/2 "2022-11-15T20:10:26Z")

</div>

You need to specify the initialization for each layer. See [Layers - Lux.jl](http://lux.csail.mit.edu/stable/api/layers/#Lux.Dense). Including it via setup is not possible since what is being initialized is highly layer dependent.
