Binary codes correcting two deletions, lengths 16 to 18
Find larger binary codes of length 16, 17 and 18 that correct two deletions; the best known have 220, 349 and 567 words.
Compare independent cold starts and index larger exchanges
Browse files+11 −9 routes/irisbud-codex/n17-local-search/audit_exchanges.py View file
| @@ -49,22 +49,24 @@ def connected_owners(groups, radius): | ||
| 49 | 49 | # At the first improving radius, the blocker hypergraph must be connected. |
| 50 | 50 | # Otherwise a smaller component would already provide an improvement. |
| 51 | 51 | subsets = [set() for _ in range(radius + 1)] |
| 52 | - incident = defaultdict(list) | |
| 52 | + extensions = defaultdict(set) | |
| 53 | 53 | for owners in groups: |
| 54 | 54 | if len(owners) <= radius: |
| 55 | 55 | subsets[len(owners)].add(owners) |
| 56 | 56 | if 1 < len(owners) < radius: |
| 57 | - edge = frozenset(owners) | |
| 58 | - for word in owners: | |
| 59 | - incident[word].append(edge) | |
| 57 | + for count in range(1, len(owners)): | |
| 58 | + for shared in combinations(owners, count): | |
| 59 | + extra = tuple(word for word in owners if word not in shared) | |
| 60 | + extensions[shared, len(extra)].add(extra) | |
| 60 | 61 | for size in range(2, radius): |
| 61 | 62 | for owners in subsets[size]: |
| 62 | 63 | selected = frozenset(owners) |
| 63 | - for word in owners: | |
| 64 | - for edge in incident[word]: | |
| 65 | - extra = edge - selected | |
| 66 | - if 0 < len(extra) <= radius - size: | |
| 67 | - subsets[size + len(extra)].add(tuple(sorted(selected | extra))) | |
| 64 | + for count in range(1, size + 1): | |
| 65 | + for shared in combinations(owners, count): | |
| 66 | + for added in range(1, radius - size + 1): | |
| 67 | + for extra in extensions.get((shared, added), ()): | |
| 68 | + if selected.isdisjoint(extra): | |
| 69 | + subsets[size + added].add(tuple(sorted((*owners, *extra)))) | |
| 68 | 70 | return subsets |
| 69 | 71 | |
| 70 | 72 | |
+55 −0 routes/irisbud-codex/n17-local-search/cold.sbatch added View file
| @@ -0,0 +1,55 @@ | ||
| 1 | +#!/usr/bin/env bash | |
| 2 | +#SBATCH --job-name=n17-cold-starts | |
| 3 | +#SBATCH --cpus-per-task=4 | |
| 4 | +#SBATCH --time=00:09:00 | |
| 5 | +#SBATCH --mem=1024M | |
| 6 | +set -euo pipefail | |
| 7 | + | |
| 8 | +if [[ $# -ne 7 ]]; then | |
| 9 | + echo 'Usage: cold.sbatch GREEDY_ATTEMPTS FIRST_SEED ROUNDS LOCAL_SEED1 LOCAL_SEED2 LOCAL_SEED3 LOCAL_SEED4' >&2 | |
| 10 | + exit 2 | |
| 11 | +fi | |
| 12 | + | |
| 13 | +here=$(pwd) | |
| 14 | +repo=${SS_INPUT:-$(git rev-parse --show-toplevel)} | |
| 15 | +tmp_base=$(cd -- "${TMPDIR:-/tmp}" && pwd -P) | |
| 16 | +scratch=$(mktemp -d "$tmp_base/n17-cold.XXXXXXXX") | |
| 17 | +scratch=$(cd -- "$scratch" && pwd -P) | |
| 18 | +[[ $(dirname -- "$scratch") == "$tmp_base" && ${scratch##*/} == n17-cold.* ]] | |
| 19 | +trap 'rm -rf -- "$scratch"' EXIT | |
| 20 | +cxx=${CXX:-c++} | |
| 21 | +python=${PYTHON:-python3} | |
| 22 | + | |
| 23 | +"$python" -B greedy_starts.py "$scratch/greedy.json" --attempts "$1" --first-seed "$2" | tee "$scratch/greedy.log" | |
| 24 | +"$cxx" -O3 -std=c++17 search.cpp -o "$scratch/search.exe" | |
| 25 | +( | |
| 26 | + cd "$scratch" | |
| 27 | + "$python" -B "$here/run_seeds.py" "$scratch/search.exe" "$scratch" "$scratch/greedy.json" "$3" "$4" "$5" "$6" "$7" | |
| 28 | +) | |
| 29 | +mv -- "$scratch/n17.json" "$scratch/cold-n17.json" | |
| 30 | +"$python" -B recombine.py "$scratch/recombined.json" n17.json "$scratch/cold-n17.json" | tee "$scratch/recombined.log" | |
| 31 | + | |
| 32 | +"$python" -B - "$scratch" <<'PY' | |
| 33 | +import json | |
| 34 | +import shutil | |
| 35 | +import sys | |
| 36 | +from pathlib import Path | |
| 37 | + | |
| 38 | +scratch = Path(sys.argv[1]) | |
| 39 | +current, cold, combined = Path('n17.json'), scratch / 'cold-n17.json', scratch / 'recombined.json' | |
| 40 | + | |
| 41 | +def size(path): | |
| 42 | + return len(json.loads(path.read_text(encoding='utf-8'))['words']) | |
| 43 | + | |
| 44 | +old_size, best_size = size(current), size(combined) | |
| 45 | +shutil.copyfile(cold, 'alternative-n17.json') | |
| 46 | +if best_size > old_size: | |
| 47 | + shutil.copyfile(combined, current) | |
| 48 | +lines = [(scratch / 'greedy.log').read_text(encoding='utf-8').splitlines()[-1], | |
| 49 | + (scratch / 'search-report.txt').read_text(encoding='utf-8').strip(), | |
| 50 | + (scratch / 'recombined.log').read_text(encoding='utf-8').strip(), | |
| 51 | + f'Primary construction: {size(current)} codewords'] | |
| 52 | +Path('cold-start-report.txt').write_text('\n'.join(lines) + '\n', encoding='utf-8') | |
| 53 | +print(lines[-1]) | |
| 54 | +PY | |
| 55 | +"$python" -B "$repo/checks/judge/check.py" . | |
+63 −0 routes/irisbud-codex/n17-local-search/greedy_starts.py added View file
| @@ -0,0 +1,63 @@ | ||
| 1 | +"""Try deletion-sphere priorities to construct new length-17 starting codes.""" | |
| 2 | + | |
| 3 | +import argparse | |
| 4 | +import itertools | |
| 5 | +from pathlib import Path | |
| 6 | + | |
| 7 | +import numpy as np | |
| 8 | + | |
| 9 | +from optimize import DESCENDANT_COUNT, LENGTH, WORD_COUNT, check_code, deletion_table, write_code | |
| 10 | + | |
| 11 | + | |
| 12 | +def popcounts(words): | |
| 13 | + return np.fromiter((word.bit_count() for word in words.tolist()), dtype=np.int16) | |
| 14 | + | |
| 15 | + | |
| 16 | +def greedy(table, priority): | |
| 17 | + used = np.zeros(DESCENDANT_COUNT, dtype=bool) | |
| 18 | + code = set() | |
| 19 | + for word in np.argsort(priority, kind="stable").tolist(): | |
| 20 | + children = table[word] | |
| 21 | + if not used[children].any(): | |
| 22 | + code.add(word) | |
| 23 | + used[children] = True | |
| 24 | + return code | |
| 25 | + | |
| 26 | + | |
| 27 | +def main(): | |
| 28 | + parser = argparse.ArgumentParser(description=__doc__) | |
| 29 | + parser.add_argument("output", type=Path) | |
| 30 | + parser.add_argument("--first-seed", type=int, default=501) | |
| 31 | + parser.add_argument("--attempts", type=int, default=48) | |
| 32 | + args = parser.parse_args() | |
| 33 | + if args.first_seed < 0 or args.attempts < 1: | |
| 34 | + parser.error("Seed must be nonnegative and attempts must be positive") | |
| 35 | + words = np.arange(WORD_COUNT, dtype=np.uint32) | |
| 36 | + table = deletion_table() | |
| 37 | + sorted_table = np.sort(table, axis=1) | |
| 38 | + sphere_size = 1 + np.count_nonzero(sorted_table[:, 1:] != sorted_table[:, :-1], axis=1) | |
| 39 | + del sorted_table | |
| 40 | + weight_from_center = np.abs(2 * popcounts(words) - LENGTH) | |
| 41 | + transitions = popcounts((words ^ (words >> 1)) & ((1 << (LENGTH - 1)) - 1)) | |
| 42 | + | |
| 43 | + best = set() | |
| 44 | + best_seed = args.first_seed | |
| 45 | + combinations = tuple(itertools.product((2.0, 5.0, 10.0, 16.0), (-1.0, 0.0, 1.0), (-1.0, 0.0, 1.0))) | |
| 46 | + for attempt in range(args.attempts): | |
| 47 | + seed = args.first_seed + attempt | |
| 48 | + rng = np.random.default_rng(seed) | |
| 49 | + noise, weight, run = combinations[attempt % len(combinations)] | |
| 50 | + priority = sphere_size + weight * weight_from_center + run * transitions + rng.normal(0, noise, WORD_COUNT) | |
| 51 | + code = greedy(table, priority) | |
| 52 | + if len(code) > len(best): | |
| 53 | + best, best_seed = code, seed | |
| 54 | + check_code(best, table) | |
| 55 | + write_code(args.output, best) | |
| 56 | + print(f"metric: cold_start_size {len(best)}", flush=True) | |
| 57 | + if (attempt + 1) % 8 == 0 or attempt + 1 == args.attempts: | |
| 58 | + print(f"progress: {attempt + 1}/{args.attempts} starts, best {len(best)} (seed {best_seed})", flush=True) | |
| 59 | + print(f"seed {best_seed}, {len(best)} codewords", flush=True) | |
| 60 | + | |
| 61 | + | |
| 62 | +if __name__ == "__main__": | |
| 63 | + main() | |
+4 −1 routes/irisbud-codex/n17-local-search/search.sbatch View file
| @@ -14,7 +14,10 @@ if [[ $# -lt 4 || $# -gt 7 || ( $# -eq 7 && $7 != escape ) ]]; then | ||
| 14 | 14 | exit 2 |
| 15 | 15 | fi |
| 16 | 16 | |
| 17 | -scratch=$(mktemp -d) | |
| 17 | +tmp_base=$(cd -- "${TMPDIR:-/tmp}" && pwd -P) | |
| 18 | +scratch=$(mktemp -d "$tmp_base/n17-search.XXXXXXXX") | |
| 19 | +scratch=$(cd -- "$scratch" && pwd -P) | |
| 20 | +[[ $(dirname -- "$scratch") == "$tmp_base" && ${scratch##*/} == n17-search.* ]] | |
| 18 | 21 | trap 'rm -rf -- "$scratch"' EXIT |
| 19 | 22 | options=(--optimizer-rounds "${6:-0}") |
| 20 | 23 | if [[ ${7:-} == escape ]]; then |
