Updating parameters in Distribution


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

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

# 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?


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

rvs=[Normal, Gamma]

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

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


Thanks @andreasnoack!