aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--epare/visualize.ipynb112
1 files changed, 5 insertions, 107 deletions
diff --git a/epare/visualize.ipynb b/epare/visualize.ipynb
index 5b61ca1..709e566 100644
--- a/epare/visualize.ipynb
+++ b/epare/visualize.ipynb
@@ -77,41 +77,6 @@
]
},
{
- "cell_type": "code",
- "execution_count": null,
- "id": "2df8cd8c-9528-4755-83b5-10ecabaead54",
- "metadata": {},
- "outputs": [],
- "source": [
- "def divides_any(l: int, small_scalars: set[int]) -> bool:\n",
- " for s in small_scalars:\n",
- " if s%l==0:\n",
- " return True\n",
- " return False\n",
- "\n",
- "def process_small_scalars(scalar_results: MultResults, divisors: set[int]) -> ProbMap:\n",
- " result = {}\n",
- " for divisor in divisors:\n",
- " count = 0\n",
- " for smult in scalar_results.multiplications:\n",
- " if divides_any(divisor, smult):\n",
- " count += 1\n",
- " result[divisor] = count / scalar_results.samples\n",
- " return ProbMap(result, scalar_results.samples)\n",
- "\n",
- "def load_chunk(fname: str, divisors: set[int]) -> dict[MultIdent, ProbMap]:\n",
- " with open(fname, \"rb\") as f:\n",
- " multiples = pickle.load(f)\n",
- " res = {}\n",
- " for mult, results in multiples.items():\n",
- " res[mult] = process_small_scalars(results, divisors)\n",
- " return res\n",
- "\n",
- "def conf_interval(p: float, samples: int, alpha: float = 0.05) -> tuple[float, float]:\n",
- " return proportion_confint(round(p*samples), samples, alpha, method=\"wilson\")"
- ]
- },
- {
"cell_type": "markdown",
"id": "2596562f-8a6a-4a25-ae82-a6b9562d8a40",
"metadata": {},
@@ -127,39 +92,9 @@
"metadata": {},
"outputs": [],
"source": [
- "def powers_of(k, max_power=20):\n",
- " return [k**i for i in range(1, max_power)]\n",
- "\n",
- "def prod_combine(one, other):\n",
- " return [a * b for a, b in itertools.product(one, other)]\n",
- "\n",
- "small_primes = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]\n",
- "medium_primes = [211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397]\n",
- "large_primes = [401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]\n",
- "all_integers = list(range(1, 400))\n",
- "all_even = list(range(2, 400, 2))\n",
- "all_odd = list(range(1, 400, 2))\n",
- "all_primes = small_primes + medium_primes + large_primes\n",
- "\n",
- "divisor_map = {\n",
- " \"small_primes\": small_primes,\n",
- " \"medium_primes\": medium_primes,\n",
- " \"large_primes\": large_primes,\n",
- " \"all_primes\": all_primes,\n",
- " \"all_integers\": all_integers,\n",
- " \"all_even\": all_even,\n",
- " \"all_odd\": all_odd,\n",
- " \"powers_of_2\": powers_of(2),\n",
- " \"powers_of_2_large\": powers_of(2, 256),\n",
- " \"powers_of_2_large_3\": [i * 3 for i in powers_of(2, 256)],\n",
- " \"powers_of_2_large_p1\": [i + 1 for i in powers_of(2, 256)],\n",
- " \"powers_of_2_large_m1\": [i - 1 for i in powers_of(2, 256)],\n",
- " \"powers_of_2_large_pmautobus\": sorted(set([i + j for i in powers_of(2, 256) for j in range(-5,5) if i+j > 0])),\n",
- " \"powers_of_3\": powers_of(3),\n",
- "}\n",
- "divisor_map[\"all\"] = list(sorted(set().union(*[v for v in divisor_map.values()])))\n",
+ "from common import divisor_map\n",
"for d, ds in divisor_map.items():\n",
- " print(d, len(ds))"
+ " print(f\"{d:<27}\", ds[:3], \"...\", ds[-1:])"
]
},
{
@@ -175,18 +110,11 @@
},
{
"cell_type": "markdown",
- "id": "5b427252-a3ff-4a55-940c-3c8659caa799",
- "metadata": {},
- "source": [
- "Select the mults you want to compute the prob-maps for here as well as a set of divisors. It is good to set `all` here, compute the prob-maps for all the divisors, save them and they continue with visualizing them on subsets of divisors."
- ]
- },
- {
- "cell_type": "markdown",
"id": "8b008248-a0aa-41fa-933c-f325f8eec31b",
"metadata": {},
"source": [
- "## Configuration"
+ "## Configuration\n",
+ "Select the mults you want to compute the prob-maps for here as well as a set of divisors. It is good to set `all` here, compute the prob-maps for all the divisors, save them and they continue with visualizing them on subsets of divisors."
]
},
{
@@ -198,7 +126,7 @@
"source": [
"selected_mults = all_mults\n",
"divisor_name = \"all\"\n",
- "kind = \"necessary\"\n",
+ "kind = \"precomp+necessary\"\n",
"showci = False\n",
"selected_divisors = divisor_map[divisor_name]"
]
@@ -206,36 +134,6 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "4d2b0f1a-b50a-4548-b63e-c6507e95503d",
- "metadata": {},
- "outputs": [],
- "source": [
- "# This cell computes the probmaps from the multiplication result chunks. Only do this on small amount of chunks.\n",
- "# distributions_mults = {}\n",
- "# files = sorted(glob.glob(f\"multiples_{bits}_{kind}_chunk*.pickle\"))\n",
- "# with TaskExecutor(max_workers=num_workers) as pool:\n",
- "# for fname in files:\n",
- "# pool.submit_task(fname,\n",
- "# load_chunk,\n",
- "# fname, selected_divisors)\n",
- "# for fname, future in tqdm(pool.as_completed(), leave=False, total=len(pool.tasks), smoothing=0):\n",
- "# if error := future.exception():\n",
- "# print(f\"Error {fname}, {error}\")\n",
- "# continue\n",
- "# new_distrs = future.result()\n",
- "# for mult, prob_map in new_distrs.items():\n",
- "# if mult in distributions_mults:\n",
- "# distributions_mults[mult].merge(prob_map)\n",
- "# else:\n",
- "# distributions_mults[mult] = prob_map\n",
- "# Save\n",
- "# with open(f\"{divisor_name}_{kind}_distrs.pickle\", \"wb\") as f:\n",
- "# pickle.dump(distributions_mults, f)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
"id": "19d986ab-5fe7-4dd6-b5b5-4e75307217d6",
"metadata": {},
"outputs": [],