# Histogram not plotting RandomVariate of EmpiricalDistribution

Bug introduced in 11.1 or earlier and fixed in 11.2

I have a seemingly odd case in 11.1 where a sample from an EmpiricalDistribution is not being plotted by Histogram but the same sample is plotted by SmoothHistogram.

The weights and values are

{weights, values} ={{1.00875,1.99112,1.99116,1.95452,1.92082,1.87752,1.84808,1.78201,1.7213,1.6468,1.58059,1.50983,1.43815,1.36926,1.31043,1.26065,1.22202,1.18499,1.15066,1.12557,1.10673,1.09089,1.07963,1.06488,1.05452,1.04687,1.03911,1.03402,1.02988,1.02755,1.02153,1.01821,1.01406,1.01201,1.00763,1.00593,1.00405,1.00396,1.00296,1.00295,1.00108,1.00108,1.00108,1.0011,1.0011,1.0011,1.00031,1.00031,1.00031,1.00031,1.00031,1.00031,1.00031,1.00031,1.00031,1.00031,1.00031,1.00031,1.00031,1.00031,1.00031,1.00031,1.00031,1.00031,1.00031,1.00031,1.00031,0.999535,0.999535,0.999535,0.999535,0.999535,0.999535,0.999535,0.999535,0.999535,0.999535,0.999535,0.999535,0.999535,0.999535,0.999535,0.999535,0.999535,0.998749,0.998749,0.998749,0.998749,0.998749,1.,1.,1.,1.},{3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147,150,153,156,159,162,165,168,171,174,177,180,183,186,189,192,195,198,201,204,207,210,213,216,219,222,225,228,231,234,237,240,243,246,249,252,255,258,261,264,267,270,273,276,279}};


I setup the distribution as

ed = EmpiricalDistribution[(weights - Min@weights) -> values];
data = RandomVariate[ed, 100000];


SmoothHistogram has no issues plotting this.

SmoothHistogram[data, PlotRange -> Full]


However Histogram runs forever until I abort it.

Histogram[data]

\$Aborted


Any ideas what is going on here? Version 11.1 on Win 7 Ent.

CASE:3879575

• Works like a charm on my machine (Mac OS, Mathematica 11.0.1): (i.stack.imgur.com/MhWfM.png) Probably a memory issue or something like that. – yohbs Apr 19 '17 at 15:23
• I can confirm this for 11.1 on Win 10 (64 bit). – gwr Apr 19 '17 at 15:28
• Has been reported to WRI. – Edmund Apr 19 '17 at 17:06

It seems to be related to the way the binning is determined by Histogram if no explicit bspec is given. Once bspecs are given it seems to work without any problem:

Histogram[ data, {0, 95, 5} ]


I would assume that somewhere inside the assumption of smoothly distributed data is violated and causes the algorithm to get stuck. Note for example that it works out correctly when we add a small amount to the shifted (standardized) weights:

edMod = EmpiricalDistribution[
0.001 + Standardize[ weights, (*shift*) Min, (*scale*) Function[1] ] -> values
];

dataMod = RandomVariate[ edMod, 100000 ];

Histogram @ data


So there may be precision issues here. But to me the behavior looks like a bug.

• Good workaround. (+1) – Edmund Apr 19 '17 at 17:06