8
$\begingroup$

I have been using WeightedData with Histogram, HistogramList, DensityHistogram, HistogramDistribution and SmoothKernelDistribution, with 1D and 2D data, and have noticed that those functions are much slower when the same data is represented with WeightedData instead of an unweighted data list.

This can be seen here:

d=RandomVariate[NormalDistribution[0,1],10^5];
w=ConstantArray[1,Length[d]];
wd=WeightedData[d,w];
HistogramList[d,{.1}]//Timing//First
HistogramList[wd,{.1}]//Timing//First

The unweighted histogram takes 0.05s and the weighted one takes 3.4s.

What makes these functions be slower with WeightedData?

$\endgroup$
3
  • 4
    $\begingroup$ Wow, that's bad performance. This is a question for support! I can hardly imagine any good reason for this. $\endgroup$ Nov 4 '21 at 10:38
  • $\begingroup$ Yeah. Most of my use has been with SmoothKernelDistribution, and it would take about 20 minutes for a 2D dataset of about 20000 weighted entries. I was blaming already SmoothKernelDistribution for being so slow. It never crossed my mind that the weighted data wouldn't be faster than the plain full dataset. $\endgroup$
    – anonymous
    Nov 4 '21 at 10:46
  • 1
    $\begingroup$ I sent Wolfram a report about the issue. I'll post here any update. $\endgroup$
    – anonymous
    Nov 9 '21 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.