I wanted to check something, but ran into troubles using HistogramDistribution in combination with ParallelTable.
The code does the following: Compute a HistogramDistribution of some sample and use some function which draws from that HistogramDistribution. Here's a stripped down version of the code that reproduces my problem:
exampledist =
TruncatedDistribution[{0, 1.16},
HistogramDistribution[
RandomVariate[ExponentialDistribution[1], 1000], 3]];
SetSharedVariable[exampledist];
drawExample[n_] :=
Module[{draws = Table[0, {n}]},
(*check some stuff, do something*)
For[i = 1, i <= n, i++,
draws[[i]] = First[RandomVariate[exampledist, 1]];
];
Return[draws];
];
drawExample[3]
ParallelTable[Table[drawExample[3], {1}], {i, 1, 2}]
The output is:
{1.05817, 1.05732, 0.47069}
and
{{{DataDistribution[<<"Histogram">>, {1000}],
DataDistribution[<<"Histogram">>, {1000}],
DataDistribution[<<"Histogram">>, {1000}]}}, \
{{DataDistribution[<<"Histogram">>, {1000}],
DataDistribution[<<"Histogram">>, {1000}],
DataDistribution[<<"Histogram">>, {1000}]}}}
Why can't I use the distribution in ParallelTable? First I thought the definition isn't shared properly, so I added SetSharedVariable
, but that didn't resolve it.
Does anyone know what I am missing here? Thank you very much.
$Version
)? $\endgroup$ – Andy Ross Dec 15 '12 at 23:30