# Updating parameters in Distribution

**URL:** <https://discourse.julialang.org/t/updating-parameters-in-distribution/4140>\
**Category:** Statistics\
**Created:** [June 7, 2017, 3:25pm UTC](https://discourse.julialang.org/t/updating-parameters-in-distribution/4140 "2017-06-07T15:25:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacobcvt12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacobcvt12/32/2695_2.png) [@jacobcvt12](https://discourse.julialang.org/u/jacobcvt12)\
**Post date:** [June 7, 2017, 3:25pm UTC](https://discourse.julialang.org/t/updating-parameters-in-distribution/4140/1 "2017-06-07T15:25:55Z")

</div>

I’d like to be able to modify the parameters in a `Distribution` using a tuple. For example, something like this

```julia
using Distributions

x=Normal(1.0, 3.0)

# doesn't work
params(x) = (2.0, 4.0)

```

Is it possible to do something along these lines? I’d like to modify the parameters of a distribution in a more programmatic fashion, i.e. only having a tuples of parameter values to pass (where I know how many parameters are appropriate, as well as restrictions on negativity) to several different variables representing a `Distribution`. My use case will look something like this

```julia
# vector of distributions
rvs=[Normal(), Gamma()]

# vector of tuple of params to pass to each random variable
parms=[(-1, 2), (3, 4)]

# update parameters of `rvs` with corresponding `tuple`
for i in 1:length(rvs)
    params(rvs[i]) = parms[i] # change this how?
end

```

---

<div class="post-metadata">

**Author:** ![andreasnoack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andreasnoack/32/27_2.png) [@andreasnoack](https://discourse.julialang.org/u/andreasnoack)\
**Post date:** [June 7, 2017, 3:46pm UTC](https://discourse.julialang.org/t/updating-parameters-in-distribution/4140/2 "2017-06-07T15:46:58Z")

</div>

No, because distributions are immutable. Just make a new instance with the new values. It is extremely cheap to create a new instance. Maybe something like

```julia
rvs=[Normal, Gamma]

parms=[(-1, 2), (3, 4)]

for i in 1:length(rvs)
    rv = rvs[i](parms[i]...)
end

```

---

<div class="post-metadata">

**Author:** ![jacobcvt12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacobcvt12/32/2695_2.png) [@jacobcvt12](https://discourse.julialang.org/u/jacobcvt12)\
**Post date:** [June 7, 2017, 4:36pm UTC](https://discourse.julialang.org/t/updating-parameters-in-distribution/4140/3 "2017-06-07T16:36:49Z")

</div>

Thanks @andreasnoack!
