Dear community, I have a program that should give me a fixed distribution through a recurrence recursion. Because it is something related to the statistic I need to get the result for the program using a large amount of data (around 10^4 at least), this is the code:
RecurrenceDistributionRandomGraph[J_, H_, \[Beta]_, y_, Pf_, P0_, n_,
m_] := Block[ {x0, q, x, z},
x0 = RandomVariate[P0, n];
(*x0=Table[3,n];*)
R = {x0};
Do[
x = Table[0, n];
Do[
q = Round[RandomVariate[Pf]];
z = RandomSample[R[[i]], q];
x[[j]] = N[y[z, J, H , \[Beta]]]
, {j, 1, n}];
R = Append[R, x];
, {i, 1, m}]
]
and the inputs are, for example (they can be modified):
P0 = PoissonDistribution[5];
Pf = ProbabilityDistribution[q*(E^-3 3^q/q!)/3, {q, 0, +\[Infinity]}];
y[z_, J_, H_, \[Beta]_] := (
E^(\[Beta] (J + H)) Product[i, {i, z}] + E^(-\[Beta] (J + H)))/(
E^(\[Beta] (-J + H)) Product[i, {i, z}] + E^(\[Beta] (J - H))).
y is the recursion relation. Unfortunately my code seems to work properly but it really takes an huge quantity of time. For example even with few data:
RecurrenceDistributionRandomGraph[1., 1., 0.2, y, Pf, P0, 100,
20] // Timing
{305.652, Null}.
So how can I speed up the algorithm or maybe there is no solution? Unfortunately I have to store every set of data in the list (matrix) R, so I cannot make a quicker program in that sense. Thanks you for the answers