I have a sample from a distribution invariant w.r.t rotations around 0. What's the best way to incorporate this information into a smooth 3D histogram?

n = 400;
sample := RandomVariate[NormalDistribution[], {n, n}];
products = NestList[sample . # &, sample, 2];
SmoothHistogram3D[ReIm /@ Eigenvalues[#], Axes -> False] & /@ products


To account for the "known" radial symmetry about (0,0) first construct the (univariate) density of the distance from (0,0) and then transform to a 2-dimensional density.

(* Take a random sample from a radially symmetric distribution *)
n = 400;
SeedRandom[12345];
sample = RandomVariate[NormalDistribution[0, 1], {n, 2}];

(* The usual nonparametric density estimate *)
skd2 = SmoothKernelDistribution[sample, "LeastSquaresCrossValidation"];

(* Accounting for the knowledge that the bivariate density is symmetric about {0,0} *)
d = Norm[#] & /@ sample; (* Distances from {0,0} *)
skd1 = SmoothKernelDistribution[d,
"LeastSquaresCrossValidation", {"Bounded", {0, ∞},
"Gaussian"}];
(* To get the bivariate density estimate from the univariate density
estimate divide by the circumference *)
pdf[x_, y_] := PDF[skd1, Norm[{x, y}]]/(2 π Norm[{x, y}])

(* Plot both bivariate density estimates *)
Plot3D[{PDF[skd2, {x, y}], pdf[x, y]}, {x, Min[sample],
Max[sample]}, {y, Min[sample], Max[sample]}, PlotTheme -> "ZMesh",
PlotRange -> {All, All, {0, 0.16}}, PlotPoints -> 100]


Notice the funny business at (0,0). Unless there are additional assumptions one can make, I think that will just be what one obtains. (That happens from dividing by the distance from (0,0) which is close to zero near (0,0).) For a justification for this approach (or maybe for a "Don't do it that way"), try asking this question at CrossValidated.

• it looks like an alternative trick is just to add rotations of the data into the dataset Commented Jul 25, 2023 at 21:17
• Rather than "trick", I would use tterms like "one more tool in the statistical toolbox" but I get your point. Essentially the same thing can be done with samples from densities known to be symmetric about zero.
– JimB
Commented Jul 25, 2023 at 23:12
• The following link has the same question at CrossValidated with links to solutions: stats.stackexchange.com/questions/613725/….
– JimB
Commented Jul 25, 2023 at 23:24

If your question is about getting the same bandwidth for each of the two dimensions in a nonparametric density estimator, then the following will do that:

n = 400;
sample := RandomVariate[NormalDistribution[], {n, n}];
products = NestList[sample . # &, sample, 2];
data = ReIm /@ Eigenvalues[#] & /@ products;

(* Initial density *)
skd = SmoothKernelDistribution[#, Automatic, {"Radial", "Gaussian"}] & /@ data;

(* Now use the average of the two automatically chosen bandwidths
as the common bandwidth *)
skd2 = SmoothKernelDistribution[data[[#]],
Mean[skd[[#, 2, 3]]] {1, 1}, {"Radial", "Gaussian"}] & /@ {1, 2,  3};

(* Plot results *)
Plot3D[PDF[skd2[[#]], {x, y}], {x, Min[data[[#]]],
Max[data[[#]]]}, {y, Min[data[[#]]], Max[data[[#]]]},
PlotTheme -> "ZMesh", PlotRange -> All, Axes -> False] & /@ {1, 2, 3}


As a check that the same bandwidths are used for both dimensions:

skd[[1]]


But if the data is invariant w.r.t. rotations around 0 and you have a large sample size, you won't see much difference from what you initially used and what I used above.

• Underlying density is symmetric w.r.t rotations around 0, so the 3D histogram contours should be perfect circles Commented Jul 24, 2023 at 14:39
• Thanks. I clearly misunderstood the question. In that case I would suggest that you only need a single and simpler example: sample = RandomVariate[NormalDistribution[], {n, 2}];. And now to see that I really understand the question: your question is analogous to a 1-dimensional sample where you want to estimate the density from a sample and incorporate the fact that you know the distribution is symmetric about zero but still use a nonparametric density estimator.
– JimB
Commented Jul 24, 2023 at 15:03
• In fact, the approach should then probably be finding a nonparametric density for the distance from zero. In other words, turning this into a 1-dimensional problem.
– JimB
Commented Jul 24, 2023 at 15:04