1
$\begingroup$

I have the following function of two variables

$(1)\qquad f(x,y)=\exp[-x^{2} - y^{2} + \frac{1}{2}xy]$

which is interpreted as a two-variable Gaussian probability distribution. Concretely I want to make a discrete density plot in the $xy$-plane for the probability function (1), instead of the continuous ones usually constructed by the DensityPlot.

Is there any way to make a discrete density plot for the probability distribution (1)? I mean a set of points that are distributed according to the probability distribution (1).

$\endgroup$
  • $\begingroup$ I don't understand what you mean by a "discrete" density plot. $\endgroup$ – mikado Dec 15 '19 at 21:20
  • $\begingroup$ @mikado By a "discrete" density plot, I mean a set of points that are distributed according to the probability distribution (1). $\endgroup$ – Julio Abraham Mendoza Fierro Dec 15 '19 at 21:32
  • $\begingroup$ Would you explain why you'd want a discrete representation of a smooth surface? Also, an answer to a question posted by others: Do you have a set of samples or do you have a function describing a surface? Both answers would be helpful. $\endgroup$ – JimB Dec 16 '19 at 16:28
3
$\begingroup$

Is this what you mean? When you "a set of points distributed according to..." it's not clear if you want them randomly sampled from that or what.

dist = MultinormalDistribution[{0, 0}, 1/3*{{2, 1}, {1, 2}}];

PDF[dist, {x, y}] // Simplify

$$ \frac{\sqrt{3} e^{-x^2+x y-y^2}}{2 \pi } $$

Histogram3D[RandomVariate[dist, 10000]]

enter image description here

$\endgroup$
2
$\begingroup$
Clear["Global`*"]

distbn = BinormalDistribution[{0, 0}, {s1, s2}, p];

PDF[distbn, {x, y}] // Expand

(* E^(-(x^2/(2 (1 - p^2) s1^2)) + (p x y)/((1 - p^2) s1 s2) - y^2/(
 2 (1 - p^2) s2^2))/(2 Sqrt[1 - p^2] π s1 s2) *)

Solving for {s1, s2, p} to match the specified form

Solve[{2 (1 - p^2) s1^2 == 1, 2 (1 - p^2) s2^2 == 1, ((1 - p^2) s1 s2)/p == 2,
   s1 > 0, s2 > 0}, {s1, s2, p}]

(* {{s1 -> 2 Sqrt[2/15], s2 -> 2 Sqrt[2/15], p -> 1/4}} *)

The distribution is

dist = BinormalDistribution[{0, 0}, {2 Sqrt[2/15], 2 Sqrt[2/15]}, 1/4];

PDF[dist, {x, y}] // Simplify

(* (Sqrt[15] E^(-x^2 + (x y)/2 - y^2))/(4 π) *)

SeedRandom[1234]

data = RandomVariate[dist, 2000];

Needs["MultivariateStatistics`"]

With[{q = {0.5, 0.9, 0.95}},
 Show[
  ListPlot[data, PlotStyle -> Red],
  Graphics /@
   EllipsoidQuantile[data, q]]]

enter image description here

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.