## Volume primerjava

Tukaj primerjam volumne.

Best case:

$$
\begin{equation}
\label{volume3}
    \frac{V_{hyperball}}{V_{hypercube}} = \frac{ \frac{2}{d}\frac{\pi^{d/2}}{\Gamma \left( d/2 \right)} r^d }{\left(2r\right)^d } = \frac{2}{d}\frac{\pi^{d/2}}{\Gamma \left( d/2 \right) \cdot 2^d }
\end{equation}
$$

Worst case:

$$
\begin{equation}
\label{volume4}
    \frac{V_{hyperball}}{V_{hypercube}} = \frac{ \frac{2}{d}\frac{\pi^{d/2}}{\Gamma \left( d/2 \right)} \left( r \sqrt{d} \right) ^d }{\left(2 r \right)^d } = \frac{2}{d}\frac{\pi^{d/2}}{\Gamma \left( d/2 \right) \cdot 2^d } \cdot d^{\frac{d}{2}}
\end{equation}
$$


```python
# %matplotlib qt
%matplotlib inline

import numpy as np
from scipy.special import gamma
import matplotlib.pyplot as plt
from math import pi
```


```python
d_vals = np.arange(2, 18 +1)
cube = np.ones( d_vals.shape )

frac_best = np.array([])
frac_worst = np.array([])

for d in d_vals:
    el = 2/d * (pi**(d/2))/(gamma(d/2)* 2**d)
    frac_best = np.append( frac_best,   el )
    frac_worst = np.append( frac_worst,  el* d**(d/2) )
```


```python
plt.figure(figsize=(8,4))

plt.plot( d_vals, cube, label="enotska hiperkocka" )
plt.plot( d_vals, frac_best, label="najboljši hiperelipsoid" )
plt.plot( d_vals, frac_worst, label="najslabši hiperelipsoid" )

plt.yscale("log")

plt.legend(loc=3, prop={'size': 12})
plt.xlabel("Število dimenzij "+r'$d$', fontsize=14)
plt.ylabel("Volumen", fontsize=14 )

plt.show()
```


```python
plt.figure(figsize=(8,4))

plt.plot( d_vals, cube, label="enotska hiperkocka" )
plt.plot( d_vals, frac_best, label="najboljši hiperelipsoid" )
plt.plot( d_vals, frac_worst, label="najslabši hiperelipsoid" )

plt.yscale("log")

plt.legend(loc=3, prop={'size': 12})
plt.xlabel("Število dimenzij "+r'$d$', fontsize=14)
plt.ylabel("Volumen", fontsize=14 )

plt.scatter([12,12,12,12], [6.894,1.353, 4.204, 4.986], c="red", s=30, label="raztezani hiperelipsoid")
plt.scatter([12,12,12,12], [0.1007,0.07501, 0.08465, 0.04670], c="purple", s=30, label="elipsoidna metoda")

plt.legend(loc=3, prop={'size': 12})

plt.show()
```


```python
print(frac_best[10])
print(frac_worst[10])
print( frac_worst[10] / frac_best[10])
```

    0.00032599188692738996
    973.4065584949956
    2985984.0



```python

```

45c2d234f1a9e5ba41b3ee1f57c799a9581dbabf
ipynb
Jupyter Notebook
demonstrations/volume_primerjava.ipynb
JurijNastran/Ellipsoids
ed04b6c10d196407bfd310962a6ed0d7a80140d7
MIT
demonstrations/volume_primerjava.ipynb
JurijNastran/Ellipsoids
ed04b6c10d196407bfd310962a6ed0d7a80140d7
MIT
demonstrations/volume_primerjava.ipynb
JurijNastran/Ellipsoids
ed04b6c10d196407bfd310962a6ed0d7a80140d7
MIT
Qwen/Qwen-72B
1. YES
2. YES