# Flux.jl: Initializing Parameters in Specified Range

**URL:** https://discourse.julialang.org/t/flux-jl-initializing-parameters-in-specified-range/42621
**Category:** Machine Learning
**Created:** [July 6, 2020, 4:22pm UTC](https://discourse.julialang.org/t/flux-jl-initializing-parameters-in-specified-range/42621 "2020-07-06T16:22:55Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![astroboy](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@astroboy](https://discourse.julialang.org/u/astroboy)
#### Post date: [July 6, 2020, 4:22pm UTC](https://discourse.julialang.org/t/flux-jl-initializing-parameters-in-specified-range/42621/1 "2020-07-06T16:22:56Z")

</div>

Hello! I hope you’re all doing well.

I’m trying to figure out how to initialize the parameters of a simple `Dense` layer object uniformly in a range that I specify. I know that I can access how the layer parameters are initialized with `initW` and `initb`, but I don’t know what do after that. Any ideas?

Thanks in advance!

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [July 10, 2020, 12:45pm UTC](https://discourse.julialang.org/t/flux-jl-initializing-parameters-in-specified-range/42621/2 "2020-07-10T12:45:07Z")

</div>

If all you need is a feed-forward neural network on a mid-scale dataset you can use the [BetaML library](https://github.com/sylvaticus/BetaML.jl/) (disclaimer: I’m the author):

```julia
using Distributions
l1 = DenseLayer(23,15,f=sigmoid, w=rand(Uniform(-2,2),15,23), wb=rand(Uniform(-2,2),15)) # Activation function is ReLU
l2 = DenseLayer(15,1,f=identity, w=rand(Uniform(-2,2),1,15), wb=rand(Uniform(-2,2),1))
mynn = buildNetwork([l1,l2],squaredCost,name="Bike sharing regression model") # Build the NN and use the squared cost (aka MSE) as error function
Nn.show(mynn)
"""
*** Bike sharing regression model (2 layers, non trained)

# # In # Out Type
1 23 15 DenseLayer 
2 15 1 DenseLayer 
"""
# Training it (default to ADAM)
# xtrain: (n,d) - ytrain: (n,1)
res = train!(mynn,xtrain,ytrain,epochs=100,batchSize=8,optAlg=ADAM(),verbosity=HIGH) # Use optAlg=SGD() to get Stochastic Gradient Descent
ŷtest = predict(mynn,xtrain)

```
