I want to run following for few hundreds of a random variable set. This calculates:
- generate normal random variable
- find gain with squaring
- calculate performance metric
- find
maxofminof possibleM+1performance metric whenachanges(0,1). I have other case with another parameterbwhich changes(0,1). - find the
averagefor 100 or 1000 random realizations - find same for different
pvalues
Finally I want to save it as a table with different p and M.
variable[M_] := RandomVariate[NormalDistribution[0, 1], M + 1];
gain[M_, d_, t_] := variable[M]^2/(d/(M + 1))^t;
perform[p_, a_, m_, M_, d_, t_] :=
1/(M + 1) p ((1 - a)/(2 - a)) a^(
m - 1) (Product[gain[M, d, t][[i]], {i, 1, m}]);
maxminperform[p_, M_, d_, t_] :=
Max[Table[
Min[Table[perform[p, a, m, M, d, t], {m, 1, M + 1, 1}]], {a,
0.00001, 0.999, 0.001}]];
avgperform[p_, M_, d_, t_, itr_] :=
Mean[Table[maxminperform[p, M, d, t], {i, 1, itr}]];
$ $
Module[{n = 0.001, η = 0.7, σ = 1, k = 7, d = 6, t = 3,
itr = 5},
Export["table.xls", {Table[{avgperform[p, 2, d, t, itr],
avgperform[p, 4, d, t, itr], avgperform[p, 6, d, t, itr]}, {p,
1, 10, 1}] // N}]]
I understand that this takes really long time when I run.
Can someone help me to faster this code?
SetDelayedforvariable[M_]? – gwr Jul 25 '16 at 11:22Product[gain[][[i]]], each factor in the product is computed using a newly generated random distribution. Is that your intent? You might want in thereProduct@@gain[][[;;m]]to compute it only once. It will be faster but obviously change the result. – george2079 Jul 25 '16 at 15:24