# What the parameter in PerturbedAdditive means

**URL:** <https://discourse.julialang.org/t/what-the-parameter-in-perturbedadditive-means/121446>\
**Category:** General Usage\
**Tags:** question, package, inferopt\
**Created:** [October 18, 2024, 8:14am UTC](https://discourse.julialang.org/t/what-the-parameter-in-perturbedadditive-means/121446 "2024-10-18T08:14:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yaozhong\_Liu](https://avatars.discourse-cdn.com/v4/letter/y/a587f6/32.png) [@Yaozhong\_Liu](https://discourse.julialang.org/u/Yaozhong_Liu)\
**Post date:** [October 18, 2024, 8:14am UTC](https://discourse.julialang.org/t/what-the-parameter-in-perturbedadditive-means/121446/1 "2024-10-18T08:14:12Z")

</div>

Hi.  
There’s a function in InferOpt package named PerturbedAdditive.  
I’m curious about a parameter.

```julia
co_layer = PerturbedAdditive(knapsack_maximizer; ε=10.0, nb_samples=10)

```

For codes above, what does “ε=10.0” mean?  
And I know that it will give 10 random numbers from the distribution N(0,1). If I want to fetch from N(0,2), what should I do?

Could you kindly provide me with the ε meaning and example code?  
Thank you

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [October 18, 2024, 10:19am UTC](https://discourse.julialang.org/t/what-the-parameter-in-perturbedadditive-means/121446/2 "2024-10-18T10:19:55Z")

</div>

In this function, `ε` is the scaling of the perturbation, which corresponds to the standard deviation for a Gaussian variable. So your code will actually perturb the `knapsack_maximizer` with `nb_samples=10` random numbers from the distribution `N(0, ε^2)`.  
Ping @BatyLeo

---

<div class="post-metadata">

**Author:** ![Yaozhong\_Liu](https://avatars.discourse-cdn.com/v4/letter/y/a587f6/32.png) [@Yaozhong\_Liu](https://discourse.julialang.org/u/Yaozhong_Liu)\
**Post date:** [October 19, 2024, 8:15am UTC](https://discourse.julialang.org/t/what-the-parameter-in-perturbedadditive-means/121446/3 "2024-10-19T08:15:59Z")

</div>

Thank you for replying!  
I understood. But I tried with the code.

```julia
printf(co_player)

```

And I got print like this:

```julia
PerturbedAdditive(pctsp, 10.0, 10, MersenneTwister, nothing, Normal(0, 1))

```

It indicates that it produced a distribution N(0,1) rather than N(0,10) ?

---

<div class="post-metadata">

**Author:** ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Post date:** [October 19, 2024, 8:37am UTC](https://discourse.julialang.org/t/what-the-parameter-in-perturbedadditive-means/121446/4 "2024-10-19T08:37:10Z")

</div>

You should read the documentation `?PerturbedAdditive`. `ε` is the standard deviation in the normal random variable case. The `perturbation` keyword, which is what you are seeing printed with `Normal(0, 1)`, is the base sampling distribution for that perturbation (which defaults to `perturbation=nothing` or equivalent `Normal(0, 1)`).

---

<div class="post-metadata">

**Author:** ![Yaozhong\_Liu](https://avatars.discourse-cdn.com/v4/letter/y/a587f6/32.png) [@Yaozhong\_Liu](https://discourse.julialang.org/u/Yaozhong_Liu)\
**Post date:** [October 19, 2024, 9:10am UTC](https://discourse.julialang.org/t/what-the-parameter-in-perturbedadditive-means/121446/5 "2024-10-19T09:10:49Z")

</div>

Thank you !  
I see.  
It means we fetch one random number z from distribution N(0,1) first. Then, we mutiple z with ε as our final perturbation?  
I think I fully understood now.  
Thanks

---

<div class="post-metadata">

**Author:** ![BatyLeo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/batyleo/32/35017_2.png) [@BatyLeo](https://discourse.julialang.org/u/BatyLeo)\
**Post date:** [October 20, 2024, 10:50am UTC](https://discourse.julialang.org/t/what-the-parameter-in-perturbedadditive-means/121446/6 "2024-10-20T10:50:24Z")

</div>

Hi, here is the full formula behind the hood:  
\text{co\_layer}(\theta) = \dfrac{1}{\text{nb\_samples}} \sum\limits\_{i=1}^{\text{nb\_samples}} \text{knapsack\_maximizer}(\theta + \varepsilon Z\_i),  
where Z\_i are sampled from `Normal(0, 1)`.

---

<div class="post-metadata">

**Author:** ![Yaozhong\_Liu](https://avatars.discourse-cdn.com/v4/letter/y/a587f6/32.png) [@Yaozhong\_Liu](https://discourse.julialang.org/u/Yaozhong_Liu)\
**Post date:** [October 20, 2024, 11:53am UTC](https://discourse.julialang.org/t/what-the-parameter-in-perturbedadditive-means/121446/7 "2024-10-20T11:53:14Z")

</div>

Thank you! I understand!  
This is an execellent answer!
