Skip to main content
Changed "surface" to "region" to conform with conventional terms.
Source Link
whuber
  • 333.6k
  • 63
  • 792
  • 1.3k

Uniform Sampling From the SurfaceRegion Bounded by $\sqrt{x}$, $x=3$, and $y=0$

I want to sample uniformly from the area bounded by $y=0$, $x=3$, and $y=\sqrt{x}$: enter image description here

If I draw $x$ from $U[0, 3]$ and $y$ from $U[0, \sqrt{x}]$, the density will be higher in the bottom left corner: enter image description here

I tried to fix this by making the number of points on a surfaceregion bounded by $x=a \in [0, 3]$ on the right, the square root curve, and the $x$-axis proportional to its area (relative to that of the entire figure).

So, the total area should be: $$\int_{0}^{3}\sqrt{x}dx = \frac{2}{3}x^{\frac{3}{2}}\bigg\rvert_{0}^{3}=2\sqrt{3}$$

The area bounded by $x=a$ on the right is $\frac{2}{3}a^{\frac{3}{2}}$, so the pdf of $x$ should be proportional to the ratio, i.e.: $$ pdf(x) = C \times \frac{\frac{2}{3}a^{\frac{3}{2}}}{2\sqrt{3}} = \frac{C}{3\sqrt{3}}a^{\frac{3}{2}} $$

The corresponding CDF is then:

$$ CDF(x) = \int_{0}^{x} pdf(u)du = \int_{0}^{x} \frac{C}{3\sqrt{3}}u^{\frac{3}{2}}du = \frac{C}{3\sqrt{3}} \times \frac{2}{5} u^{\frac{5}{2}} \bigg\rvert_{0}^{x} $$

$$ CDF(x) = \frac{C}{3\sqrt{3}} \times \frac{2}{5} x^{\frac{5}{2}} = \frac{2C}{5\times3\sqrt{3}} x^{\frac{5}{2}} $$

I get $C$ from the condition $CDF(3)=1$: $$ CDF(3) = \frac{2C}{5\times3\sqrt{3}} 3^{\frac{5}{2}} = \frac{2C}{5}\times 3 = \frac{6C}{5} = 1 $$ So: $$ C = \frac{5}{6} \implies \quad CDF(x) = \left(\frac{x}{3}\right)^{\frac{5}{2}} $$

Therefore, I should sample $x$ by sampling a random number $r \in Uniform[0, 1]$ and solving $CDF(x)=r$ for $x$: $$ x = 3 \times r^{\frac{2}{5}} \quad (r \in Uniform[0,1]) $$

and get $y$ by sampling from $Uniform[0, \sqrt{x}]$. However, this approach doesn't make the distribution uniform: enter image description here The sampled points are now concentrated away from the bottom left corner.

Can someone help me? :)

Uniform Sampling From the Surface Bounded by $\sqrt{x}$, $x=3$, and $y=0$

I want to sample uniformly from the area bounded by $y=0$, $x=3$, and $y=\sqrt{x}$: enter image description here

If I draw $x$ from $U[0, 3]$ and $y$ from $U[0, \sqrt{x}]$, the density will be higher in the bottom left corner: enter image description here

I tried to fix this by making the number of points on a surface bounded by $x=a \in [0, 3]$ on the right, the square root curve, and the $x$-axis proportional to its area (relative to that of the entire figure).

So, the total area should be: $$\int_{0}^{3}\sqrt{x}dx = \frac{2}{3}x^{\frac{3}{2}}\bigg\rvert_{0}^{3}=2\sqrt{3}$$

The area bounded by $x=a$ on the right is $\frac{2}{3}a^{\frac{3}{2}}$, so the pdf of $x$ should be proportional to the ratio, i.e.: $$ pdf(x) = C \times \frac{\frac{2}{3}a^{\frac{3}{2}}}{2\sqrt{3}} = \frac{C}{3\sqrt{3}}a^{\frac{3}{2}} $$

The corresponding CDF is then:

$$ CDF(x) = \int_{0}^{x} pdf(u)du = \int_{0}^{x} \frac{C}{3\sqrt{3}}u^{\frac{3}{2}}du = \frac{C}{3\sqrt{3}} \times \frac{2}{5} u^{\frac{5}{2}} \bigg\rvert_{0}^{x} $$

$$ CDF(x) = \frac{C}{3\sqrt{3}} \times \frac{2}{5} x^{\frac{5}{2}} = \frac{2C}{5\times3\sqrt{3}} x^{\frac{5}{2}} $$

I get $C$ from the condition $CDF(3)=1$: $$ CDF(3) = \frac{2C}{5\times3\sqrt{3}} 3^{\frac{5}{2}} = \frac{2C}{5}\times 3 = \frac{6C}{5} = 1 $$ So: $$ C = \frac{5}{6} \implies \quad CDF(x) = \left(\frac{x}{3}\right)^{\frac{5}{2}} $$

Therefore, I should sample $x$ by sampling a random number $r \in Uniform[0, 1]$ and solving $CDF(x)=r$ for $x$: $$ x = 3 \times r^{\frac{2}{5}} \quad (r \in Uniform[0,1]) $$

and get $y$ by sampling from $Uniform[0, \sqrt{x}]$. However, this approach doesn't make the distribution uniform: enter image description here The sampled points are now concentrated away from the bottom left corner.

Can someone help me? :)

Uniform Sampling From the Region Bounded by $\sqrt{x}$, $x=3$, and $y=0$

I want to sample uniformly from the area bounded by $y=0$, $x=3$, and $y=\sqrt{x}$: enter image description here

If I draw $x$ from $U[0, 3]$ and $y$ from $U[0, \sqrt{x}]$, the density will be higher in the bottom left corner: enter image description here

I tried to fix this by making the number of points on a region bounded by $x=a \in [0, 3]$ on the right, the square root curve, and the $x$-axis proportional to its area (relative to that of the entire figure).

So, the total area should be: $$\int_{0}^{3}\sqrt{x}dx = \frac{2}{3}x^{\frac{3}{2}}\bigg\rvert_{0}^{3}=2\sqrt{3}$$

The area bounded by $x=a$ on the right is $\frac{2}{3}a^{\frac{3}{2}}$, so the pdf of $x$ should be proportional to the ratio, i.e.: $$ pdf(x) = C \times \frac{\frac{2}{3}a^{\frac{3}{2}}}{2\sqrt{3}} = \frac{C}{3\sqrt{3}}a^{\frac{3}{2}} $$

The corresponding CDF is then:

$$ CDF(x) = \int_{0}^{x} pdf(u)du = \int_{0}^{x} \frac{C}{3\sqrt{3}}u^{\frac{3}{2}}du = \frac{C}{3\sqrt{3}} \times \frac{2}{5} u^{\frac{5}{2}} \bigg\rvert_{0}^{x} $$

$$ CDF(x) = \frac{C}{3\sqrt{3}} \times \frac{2}{5} x^{\frac{5}{2}} = \frac{2C}{5\times3\sqrt{3}} x^{\frac{5}{2}} $$

I get $C$ from the condition $CDF(3)=1$: $$ CDF(3) = \frac{2C}{5\times3\sqrt{3}} 3^{\frac{5}{2}} = \frac{2C}{5}\times 3 = \frac{6C}{5} = 1 $$ So: $$ C = \frac{5}{6} \implies \quad CDF(x) = \left(\frac{x}{3}\right)^{\frac{5}{2}} $$

Therefore, I should sample $x$ by sampling a random number $r \in Uniform[0, 1]$ and solving $CDF(x)=r$ for $x$: $$ x = 3 \times r^{\frac{2}{5}} \quad (r \in Uniform[0,1]) $$

and get $y$ by sampling from $Uniform[0, \sqrt{x}]$. However, this approach doesn't make the distribution uniform: enter image description here The sampled points are now concentrated away from the bottom left corner.

Can someone help me? :)

Source Link
Milos
  • 1.1k
  • 9
  • 19

Uniform Sampling From the Surface Bounded by $\sqrt{x}$, $x=3$, and $y=0$

I want to sample uniformly from the area bounded by $y=0$, $x=3$, and $y=\sqrt{x}$: enter image description here

If I draw $x$ from $U[0, 3]$ and $y$ from $U[0, \sqrt{x}]$, the density will be higher in the bottom left corner: enter image description here

I tried to fix this by making the number of points on a surface bounded by $x=a \in [0, 3]$ on the right, the square root curve, and the $x$-axis proportional to its area (relative to that of the entire figure).

So, the total area should be: $$\int_{0}^{3}\sqrt{x}dx = \frac{2}{3}x^{\frac{3}{2}}\bigg\rvert_{0}^{3}=2\sqrt{3}$$

The area bounded by $x=a$ on the right is $\frac{2}{3}a^{\frac{3}{2}}$, so the pdf of $x$ should be proportional to the ratio, i.e.: $$ pdf(x) = C \times \frac{\frac{2}{3}a^{\frac{3}{2}}}{2\sqrt{3}} = \frac{C}{3\sqrt{3}}a^{\frac{3}{2}} $$

The corresponding CDF is then:

$$ CDF(x) = \int_{0}^{x} pdf(u)du = \int_{0}^{x} \frac{C}{3\sqrt{3}}u^{\frac{3}{2}}du = \frac{C}{3\sqrt{3}} \times \frac{2}{5} u^{\frac{5}{2}} \bigg\rvert_{0}^{x} $$

$$ CDF(x) = \frac{C}{3\sqrt{3}} \times \frac{2}{5} x^{\frac{5}{2}} = \frac{2C}{5\times3\sqrt{3}} x^{\frac{5}{2}} $$

I get $C$ from the condition $CDF(3)=1$: $$ CDF(3) = \frac{2C}{5\times3\sqrt{3}} 3^{\frac{5}{2}} = \frac{2C}{5}\times 3 = \frac{6C}{5} = 1 $$ So: $$ C = \frac{5}{6} \implies \quad CDF(x) = \left(\frac{x}{3}\right)^{\frac{5}{2}} $$

Therefore, I should sample $x$ by sampling a random number $r \in Uniform[0, 1]$ and solving $CDF(x)=r$ for $x$: $$ x = 3 \times r^{\frac{2}{5}} \quad (r \in Uniform[0,1]) $$

and get $y$ by sampling from $Uniform[0, \sqrt{x}]$. However, this approach doesn't make the distribution uniform: enter image description here The sampled points are now concentrated away from the bottom left corner.

Can someone help me? :)