Problem with random generator

I’m completely puzzled with a problem concerning my code:

using LinearAlgebra
using DeterminantalPointProcesses

L=Symmetric(rand(100,100))
variables=collect(1:100)
dpp=DPP(eigen(L))
M0=rand(dpp,1)
function proposal(Mt::Array{Int64,1})
    compl=setdiff(variables,Mt)
    Lcompl=L[compl,compl]
    dpp_compl=DPP(eigen(Lcompl))
    M1=compl[rand(dpp_compl,1)[1]]
    return M1
end

When I run map(x->proposal(M0[1]),1:3) I get

3-element Array{Array{Int64,1},1}:
 [2, 3, 4, 5, 6, 8, 10, 11, 12, 13  …  84, 87, 88, 89, 93, 94, 97, 98, 99, 100]
 [2, 3, 4, 5, 6, 8, 10, 11, 12, 13  …  84, 87, 88, 89, 93, 94, 97, 98, 99, 100]
 [2, 3, 4, 5, 6, 8, 10, 11, 12, 13  …  84, 87, 88, 89, 93, 94, 97, 98, 99, 100]

but I’m supposed to obtain 3 different arrays, because of the random command rand(dpp_compl,1)[1] .
When I try to run

Mt=M0
compl=setdiff(variables,Mt[1])
Lcompl=L[compl,compl]
dpp_compl=DPP(eigen(Lcompl))
compl[rand(dpp_compl,1)[1]]
compl[rand(dpp_compl,1)[1]]
compl[rand(dpp_compl,1)[1]]

I obtain 3 different arrays and that’s what I should obtain. I’ completely puzzled because the first code should produce different arrays just like the second code! Has anyone an idea of what’s wrong??

It is returning a Vector of Vectors, i.e. each component of the result is one of the Vectors that you wanted.

1 Like

I think the complaint is that the three entries are the same.

1 Like

I didn’t run the code, but it looks likely to come from the fact that in your mapcommand, the function returns a constant (i.e. doesn’t depend on its argument x.

Each time you call DPP the DeterminantalPointProcesses it creates contains a MersenneTwister created with the same seed.

Since the rand method provided by the package uses that MersenneTwister you will always get the same sequence if you create the DeterminantalPointProcesses without setting the seed to a different number each time you create one.

2 Likes

The problem is that the three vectors are the same when they don’t have to be! :slight_smile:

Yes exactly!

The argument x is just here to settle the numer of times I repeat the function proposal.

Ahhhhhhh yes! Didn’t see that the seed was inside the rand command, since usually I set a seed myself outside! That should do the trick, then!