Created
August 28, 2023 02:22
-
-
Save theXYZT/d949034899318b51cbd1c3b161490eff to your computer and use it in GitHub Desktop.
Square of Sums / Sum of Squares
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numba as nb | |
import numpy as np | |
from tqdm.auto import tqdm | |
import dask.array as da | |
@nb.njit([nb.float64[:](nb.float64[:, :]),]) | |
def g(x): | |
res = np.zeros(x.shape[0], dtype=np.float64) | |
for i in range(res.shape[0]): | |
b, c = 0, 0 | |
for a in x[i]: | |
b += a | |
c += a**2 | |
res[i] = b**2 / c | |
return res | |
def expected_g_uniform(n, N=1000000): | |
z = da.random.uniform(0, 1, (N, n), chunks=("auto", -1)) | |
z = da.map_blocks(g, z, drop_axis=-1) | |
return z.mean().compute() | |
# Find G(100; U(0, 1)) | |
G = expected_g_uniform(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment