%23%20%2F%2F%2F%20script%0A%23%20requires-python%20%3D%20%22%3E%3D3.14%22%0A%23%20dependencies%20%3D%20%5B%0A%23%20%20%20%20%20%22marimo%3E%3D0.23.1%22%2C%0A%23%20%20%20%20%20%22altair%3E%3D5.5.0%22%2C%0A%23%20%20%20%20%20%22optuna%3E%3D4.0.0%22%2C%0A%23%20%20%20%20%20%22numpy%3E%3D2.4.4%22%2C%0A%23%20%20%20%20%20%22scipy%3E%3D1.17.1%22%2C%0A%23%20%20%20%20%20%22numba%3E%3D0.65.0%22%2C%0A%23%20%20%20%20%20%22kbank%22%2C%0A%23%20%20%20%20%20%22serogen%22%2C%0A%23%20%5D%0A%23%0A%23%20%5Btool.uv.sources%5D%0A%23%20kbank%20%3D%20%7B%20path%20%3D%20%22..%22%2C%20editable%20%3D%20true%20%7D%0A%23%20serogen%20%3D%20%7B%20path%20%3D%20%22..%2F..%2FSeroGen%22%2C%20editable%20%3D%20true%20%7D%0A%23%20%2F%2F%2F%0A%0A%22%22%22Marimo%20slide%20deck%20%26%20Two-Phase%20Optuna%20TPE%20tuning%20for%20KBank's%204-Stage%20GlycanPredictor.%22%22%22%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.25.2%22%0Aapp%20%3D%20marimo.App(%0A%20%20%20%20width%3D%22full%22%2C%0A%20%20%20%20app_title%3D%22KBank%20%E2%80%94%20GlycanPredictor%20GNN%20%26%20Arborescence%20Training%2C%20Optuna%20Tuning%20%26%20Validation%22%2C%0A%20%20%20%20layout_file%3D%22data%3Aapplication%2Fjson%3Bbase64%2CeyJ0eXBlIjogInNsaWRlcyIsICJkYXRhIjogeyJjZWxscyI6IFt7ImlkIjogIkhib2wiLCAiY29kZV9oYXNoIjogIjhjZTQ1Nzc3MGI5MzFmNWE1M2IzMGRjY2VhNDIxNGRhIn0sIHsiaWQiOiAiTUpVZSIsICJjb2RlX2hhc2giOiAiZjlhZWFlZmI3OWFhMDE1MDFkM2FjMmY5ZmQ5ZDJhNjkifSwgeyJpZCI6ICJ2YmxBIiwgImNvZGVfaGFzaCI6ICI0MDlkMzA5ODk2Mjc5ODQ5ODY3MTEyODQ2ZGZkOTU4ZSJ9LCB7ImlkIjogImJrSEMiLCAiY29kZV9oYXNoIjogImM3ZjNkNjQ5YTJhN2ZjNmVlNTg2MjQ5ODk3Mjc1Mjg3In0sIHsiaWQiOiAibEVRYSIsICJjb2RlX2hhc2giOiAiZjQ3NzJlZGJkNzM3MzQ1ZTBlZTMxMmEyM2ZiNmQ4OWMifSwgeyJpZCI6ICJQS3JpIiwgImNvZGVfaGFzaCI6ICJjMGM5NmY2NjhiN2Y3OThiNmM5YjIyMDgwY2MwY2UwMSJ9LCB7ImlkIjogIlhyZWYiLCAiY29kZV9oYXNoIjogIjQyNTk5MTUzYmFmMjliNzFiZDkyMGM2MzJiZWJjNDIzIn0sIHsiaWQiOiAiU0ZQTCIsICJjb2RlX2hhc2giOiAiZDIxNGRjMDM4NDZjZTY2M2IxNWRkYjcyNzMyMWYxMjIifSwgeyJpZCI6ICJCWXRDIiwgImNvZGVfaGFzaCI6ICJmYWEyMzhlOWQ3ODE1MTQ0YTVlODQ5MjU2ZGM5MGUxZCJ9XX19%22%2C%0A)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20os%0A%20%20%20%20import%20time%0A%20%20%20%20import%20urllib.request%0A%20%20%20%20from%20pathlib%20import%20Path%0A%0A%20%20%20%20import%20altair%20as%20alt%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20optuna%0A%20%20%20%20from%20serogen.core.graph.gnn%20import%20RelationalCSR%2C%20RelationalMPNN%2C%20build_multihop_csr%0A%20%20%20%20from%20serogen.core.seq.seq%20import%20Sequences%0A%20%20%20%20from%20serogen.genes.roles%20import%20GeneRole%0A%20%20%20%20from%20serogen.loci.archetypes%20import%20LocusArchetype%0A%20%20%20%20from%20serogen.loci.models%20import%20GeneNode%2C%20Locus%0A%20%20%20%20from%20serogen.loci.predictor%20import%20LocusPredictor%0A%0A%20%20%20%20from%20kbank.biosynthesis.align%20import%20AssignmentEvidence%0A%20%20%20%20from%20kbank.biosynthesis.classifier%20import%20(%0A%20%20%20%20%20%20%20%20BiosyntheticClassifierSuite%2C%0A%20%20%20%20%20%20%20%20encode_donor_linkage_label%2C%0A%20%20%20%20%20%20%20%20encode_donor_residue_chem%2C%0A%20%20%20%20)%0A%20%20%20%20from%20kbank.biosynthesis.predictor%20import%20(%0A%20%20%20%20%20%20%20%20DEFAULT_MPNN_PATH%2C%0A%20%20%20%20%20%20%20%20HOUSEKEEPING_SUGARS%2C%0A%20%20%20%20%20%20%20%20PRECURSOR_POOL_SUGAR_NAMES%2C%0A%20%20%20%20%20%20%20%20GlycanPredictor%2C%0A%20%20%20%20%20%20%20%20GlycanPredictorParams%2C%0A%20%20%20%20)%0A%20%20%20%20from%20kbank.db.records%20import%20GlycanRecords%0A%20%20%20%20from%20kbank.glycan%20import%20Anomer%2C%20Glycan%2C%20Glycans%0A%20%20%20%20from%20kbank.io.csdb%20import%20CSDBParser%0A%20%20%20%20from%20kbank.sugars%20import%20Sugars%0A%0A%20%20%20%20alt.data_transformers.disable_max_rows()%0A%20%20%20%20optuna.logging.set_verbosity(optuna.logging.WARNING)%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20Anomer%2C%0A%20%20%20%20%20%20%20%20AssignmentEvidence%2C%0A%20%20%20%20%20%20%20%20CSDBParser%2C%0A%20%20%20%20%20%20%20%20DEFAULT_MPNN_PATH%2C%0A%20%20%20%20%20%20%20%20GeneRole%2C%0A%20%20%20%20%20%20%20%20Glycan%2C%0A%20%20%20%20%20%20%20%20GlycanPredictor%2C%0A%20%20%20%20%20%20%20%20GlycanPredictorParams%2C%0A%20%20%20%20%20%20%20%20GlycanRecords%2C%0A%20%20%20%20%20%20%20%20Locus%2C%0A%20%20%20%20%20%20%20%20LocusArchetype%2C%0A%20%20%20%20%20%20%20%20LocusPredictor%2C%0A%20%20%20%20%20%20%20%20Path%2C%0A%20%20%20%20%20%20%20%20RelationalCSR%2C%0A%20%20%20%20%20%20%20%20RelationalMPNN%2C%0A%20%20%20%20%20%20%20%20Sequences%2C%0A%20%20%20%20%20%20%20%20alt%2C%0A%20%20%20%20%20%20%20%20build_multihop_csr%2C%0A%20%20%20%20%20%20%20%20encode_donor_linkage_label%2C%0A%20%20%20%20%20%20%20%20encode_donor_residue_chem%2C%0A%20%20%20%20%20%20%20%20mo%2C%0A%20%20%20%20%20%20%20%20np%2C%0A%20%20%20%20%20%20%20%20optuna%2C%0A%20%20%20%20%20%20%20%20os%2C%0A%20%20%20%20%20%20%20%20time%2C%0A%20%20%20%20%20%20%20%20urllib%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20Anomer%2C%0A%20%20%20%20AssignmentEvidence%2C%0A%20%20%20%20GeneRole%2C%0A%20%20%20%20Glycan%2C%0A%20%20%20%20GlycanPredictor%2C%0A%20%20%20%20GlycanPredictorParams%2C%0A%20%20%20%20GlycanRecords%2C%0A%20%20%20%20Locus%2C%0A%20%20%20%20LocusArchetype%2C%0A%20%20%20%20LocusPredictor%2C%0A%20%20%20%20Path%2C%0A%20%20%20%20RelationalCSR%2C%0A%20%20%20%20RelationalMPNN%2C%0A%20%20%20%20Sequences%2C%0A%20%20%20%20build_multihop_csr%2C%0A%20%20%20%20encode_donor_linkage_label%2C%0A%20%20%20%20encode_donor_residue_chem%2C%0A%20%20%20%20np%2C%0A%20%20%20%20optuna%2C%0A%20%20%20%20urllib%2C%0A)%3A%0A%20%20%20%20%23%20------------------------------------------------------------------------------------------------------------------%0A%20%20%20%20%23%20Helper%20Functions%3A%20Stratified%20Splitting%2C%20Pre-Extracted%20MPNN%20Graphs%2C%20Structural%20Metrics%20%26%20Two-Phase%20Optuna%20Studies%0A%20%20%20%20%23%20------------------------------------------------------------------------------------------------------------------%0A%0A%20%20%20%20_stripped_locus_cache%3A%20dict%5Bint%2C%20Locus%5D%20%3D%20%7B%7D%0A%0A%20%20%20%20def%20strip_locus_clusters(loc%3A%20Locus%2C%20cache_key%3A%20int%20%3D%20-1)%20-%3E%20Locus%3A%0A%20%20%20%20%20%20%20%20%22%22%22Return%20a%20copy%20of%20%60loc%60%20with%20all%20%60cluster_id%60%20values%20zeroed%20out%20(pure%20sequence%20de%20novo%20regime).%22%22%22%0A%20%20%20%20%20%20%20%20if%20cache_key%20%3E%3D%200%20and%20cache_key%20in%20_stripped_locus_cache%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20_stripped_locus_cache%5Bcache_key%5D%0A%20%20%20%20%20%20%20%20res%20%3D%20Locus(%0A%20%20%20%20%20%20%20%20%20%20%20%20nodes%3Dtuple(n.with_cluster(0)%20for%20n%20in%20loc.nodes)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20edges%3Dloc.edges%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20genes%3Dloc.genes%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20interval%3Dloc.interval%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20contig_index%3Dloc.contig_index%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20archetype%3Dloc.archetype%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20completeness%3Dloc.completeness%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20score%3Dloc.score%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20is_tandem_split%3Dloc.is_tandem_split%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20name%3Dloc.name%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20if%20cache_key%20%3E%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20_stripped_locus_cache%5Bcache_key%5D%20%3D%20res%0A%20%20%20%20%20%20%20%20return%20res%0A%0A%20%20%20%20def%20core_monosaccharide_glycan(g%3A%20Glycan)%20-%3E%20Glycan%3A%0A%20%20%20%20%20%20%20%20%22%22%22Strip%20modifier%20nodes%20(e.g.%20OAc%2C%20Pyr)%20to%20compare%20core%20monosaccharide%20repeat%20topology.%22%22%22%0A%20%20%20%20%20%20%20%20return%20g.without_modifiers()%0A%0A%20%20%20%20def%20multiset_f1(c1%3A%20dict%2C%20c2%3A%20dict)%20-%3E%20float%3A%0A%20%20%20%20%20%20%20%20%22%22%22Compute%20exact%20multiset%20Sorensen-Dice%20%2F%20F1%20overlap%20between%20two%20count%20dictionaries.%22%22%22%0A%20%20%20%20%20%20%20%20tot1%20%3D%20sum(c1.values())%0A%20%20%20%20%20%20%20%20tot2%20%3D%20sum(c2.values())%0A%20%20%20%20%20%20%20%20if%20tot1%20%3D%3D%200%20and%20tot2%20%3D%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%201.0%0A%20%20%20%20%20%20%20%20if%20tot1%20%3D%3D%200%20or%20tot2%20%3D%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%200.0%0A%20%20%20%20%20%20%20%20inter%20%3D%20sum(min(c1.get(k%2C%200)%2C%20c2.get(k%2C%200))%20for%20k%20in%20set(c1)%20%7C%20set(c2))%0A%20%20%20%20%20%20%20%20return%20float(2.0%20*%20inter%20%2F%20(tot1%20%2B%20tot2))%0A%0A%20%20%20%20def%20composition_counts(g%3A%20Glycan)%20-%3E%20dict%5Bint%2C%20int%5D%3A%0A%20%20%20%20%20%20%20%20%22%22%22Count%20non-modifier%20donor%20residue%20chemical%20identities%20in%20%60g%60.%22%22%22%0A%20%20%20%20%20%20%20%20counts%3A%20dict%5Bint%2C%20int%5D%20%3D%20%7B%7D%0A%20%20%20%20%20%20%20%20for%20n%20in%20g.nodes%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20not%20n.is_modifier%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20k%20%3D%20encode_donor_residue_chem(n)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20counts%5Bk%5D%20%3D%20counts.get(k%2C%200)%20%2B%201%0A%20%20%20%20%20%20%20%20return%20counts%0A%0A%20%20%20%20def%20bigram_counts(g%3A%20Glycan)%20-%3E%20dict%5Btuple%5Bint%2C%20int%2C%20int%5D%2C%20int%5D%3A%0A%20%20%20%20%20%20%20%20%22%22%22Count%20directed%20%60(donor_chem%2C%20linkage_chem%2C%20acceptor_chem)%60%20glycosidic%20bigrams%20in%20%60g%60.%22%22%22%0A%20%20%20%20%20%20%20%20counts%3A%20dict%5Btuple%5Bint%2C%20int%2C%20int%5D%2C%20int%5D%20%3D%20%7B%7D%0A%20%20%20%20%20%20%20%20for%20e%20in%20g.edges%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%200%20%3C%3D%20e.source%20%3C%20len(g.nodes)%20and%200%20%3C%3D%20e.target%20%3C%20len(g.nodes)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20sn%20%3D%20g.nodes%5Be.source%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20tn%20%3D%20g.nodes%5Be.target%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20not%20sn.is_modifier%20and%20not%20tn.is_modifier%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20key%20%3D%20(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20encode_donor_residue_chem(sn)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20int(e.edge_type.chemical_int)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20encode_donor_residue_chem(tn)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20counts%5Bkey%5D%20%3D%20counts.get(key%2C%200)%20%2B%201%0A%20%20%20%20%20%20%20%20return%20counts%0A%0A%20%20%20%20_wwl_cache%3A%20dict%5Btuple%5Bbytes%2C%20bytes%5D%2C%20float%5D%20%3D%20%7B%7D%0A%0A%20%20%20%20def%20wwl_pair_distance(g1%3A%20Glycan%2C%20g2%3A%20Glycan)%20-%3E%20float%3A%0A%20%20%20%20%20%20%20%20%22%22%22Compute%20Weisfeiler-Lehman%20Wasserstein%20(WWL)%20distance%20between%20two%20%60Glycan%60%20graphs.%22%22%22%0A%20%20%20%20%20%20%20%20key%20%3D%20(g1.to_csdb()%2C%20g2.to_csdb())%0A%20%20%20%20%20%20%20%20if%20key%20in%20_wwl_cache%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20_wwl_cache%5Bkey%5D%0A%20%20%20%20%20%20%20%20val%20%3D%20float(g1.wwl_distance(g2%2C%20iterations%3D2))%0A%20%20%20%20%20%20%20%20_wwl_cache%5Bkey%5D%20%3D%20val%0A%20%20%20%20%20%20%20%20return%20val%0A%0A%20%20%20%20def%20load_ncbi_nuccore_locus(accession%3A%20str%2C%20locus_name%3A%20str%2C%20lp%3A%20LocusPredictor)%20-%3E%20Locus%3A%0A%20%20%20%20%20%20%20%20%22%22%22Load%20or%20fetch%20raw%20NCBI%20nucleotide%20FASTA%20for%20%60accession%60%20and%20segment%20with%20%60SeroGen%60%20%60LocusPredictor%60.%22%22%22%0A%20%20%20%20%20%20%20%20cache_dir%20%3D%20Path.home()%20%2F%20%22.cache%22%20%2F%20%22kbank%22%20%2F%20%22nuccore%22%0A%20%20%20%20%20%20%20%20cache_dir.mkdir(parents%3DTrue%2C%20exist_ok%3DTrue)%0A%20%20%20%20%20%20%20%20fasta_path%20%3D%20cache_dir%20%2F%20f%22%7Baccession%7D.fasta%22%0A%20%20%20%20%20%20%20%20if%20not%20fasta_path.exists()%20or%20fasta_path.stat().st_size%20%3D%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20url%20%3D%20(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22https%3A%2F%2Feutils.ncbi.nlm.nih.gov%2Fentrez%2Feutils%2Fefetch.fcgi%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22%3Fdb%3Dnuccore%26id%3D%7Baccession%7D%26rettype%3Dfasta%26retmode%3Dtext%22%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20with%20urllib.request.urlopen(url%2C%20timeout%3D30)%20as%20resp%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20fasta_path.write_bytes(resp.read())%0A%20%20%20%20%20%20%20%20lines%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20ln.strip()%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20ln%20in%20fasta_path.read_text(encoding%3D%22utf-8%22%2C%20errors%3D%22replace%22).splitlines()%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20ln.strip()%20and%20not%20ln.startswith(%22%3E%22)%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20raw_dna%20%3D%20%22%22.join(lines).encode(%22ascii%22)%0A%20%20%20%20%20%20%20%20seq%20%3D%20Sequences.from_bytes(%5Braw_dna%5D)%5B0%5D%0A%20%20%20%20%20%20%20%20return%20lp.predict(seq)%5B0%5D.canonicalize_strand().with_name(locus_name)%0A%0A%20%20%20%20def%20stratified_record_split(%0A%20%20%20%20%20%20%20%20records%3A%20GlycanRecords%2C%0A%20%20%20%20%20%20%20%20*%2C%0A%20%20%20%20%20%20%20%20val_fraction%3A%20float%20%3D%200.12%2C%0A%20%20%20%20%20%20%20%20test_fraction%3A%20float%20%3D%200.12%2C%0A%20%20%20%20%20%20%20%20max_eval_per_split%3A%20int%20%3D%2030%2C%0A%20%20%20%20%20%20%20%20seed%3A%20int%20%3D%2042%2C%0A%20%20%20%20)%20-%3E%20tuple%5Blist%5Bint%5D%2C%20list%5Bint%5D%2C%20list%5Bint%5D%5D%3A%0A%20%20%20%20%20%20%20%20%22%22%22Split%20curated%20%60GlycanRecords%60%20into%20%60(train_indices%2C%20val_indices%2C%20test_indices)%60%20stratified%20by%20archetype%20%26%20branching.%22%22%22%0A%20%20%20%20%20%20%20%20rng%20%3D%20np.random.default_rng(seed)%0A%20%20%20%20%20%20%20%20strata%3A%20dict%5Btuple%5Bint%2C%20int%5D%2C%20list%5Bint%5D%5D%20%3D%20%7B%7D%0A%20%20%20%20%20%20%20%20non_eval_indices%3A%20list%5Bint%5D%20%3D%20%5B%5D%0A%0A%20%20%20%20%20%20%20%20for%20i%20in%20range(len(records))%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20loc%20%3D%20records.loci%5Bi%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20gly%20%3D%20records.glycans%5Bi%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20len(loc.nodes)%20%3C%202%20or%20len(gly.nodes)%20%3C%202%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20non_eval_indices.append(i)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20not%20any(g_n.role%20%3D%3D%20GeneRole.INITIATOR%20for%20g_n%20in%20loc.nodes)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20non_eval_indices.append(i)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%20%20%20%20%20%20%20%20%20%20%20%20gt_indices%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20g_i%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20g_i%2C%20g_n%20in%20enumerate(loc.nodes)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20g_n.role%20in%20(GeneRole.GLYCOSYLTRANSFERASE%2C%20GeneRole.TRANSMEMBRANE_SYNTHASE)%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20not%20gt_indices%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20non_eval_indices.append(i)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%20%20%20%20%20%20%20%20%20%20%20%20by_gene_edge%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20int(a.gene_index)%3A%20a%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20a%20in%20records.assignments%5Bi%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20a.is_aligned%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20and%20a.gene_index%20in%20gt_indices%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20and%20a.edge_index%20is%20not%20None%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20and%200%20%3C%3D%20a.edge_index%20%3C%20len(gly.edges)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20len(by_gene_edge)%20%3C%20len(gt_indices)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20non_eval_indices.append(i)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%20%20%20%20%20%20%20%20%20%20%20%20core_gly%20%3D%20gly.without_modifiers()%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20len(core_gly.nodes)%20!%3D%201%20%2B%20len(gt_indices)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20non_eval_indices.append(i)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%20%20%20%20%20%20%20%20%20%20%20%20gt_sources%20%3D%20%7Bint(gly.edges%5Bint(a.edge_index)%5D.source)%20for%20a%20in%20by_gene_edge.values()%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20len(gt_sources)%20!%3D%20len(gt_indices)%20or%20gly.reducing_end_index%20in%20gt_sources%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20non_eval_indices.append(i)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20has_branch%20%3D%20int(any(not%20e.edge_type.is_backbone%20for%20e%20in%20gly.edges))%0A%20%20%20%20%20%20%20%20%20%20%20%20key%20%3D%20(int(records.archetypes%5Bi%5D)%2C%20has_branch)%0A%20%20%20%20%20%20%20%20%20%20%20%20strata.setdefault(key%2C%20%5B%5D).append(i)%0A%0A%20%20%20%20%20%20%20%20train_eval%3A%20list%5Bint%5D%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20val_indices%3A%20list%5Bint%5D%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20test_indices%3A%20list%5Bint%5D%20%3D%20%5B%5D%0A%0A%20%20%20%20%20%20%20%20for%20_key%2C%20idxs%20in%20sorted(strata.items())%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20arr%20%3D%20np.array(idxs%2C%20dtype%3Dnp.int32)%0A%20%20%20%20%20%20%20%20%20%20%20%20rng.shuffle(arr)%0A%20%20%20%20%20%20%20%20%20%20%20%20n_tot%20%3D%20len(arr)%0A%20%20%20%20%20%20%20%20%20%20%20%20n_test%20%3D%20max(1%2C%20int(round(n_tot%20*%20test_fraction)))%20if%20n_tot%20%3E%3D%205%20else%200%0A%20%20%20%20%20%20%20%20%20%20%20%20n_val%20%3D%20max(1%2C%20int(round(n_tot%20*%20val_fraction)))%20if%20n_tot%20%3E%3D%204%20else%200%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20n_test%20%2B%20n_val%20%3E%3D%20n_tot%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20n_test%20%3D%20max(0%2C%20n_tot%20%2F%2F%204)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20n_val%20%3D%20max(0%2C%20n_tot%20%2F%2F%204)%0A%20%20%20%20%20%20%20%20%20%20%20%20test_indices.extend(int(x)%20for%20x%20in%20arr%5B%3An_test%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20val_indices.extend(int(x)%20for%20x%20in%20arr%5Bn_test%20%3A%20n_test%20%2B%20n_val%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20train_eval.extend(int(x)%20for%20x%20in%20arr%5Bn_test%20%2B%20n_val%20%3A%5D)%0A%0A%20%20%20%20%20%20%20%20if%20len(val_indices)%20%3E%20max_eval_per_split%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20rng.shuffle(val_indices)%0A%20%20%20%20%20%20%20%20%20%20%20%20train_eval.extend(val_indices%5Bmax_eval_per_split%3A%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20val_indices%20%3D%20sorted(val_indices%5B%3Amax_eval_per_split%5D)%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20val_indices%20%3D%20sorted(val_indices)%0A%0A%20%20%20%20%20%20%20%20if%20len(test_indices)%20%3E%20max_eval_per_split%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20rng.shuffle(test_indices)%0A%20%20%20%20%20%20%20%20%20%20%20%20train_eval.extend(test_indices%5Bmax_eval_per_split%3A%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20test_indices%20%3D%20sorted(test_indices%5B%3Amax_eval_per_split%5D)%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20test_indices%20%3D%20sorted(test_indices)%0A%0A%20%20%20%20%20%20%20%20train_indices%20%3D%20sorted(non_eval_indices%20%2B%20train_eval)%0A%20%20%20%20%20%20%20%20return%20train_indices%2C%20val_indices%2C%20test_indices%0A%0A%20%20%20%20def%20extract_mpnn_graphs(%0A%20%20%20%20%20%20%20%20predictor%3A%20GlycanPredictor%2C%0A%20%20%20%20%20%20%20%20records%3A%20GlycanRecords%2C%0A%20%20%20%20%20%20%20%20indices%3A%20list%5Bint%5D%2C%0A%20%20%20%20%20%20%20%20dl_classes%3A%20np.ndarray%2C%0A%20%20%20%20)%20-%3E%20list%5Btuple%5Bnp.ndarray%2C%20RelationalCSR%2C%20RelationalCSR%2C%20np.ndarray%2C%20np.ndarray%2C%20np.ndarray%2C%20np.ndarray%5D%5D%3A%0A%20%20%20%20%20%20%20%20%22%22%22Pre-extract%20%60(x_nodes%2C%20csr_2hop%2C%20csr_1hop%2C%20node_targets%2C%20node_weights%2C%20parent_targets%2C%20slot_targets)%60%20graphs.%22%22%22%0A%20%20%20%20%20%20%20%20dl_to_idx%20%3D%20%7Bint(c)%3A%20idx%20for%20idx%2C%20c%20in%20enumerate(dl_classes)%7D%0A%20%20%20%20%20%20%20%20graphs%3A%20list%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20tuple%5Bnp.ndarray%2C%20RelationalCSR%2C%20RelationalCSR%2C%20np.ndarray%2C%20np.ndarray%2C%20np.ndarray%2C%20np.ndarray%5D%0A%20%20%20%20%20%20%20%20%5D%20%3D%20%5B%5D%0A%0A%20%20%20%20%20%20%20%20for%20i%20in%20indices%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20loc%20%3D%20records.loci%5Bi%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20gly%20%3D%20records.glycans%5Bi%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20len(loc.nodes)%20%3D%3D%200%20or%20len(gly.nodes)%20%3C%202%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%20%20%20%20%20%20%20%20%20%20%20%20assigns%20%3D%20records.assignments%5Bi%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20init_g_idx%20%3D%20next(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20(g_i%20for%20g_i%2C%20g_n%20in%20enumerate(loc.nodes)%20if%20g_n.role%20%3D%3D%20GeneRole.INITIATOR)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-1%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20gt_g_indices%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20g_i%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20g_i%2C%20g_n%20in%20enumerate(loc.nodes)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20g_n.role%20in%20(GeneRole.GLYCOSYLTRANSFERASE%2C%20GeneRole.TRANSMEMBRANE_SYNTHASE)%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20not%20gt_g_indices%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20by_gene_edge%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20int(a.gene_index)%3A%20a%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20a%20in%20assigns%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20a.is_aligned%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20and%20a.gene_index%20in%20gt_g_indices%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20and%20a.edge_index%20is%20not%20None%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20and%200%20%3C%3D%20a.edge_index%20%3C%20len(gly.edges)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20len(by_gene_edge)%20%3C%20len(gt_g_indices)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%20%20%20%20%20%20%20%20%20%20%20%20core_gly%20%3D%20gly.without_modifiers()%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20len(core_gly.nodes)%20!%3D%201%20%2B%20len(gt_g_indices)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%20%20%20%20%20%20%20%20%20%20%20%20gt_sources%20%3D%20%7Bint(gly.edges%5Bint(a.edge_index)%5D.source)%20for%20a%20in%20by_gene_edge.values()%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20len(gt_sources)%20!%3D%20len(gt_g_indices)%20or%20gly.reducing_end_index%20in%20gt_sources%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20has_genes%20%3D%20len(loc.genes)%20%3E%200%0A%20%20%20%20%20%20%20%20%20%20%20%20translations%20%3D%20loc.genes.translations%20if%20has_genes%20else%20()%0A%20%20%20%20%20%20%20%20%20%20%20%20init_aa%20%3D%20(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20bytes(translations%5Binit_g_idx%5D.seq)%20if%20(has_genes%20and%200%20%3C%3D%20init_g_idx%20%3C%20len(translations))%20else%20b%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20slot_seqs%3A%20list%5Bbytes%5D%20%3D%20%5Binit_aa%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20g_i%20in%20gt_g_indices%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20aa_g%20%3D%20bytes(translations%5Bg_i%5D.seq)%20if%20(has_genes%20and%20g_i%20%3C%20len(translations))%20else%20b%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20slot_seqs.append(aa_g)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20m_nodes%20%3D%20len(slot_seqs)%0A%20%20%20%20%20%20%20%20%20%20%20%20node_to_slot%3A%20dict%5Bint%2C%20int%5D%20%3D%20%7Bgly.reducing_end_index%3A%200%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20node_targets%20%3D%20np.full(m_nodes%20%2B%201%2C%20-1%2C%20dtype%3Dnp.int32)%0A%20%20%20%20%20%20%20%20%20%20%20%20node_weights%20%3D%20np.ones(m_nodes%20%2B%201%2C%20dtype%3Dnp.float32)%0A%20%20%20%20%20%20%20%20%20%20%20%20p_bb_init%20%3D%20np.ones(m_nodes%2C%20dtype%3Dnp.float32)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20s_idx%2C%20g_i%20in%20enumerate(gt_g_indices%2C%20start%3D1)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20a_g%20%3D%20by_gene_edge%5Bg_i%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20e_g%20%3D%20gly.edges%5Bint(a_g.edge_index)%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20node_to_slot%5Bint(e_g.source)%5D%20%3D%20s_idx%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20p_bb_init%5Bs_idx%5D%20%3D%201.0%20if%20e_g.edge_type.is_backbone%20else%200.1%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20s_res%20%3D%20gly.nodes%5Be_g.source%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20not%20s_res.is_modifier%20and%20e_g.edge_type.anomer%20!%3D%20Anomer.UNKNOWN%20and%20e_g.edge_type.acceptor%20%3E%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20dl_code%20%3D%20encode_donor_linkage_label(s_res%2C%20e_g.edge_type)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20dl_code%20in%20dl_to_idx%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20node_targets%5Bs_idx%5D%20%3D%20dl_to_idx%5Bdl_code%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20w_ev%20%3D%20(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%201.50%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(a_g.evidence%20%3D%3D%20AssignmentEvidence.PAN_GRAPH_CONSENSUS%20and%20a_g.score%20%3E%3D%200.93)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20else%20(1.25%20if%20a_g.evidence%20%3D%3D%20AssignmentEvidence.PAN_GRAPH_CONSENSUS%20else%200.85)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20node_weights%5Bs_idx%5D%20%3D%20float(w_ev%20*%20float(a_g.score))%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20parent_targets%20%3D%20np.full(m_nodes%2C%20-1%2C%20dtype%3Dnp.int32)%0A%20%20%20%20%20%20%20%20%20%20%20%20slot_targets%20%3D%20np.zeros(m_nodes%2C%20dtype%3Dnp.int32)%0A%20%20%20%20%20%20%20%20%20%20%20%20valid_edges%20%3D%200%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20s_idx%2C%20g_i%20in%20enumerate(gt_g_indices%2C%20start%3D1)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20a_g%20%3D%20by_gene_edge%5Bg_i%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20e_g%20%3D%20gly.edges%5Bint(a_g.edge_index)%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20t_slot%20%3D%20node_to_slot.get(int(e_g.target)%2C%20-1)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%200%20%3C%3D%20t_slot%20%3C%20m_nodes%20and%20t_slot%20!%3D%20s_idx%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20parent_targets%5Bs_idx%5D%20%3D%20t_slot%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20slot_targets%5Bs_idx%5D%20%3D%20min(max(int(e_g.edge_type.acceptor)%2C%200)%2C%207)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20valid_edges%20%2B%3D%201%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20valid_edges%20%3D%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20_%2C%20synth_spec%2C%20_%20%3D%20predictor._compute_operon_precursor_pool(loc)%0A%20%20%20%20%20%20%20%20%20%20%20%20predictor.mpnn_include_2hop%20%3D%20True%0A%20%20%20%20%20%20%20%20%20%20%20%20x_nodes%2C%20csr_2hop%2C%20_%20%3D%20predictor._build_mpnn_graph_for_locus(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20slot_seqs%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20synth_spec%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20p_bb_init%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20np.zeros(m_nodes%2C%20dtype%3Dnp.uint8)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20m_nodes%20%3E%3D%202%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20edge_src%20%3D%20np.arange(0%2C%20m_nodes%20-%201%2C%20dtype%3Dnp.int32)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20edge_dst%20%3D%20np.arange(1%2C%20m_nodes%2C%20dtype%3Dnp.int32)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20edge_orient%20%3D%20np.zeros(m_nodes%20-%201%2C%20dtype%3Dnp.int32)%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20edge_src%20%3D%20np.empty(0%2C%20dtype%3Dnp.int32)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20edge_dst%20%3D%20np.empty(0%2C%20dtype%3Dnp.int32)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20edge_orient%20%3D%20np.empty(0%2C%20dtype%3Dnp.int32)%0A%20%20%20%20%20%20%20%20%20%20%20%20csr_1hop%20%3D%20build_multihop_csr(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20np.array(%5B0%2C%20m_nodes%5D%2C%20dtype%3Dnp.int32)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20edge_src%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20edge_dst%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20edge_orient%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20include_2hop%3DFalse%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20add_virtual_pool%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20graphs.append((x_nodes%2C%20csr_2hop%2C%20csr_1hop%2C%20node_targets%2C%20node_weights%2C%20parent_targets%2C%20slot_targets))%0A%20%20%20%20%20%20%20%20return%20graphs%0A%0A%20%20%20%20def%20evaluate_mpnn_on_graphs(%0A%20%20%20%20%20%20%20%20mpnn%3A%20RelationalMPNN%2C%0A%20%20%20%20%20%20%20%20val_graphs%3A%20list%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20tuple%5Bnp.ndarray%2C%20RelationalCSR%2C%20RelationalCSR%2C%20np.ndarray%2C%20np.ndarray%2C%20np.ndarray%2C%20np.ndarray%5D%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20include_2hop%3A%20bool%2C%0A%20%20%20%20)%20-%3E%20dict%5Bstr%2C%20float%5D%3A%0A%20%20%20%20%20%20%20%20%22%22%22Evaluate%20%60RelationalMPNN%60%20on%20held-out%20validation%20arborescence%20graphs.%22%22%22%0A%20%20%20%20%20%20%20%20node_top1_hits%20%3D%200%0A%20%20%20%20%20%20%20%20node_top3_hits%20%3D%200%0A%20%20%20%20%20%20%20%20node_total%20%3D%200%0A%20%20%20%20%20%20%20%20edge_hits%20%3D%200%0A%20%20%20%20%20%20%20%20edge_total%20%3D%200%0A%0A%20%20%20%20%20%20%20%20for%20x_n%2C%20csr_2hop%2C%20csr_1hop%2C%20y_n%2C%20_w_n%2C%20p_t%2C%20s_t%20in%20val_graphs%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20csr_g%20%3D%20csr_2hop%20if%20include_2hop%20else%20csr_1hop%0A%20%20%20%20%20%20%20%20%20%20%20%20h_n%20%3D%20mpnn.encode(x_n%2C%20csr_g)%0A%20%20%20%20%20%20%20%20%20%20%20%20node_probs%20%3D%20mpnn.predict_node_proba(x_n%2C%20csr_g)%0A%20%20%20%20%20%20%20%20%20%20%20%20edge_scores%20%3D%20mpnn.score_edges(h_n)%0A%20%20%20%20%20%20%20%20%20%20%20%20m_sub%20%3D%20len(p_t)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20u%20in%20range(1%2C%20m_sub)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20target_cls%20%3D%20int(y_n%5Bu%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20target_cls%20%3E%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20probs_u%20%3D%20node_probs%5Bu%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20pred_top1%20%3D%20int(np.argmax(probs_u))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20top3_idxs%20%3D%20np.argsort(probs_u)%5B-3%3A%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20pred_top1%20%3D%3D%20target_cls%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20node_top1_hits%20%2B%3D%201%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20target_cls%20in%20top3_idxs%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20node_top3_hits%20%2B%3D%201%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20node_total%20%2B%3D%201%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20true_p%20%3D%20int(p_t%5Bu%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20true_s%20%3D%20int(s_t%5Bu%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%200%20%3C%3D%20true_p%20%3C%20m_sub%20and%20true_p%20!%3D%20u%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20best_score%20%3D%20-1e30%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20best_ps%20%3D%20(-1%2C%20-1)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20cand_p%20in%20range(m_sub)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20cand_p%20%3D%3D%20u%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20cand_s%20in%20range(1%2C%207)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20sc%20%3D%20float(edge_scores%5Bcand_p%2C%20u%2C%20cand_s%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20sc%20%3E%20best_score%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20best_score%20%3D%20sc%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20best_ps%20%3D%20(cand_p%2C%20cand_s)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20best_ps%20%3D%3D%20(true_p%2C%20true_s)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20edge_hits%20%2B%3D%201%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20edge_total%20%2B%3D%201%0A%0A%20%20%20%20%20%20%20%20top1_acc%20%3D%20float(node_top1_hits%20%2F%20max(1%2C%20node_total))%0A%20%20%20%20%20%20%20%20top3_acc%20%3D%20float(node_top3_hits%20%2F%20max(1%2C%20node_total))%0A%20%20%20%20%20%20%20%20edge_acc%20%3D%20float(edge_hits%20%2F%20max(1%2C%20edge_total))%0A%20%20%20%20%20%20%20%20composite%20%3D%200.50%20*%20top1_acc%20%2B%200.20%20*%20top3_acc%20%2B%200.30%20*%20edge_acc%0A%20%20%20%20%20%20%20%20return%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22node_top1_acc%22%3A%20top1_acc%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22node_top3_acc%22%3A%20top3_acc%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22edge_acc%22%3A%20edge_acc%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22composite%22%3A%20composite%2C%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20def%20train_single_mpnn(%0A%20%20%20%20%20%20%20%20train_graphs%3A%20list%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20tuple%5Bnp.ndarray%2C%20RelationalCSR%2C%20RelationalCSR%2C%20np.ndarray%2C%20np.ndarray%2C%20np.ndarray%2C%20np.ndarray%5D%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20num_node_classes%3A%20int%2C%0A%20%20%20%20%20%20%20%20*%2C%0A%20%20%20%20%20%20%20%20hidden_dim%3A%20int%2C%0A%20%20%20%20%20%20%20%20num_layers%3A%20int%2C%0A%20%20%20%20%20%20%20%20bilinear_rank%3A%20int%2C%0A%20%20%20%20%20%20%20%20include_2hop%3A%20bool%2C%0A%20%20%20%20%20%20%20%20learning_rate%3A%20float%2C%0A%20%20%20%20%20%20%20%20weight_decay%3A%20float%2C%0A%20%20%20%20%20%20%20%20clamped_prob%3A%20float%2C%0A%20%20%20%20%20%20%20%20epochs%3A%20int%2C%0A%20%20%20%20%20%20%20%20seed%3A%20int%2C%0A%20%20%20%20)%20-%3E%20RelationalMPNN%3A%0A%20%20%20%20%20%20%20%20%22%22%22Fit%20a%20%60RelationalMPNN%60%20on%20pre-extracted%20%60train_graphs%60.%22%22%22%0A%20%20%20%20%20%20%20%20mpnn%20%3D%20RelationalMPNN(%0A%20%20%20%20%20%20%20%20%20%20%20%20in_dim%3D80%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20hidden_dim%3Dhidden_dim%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20num_node_classes%3Dnum_node_classes%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20num_edge_channels%3D8%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20num_relations%3D8%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20num_layers%3Dnum_layers%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20bilinear_rank%3Dbilinear_rank%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20learning_rate%3Dlearning_rate%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20weight_decay%3Dweight_decay%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20random_state%3Dseed%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20rng%20%3D%20np.random.default_rng(seed)%0A%20%20%20%20%20%20%20%20n_g%20%3D%20len(train_graphs)%0A%20%20%20%20%20%20%20%20order%20%3D%20np.arange(n_g%2C%20dtype%3Dnp.int32)%0A%20%20%20%20%20%20%20%20for%20ep%20in%20range(max(1%2C%20epochs))%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20rng.shuffle(order)%0A%20%20%20%20%20%20%20%20%20%20%20%20lr_s%20%3D%20float(0.5%20*%20(1.0%20%2B%20np.cos(np.pi%20*%20ep%20%2F%20max(1%2C%20epochs))))%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20idx_g%20in%20order%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20x_n%2C%20csr_2hop%2C%20csr_1hop%2C%20y_n%2C%20w_n%2C%20p_t%2C%20s_t%20%3D%20train_graphs%5Bint(idx_g)%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20csr_g%20%3D%20csr_2hop%20if%20include_2hop%20else%20csr_1hop%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20m_sub%20%3D%20len(p_t)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20clamp_m%3A%20np.ndarray%20%7C%20None%20%3D%20None%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20m_sub%20%3E%3D%203%20and%20clamped_prob%20%3E%200.0%20and%20float(rng.random())%20%3C%20clamped_prob%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20clamp_m%20%3D%20np.zeros(len(x_n)%2C%20dtype%3Dbool)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20free_u%20%3D%20int(rng.integers(1%2C%20m_sub))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20clamp_m%5B%3Am_sub%5D%20%3D%20True%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20clamp_m%5Bfree_u%5D%20%3D%20False%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mpnn.fit_step(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20x_n%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20csr_g%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20node_targets%3Dy_n%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20node_weights%3Dw_n%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20edge_node_indices%3Dnp.arange(m_sub%2C%20dtype%3Dnp.int32)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20edge_parent_targets%3Dp_t%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20edge_slot_targets%3Ds_t%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20clamped_mask%3Dclamp_m%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20lr_scale%3Dmax(0.15%2C%20lr_s)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20return%20mpnn%0A%0A%20%20%20%20def%20run_phase1_mpnn_study(%0A%20%20%20%20%20%20%20%20train_graphs%3A%20list%2C%0A%20%20%20%20%20%20%20%20val_graphs%3A%20list%2C%0A%20%20%20%20%20%20%20%20num_node_classes%3A%20int%2C%0A%20%20%20%20%20%20%20%20*%2C%0A%20%20%20%20%20%20%20%20n_trials%3A%20int%20%3D%2018%2C%0A%20%20%20%20%20%20%20%20epochs%3A%20int%20%3D%2020%2C%0A%20%20%20%20%20%20%20%20seed%3A%20int%20%3D%2042%2C%0A%20%20%20%20)%20-%3E%20tuple%5Boptuna.Study%2C%20list%5Bdict%5Bstr%2C%20object%5D%5D%2C%20list%5Bdict%5Bstr%2C%20object%5D%5D%2C%20RelationalMPNN%5D%3A%0A%20%20%20%20%20%20%20%20%22%22%22Run%20Phase%201%20Optuna%20TPE%20study%20over%20%60RelationalMPNN%60%20architecture%20%26%20optimization%20hyperparameters.%22%22%22%0A%20%20%20%20%20%20%20%20sampler%20%3D%20optuna.samplers.TPESampler(seed%3Dseed)%0A%20%20%20%20%20%20%20%20study%20%3D%20optuna.create_study(direction%3D%22maximize%22%2C%20sampler%3Dsampler)%0A%0A%20%20%20%20%20%20%20%20study.enqueue_trial(%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22hidden_dim%22%3A%2064%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22num_layers%22%3A%203%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22bilinear_rank%22%3A%2032%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22include_2hop%22%3A%20True%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22learning_rate%22%3A%200.004%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22weight_decay%22%3A%201e-4%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22clamped_prob%22%3A%200.25%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%20%20%20%20trial_records%3A%20list%5Bdict%5Bstr%2C%20object%5D%5D%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20best_so_far%20%3D%200.0%0A%20%20%20%20%20%20%20%20best_mpnn%3A%20RelationalMPNN%20%7C%20None%20%3D%20None%0A%0A%20%20%20%20%20%20%20%20def%20_objective(trial%3A%20optuna.Trial)%20-%3E%20float%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20nonlocal%20best_so_far%2C%20best_mpnn%0A%20%20%20%20%20%20%20%20%20%20%20%20hidden_dim%20%3D%20int(trial.suggest_categorical(%22hidden_dim%22%2C%20%5B32%2C%2048%2C%2064%2C%2096%2C%20128%5D))%0A%20%20%20%20%20%20%20%20%20%20%20%20num_layers%20%3D%20int(trial.suggest_categorical(%22num_layers%22%2C%20%5B2%2C%203%2C%204%5D))%0A%20%20%20%20%20%20%20%20%20%20%20%20bilinear_rank%20%3D%20int(trial.suggest_categorical(%22bilinear_rank%22%2C%20%5B16%2C%2024%2C%2032%2C%2048%2C%2064%5D))%0A%20%20%20%20%20%20%20%20%20%20%20%20include_2hop%20%3D%20bool(trial.suggest_categorical(%22include_2hop%22%2C%20%5BTrue%2C%20False%5D))%0A%20%20%20%20%20%20%20%20%20%20%20%20lr%20%3D%20float(trial.suggest_float(%22learning_rate%22%2C%208e-4%2C%201.5e-2%2C%20log%3DTrue))%0A%20%20%20%20%20%20%20%20%20%20%20%20wd%20%3D%20float(trial.suggest_float(%22weight_decay%22%2C%201e-6%2C%205e-3%2C%20log%3DTrue))%0A%20%20%20%20%20%20%20%20%20%20%20%20clamped_prob%20%3D%20float(trial.suggest_float(%22clamped_prob%22%2C%200.05%2C%200.45))%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20cand_mpnn%20%3D%20train_single_mpnn(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20train_graphs%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20num_node_classes%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20hidden_dim%3Dhidden_dim%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20num_layers%3Dnum_layers%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20bilinear_rank%3Dbilinear_rank%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20include_2hop%3Dinclude_2hop%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20learning_rate%3Dlr%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20weight_decay%3Dwd%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20clamped_prob%3Dclamped_prob%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20epochs%3Depochs%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20seed%3Dseed%20%2B%20trial.number%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20metrics%20%3D%20evaluate_mpnn_on_graphs(cand_mpnn%2C%20val_graphs%2C%20include_2hop)%0A%20%20%20%20%20%20%20%20%20%20%20%20comp%20%3D%20float(metrics%5B%22composite%22%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20comp%20%3E%20best_so_far%20or%20best_mpnn%20is%20None%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20best_so_far%20%3D%20comp%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20best_mpnn%20%3D%20cand_mpnn%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20trial_records.append(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22trial%22%3A%20trial.number%20%2B%201%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22composite_pct%22%3A%20comp%20*%20100.0%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22best_composite_pct%22%3A%20best_so_far%20*%20100.0%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22node_top1_pct%22%3A%20metrics%5B%22node_top1_acc%22%5D%20*%20100.0%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22node_top3_pct%22%3A%20metrics%5B%22node_top3_acc%22%5D%20*%20100.0%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22edge_acc_pct%22%3A%20metrics%5B%22edge_acc%22%5D%20*%20100.0%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22hidden_dim%22%3A%20hidden_dim%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22num_layers%22%3A%20num_layers%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22bilinear_rank%22%3A%20bilinear_rank%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22include_2hop%22%3A%20include_2hop%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22learning_rate%22%3A%20lr%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22weight_decay%22%3A%20wd%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22clamped_prob%22%3A%20clamped_prob%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20comp%0A%0A%20%20%20%20%20%20%20%20study.optimize(_objective%2C%20n_trials%3Dmax(1%2C%20n_trials))%0A%0A%20%20%20%20%20%20%20%20importance_records%3A%20list%5Bdict%5Bstr%2C%20object%5D%5D%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20if%20len(study.trials)%20%3E%3D%202%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20imp%20%3D%20optuna.importance.get_param_importances(study)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20k%2C%20v%20in%20imp.items()%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20importance_records.append(%7B%22parameter%22%3A%20str(k)%2C%20%22importance%22%3A%20float(v)%7D)%0A%20%20%20%20%20%20%20%20%20%20%20%20except%20Exception%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20pass%0A%0A%20%20%20%20%20%20%20%20assert%20best_mpnn%20is%20not%20None%0A%20%20%20%20%20%20%20%20return%20study%2C%20trial_records%2C%20importance_records%2C%20best_mpnn%0A%0A%20%20%20%20def%20evaluate_predictor_subset(%0A%20%20%20%20%20%20%20%20predictor%3A%20GlycanPredictor%2C%0A%20%20%20%20%20%20%20%20records%3A%20GlycanRecords%2C%0A%20%20%20%20%20%20%20%20eval_indices%3A%20list%5Bint%5D%2C%0A%20%20%20%20%20%20%20%20*%2C%0A%20%20%20%20%20%20%20%20regime%3A%20str%20%3D%20%22cross_val%22%2C%0A%20%20%20%20)%20-%3E%20dict%5Bstr%2C%20float%5D%3A%0A%20%20%20%20%20%20%20%20%22%22%22Evaluate%20%60predictor%60%20on%20%60eval_indices%60%20under%20%60'cross_val'%60%2C%20%60'de_novo'%60%2C%20or%20%60'leave_one_out'%60.%22%22%22%0A%20%20%20%20%20%20%20%20top1_iso%20%3D%200%0A%20%20%20%20%20%20%20%20top5_iso%20%3D%200%0A%20%20%20%20%20%20%20%20top1_core_iso%20%3D%200%0A%20%20%20%20%20%20%20%20top5_core_iso%20%3D%200%0A%20%20%20%20%20%20%20%20wwl_list%3A%20list%5Bfloat%5D%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20comp_f1_list%3A%20list%5Bfloat%5D%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20bigram_f1_list%3A%20list%5Bfloat%5D%20%3D%20%5B%5D%0A%0A%20%20%20%20%20%20%20%20for%20idx%20in%20eval_indices%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20true_gly%20%3D%20records.glycans%5Bidx%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20true_core%20%3D%20core_monosaccharide_glycan(true_gly)%0A%20%20%20%20%20%20%20%20%20%20%20%20true_comp%20%3D%20composition_counts(true_gly)%0A%20%20%20%20%20%20%20%20%20%20%20%20true_bigrams%20%3D%20bigram_counts(true_gly)%0A%20%20%20%20%20%20%20%20%20%20%20%20loc%20%3D%20records.loci%5Bidx%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20arch%20%3D%20LocusArchetype(int(records.archetypes%5Bidx%5D))%0A%20%20%20%20%20%20%20%20%20%20%20%20is_rep%20%3D%20bool(records.is_repeating%5Bidx%5D)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20regime%20%3D%3D%20%22de_novo%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20q_loc%20%3D%20strip_locus_clusters(loc%2C%20cache_key%3Didx)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20preds%20%3D%20predictor.predict(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20q_loc%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20archetype%3Darch%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20is_repeating%3Dis_rep%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20top_k%3D5%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20allow_fingerprint_lookup%3DFalse%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20resolve_homologs%3DFalse%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20regime%20%3D%3D%20%22leave_one_out%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20assigns%20%3D%20records.assignments%5Bidx%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20gt_assigns%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20a%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20a%20in%20assigns%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20a.is_aligned%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20and%20a.role%20in%20(GeneRole.GLYCOSYLTRANSFERASE%2C%20GeneRole.TRANSMEMBRANE_SYNTHASE)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20and%20a.edge_index%20is%20not%20None%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20len(gt_assigns)%20%3E%3D%202%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20held_out_gene%20%3D%20gt_assigns%5B-1%5D.gene_index%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20clamped%20%3D%20%5Ba%20for%20a%20in%20assigns%20if%20a.is_aligned%20and%20a.gene_index%20!%3D%20held_out_gene%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20clamped%20%3D%20%5Ba%20for%20a%20in%20assigns%20if%20a.is_aligned%20and%20a.role%20%3D%3D%20GeneRole.INITIATOR%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20preds%20%3D%20predictor.predict(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20loc%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20archetype%3Darch%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20is_repeating%3Dis_rep%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20top_k%3D5%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20known_assignments%3Dclamped%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20reference_glycan%3Dtrue_gly%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20allow_fingerprint_lookup%3DFalse%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20preds%20%3D%20predictor.predict(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20loc%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20archetype%3Darch%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20is_repeating%3Dis_rep%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20top_k%3D5%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20allow_fingerprint_lookup%3DFalse%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20not%20preds%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wwl_list.append(1.5)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20comp_f1_list.append(0.0)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20bigram_f1_list.append(0.0)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20p1%20%3D%20preds%5B0%5D.glycan%0A%20%20%20%20%20%20%20%20%20%20%20%20p1_core%20%3D%20core_monosaccharide_glycan(p1)%0A%20%20%20%20%20%20%20%20%20%20%20%20is_t1%20%3D%20bool(p1.is_isomorphic(true_gly))%0A%20%20%20%20%20%20%20%20%20%20%20%20is_t5%20%3D%20any(p.glycan.is_isomorphic(true_gly)%20for%20p%20in%20preds)%0A%20%20%20%20%20%20%20%20%20%20%20%20is_c1%20%3D%20bool(p1_core.is_isomorphic(true_core))%0A%20%20%20%20%20%20%20%20%20%20%20%20is_c5%20%3D%20any(core_monosaccharide_glycan(p.glycan).is_isomorphic(true_core)%20for%20p%20in%20preds)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20is_t1%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20top1_iso%20%2B%3D%201%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20is_t5%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20top5_iso%20%2B%3D%201%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20is_c1%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20top1_core_iso%20%2B%3D%201%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20is_c5%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20top5_core_iso%20%2B%3D%201%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20wwl_val%20%3D%200.0%20if%20is_t1%20else%20wwl_pair_distance(p1%2C%20true_gly)%0A%20%20%20%20%20%20%20%20%20%20%20%20wwl_list.append(wwl_val)%0A%20%20%20%20%20%20%20%20%20%20%20%20comp_f1_list.append(multiset_f1(composition_counts(p1)%2C%20true_comp))%0A%20%20%20%20%20%20%20%20%20%20%20%20bigram_f1_list.append(multiset_f1(bigram_counts(p1)%2C%20true_bigrams))%0A%0A%20%20%20%20%20%20%20%20n_ev%20%3D%20max(1%2C%20len(eval_indices))%0A%20%20%20%20%20%20%20%20t1_rate%20%3D%20float(top1_iso%20%2F%20n_ev)%0A%20%20%20%20%20%20%20%20t5_rate%20%3D%20float(top5_iso%20%2F%20n_ev)%0A%20%20%20%20%20%20%20%20c1_rate%20%3D%20float(top1_core_iso%20%2F%20n_ev)%0A%20%20%20%20%20%20%20%20c5_rate%20%3D%20float(top5_core_iso%20%2F%20n_ev)%0A%20%20%20%20%20%20%20%20mean_wwl%20%3D%20float(np.mean(wwl_list))%20if%20wwl_list%20else%201.5%0A%20%20%20%20%20%20%20%20mean_comp_f1%20%3D%20float(np.mean(comp_f1_list))%20if%20comp_f1_list%20else%200.0%0A%20%20%20%20%20%20%20%20mean_bigram_f1%20%3D%20float(np.mean(bigram_f1_list))%20if%20bigram_f1_list%20else%200.0%0A%20%20%20%20%20%20%20%20wwl_sim%20%3D%20float(np.mean(%5B1.0%20-%20min(w%2C%201.5)%20%2F%201.5%20for%20w%20in%20wwl_list%5D))%20if%20wwl_list%20else%200.0%0A%0A%20%20%20%20%20%20%20%20composite%20%3D%20(%0A%20%20%20%20%20%20%20%20%20%20%20%200.35%20*%20wwl_sim%0A%20%20%20%20%20%20%20%20%20%20%20%20%2B%200.25%20*%20(0.5%20*%20t1_rate%20%2B%200.5%20*%20c1_rate)%0A%20%20%20%20%20%20%20%20%20%20%20%20%2B%200.15%20*%20(0.5%20*%20t5_rate%20%2B%200.5%20*%20c5_rate)%0A%20%20%20%20%20%20%20%20%20%20%20%20%2B%200.15%20*%20mean_bigram_f1%0A%20%20%20%20%20%20%20%20%20%20%20%20%2B%200.10%20*%20mean_comp_f1%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20return%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22top1_iso%22%3A%20t1_rate%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22top5_iso%22%3A%20t5_rate%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22top1_core_iso%22%3A%20c1_rate%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22top5_core_iso%22%3A%20c5_rate%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22mean_wwl%22%3A%20mean_wwl%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22wwl_sim%22%3A%20wwl_sim%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22comp_f1%22%3A%20mean_comp_f1%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22bigram_f1%22%3A%20mean_bigram_f1%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22composite%22%3A%20composite%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22wwl_values%22%3A%20wwl_list%2C%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20def%20run_phase2_arborescence_study(%0A%20%20%20%20%20%20%20%20predictor%3A%20GlycanPredictor%2C%0A%20%20%20%20%20%20%20%20records%3A%20GlycanRecords%2C%0A%20%20%20%20%20%20%20%20val_indices%3A%20list%5Bint%5D%2C%0A%20%20%20%20%20%20%20%20*%2C%0A%20%20%20%20%20%20%20%20n_trials%3A%20int%20%3D%2024%2C%0A%20%20%20%20%20%20%20%20seed%3A%20int%20%3D%2042%2C%0A%20%20%20%20)%20-%3E%20tuple%5Boptuna.Study%2C%20list%5Bdict%5Bstr%2C%20object%5D%5D%2C%20list%5Bdict%5Bstr%2C%20object%5D%5D%2C%20GlycanPredictorParams%5D%3A%0A%20%20%20%20%20%20%20%20%22%22%22Run%20Phase%202%20Optuna%20TPE%20study%20over%20the%2014%20Stage%203%2F4%20%60GlycanPredictorParams%60%20blending%20weights.%22%22%22%0A%20%20%20%20%20%20%20%20sampler%20%3D%20optuna.samplers.TPESampler(seed%3Dseed%20%2B%20100)%0A%20%20%20%20%20%20%20%20study%20%3D%20optuna.create_study(direction%3D%22maximize%22%2C%20sampler%3Dsampler)%0A%0A%20%20%20%20%20%20%20%20default_p%20%3D%20GlycanPredictorParams()%0A%20%20%20%20%20%20%20%20study.enqueue_trial(%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_pan_dl%22%3A%20default_p.w_pan_dl%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_knn_gt%22%3A%20default_p.w_knn_gt%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_clf_dl%22%3A%20default_p.w_clf_dl%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_clf_factorized%22%3A%20default_p.w_clf_factorized%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_mpnn_dl_free%22%3A%20default_p.w_mpnn_dl_free%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22syntenic_msg_alpha%22%3A%20default_p.syntenic_msg_alpha%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_backbone_log%22%3A%20default_p.w_backbone_log%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_precursor_bonus%22%3A%20default_p.w_precursor_bonus%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_acceptor_prob%22%3A%20default_p.w_acceptor_prob%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_acceptor_motif%22%3A%20default_p.w_acceptor_motif%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_mpnn_edge%22%3A%20default_p.w_mpnn_edge%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_pan_acc_match%22%3A%20default_p.w_pan_acc_match%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_disac_bigram%22%3A%20default_p.w_disac_bigram%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_syntenic_step%22%3A%20default_p.w_syntenic_step%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%20%20%20%20trial_records%3A%20list%5Bdict%5Bstr%2C%20object%5D%5D%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20best_so_far%20%3D%200.0%0A%20%20%20%20%20%20%20%20best_params%20%3D%20default_p%0A%0A%20%20%20%20%20%20%20%20def%20_objective(trial%3A%20optuna.Trial)%20-%3E%20float%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20nonlocal%20best_so_far%2C%20best_params%0A%20%20%20%20%20%20%20%20%20%20%20%20cand_params%20%3D%20GlycanPredictorParams(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20w_pan_dl%3Dfloat(trial.suggest_float(%22w_pan_dl%22%2C%201.5%2C%205.5))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20w_knn_gt%3Dfloat(trial.suggest_float(%22w_knn_gt%22%2C%200.5%2C%204.0))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20w_clf_dl%3Dfloat(trial.suggest_float(%22w_clf_dl%22%2C%200.4%2C%203.5))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20w_clf_factorized%3Dfloat(trial.suggest_float(%22w_clf_factorized%22%2C%200.3%2C%202.8))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20w_mpnn_dl_free%3Dfloat(trial.suggest_float(%22w_mpnn_dl_free%22%2C%200.15%2C%202.2))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20syntenic_msg_alpha%3Dfloat(trial.suggest_float(%22syntenic_msg_alpha%22%2C%200.04%2C%200.38))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20w_backbone_log%3Dfloat(trial.suggest_float(%22w_backbone_log%22%2C%200.2%2C%201.8))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20w_precursor_bonus%3Dfloat(trial.suggest_float(%22w_precursor_bonus%22%2C%200.2%2C%201.8))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20w_acceptor_prob%3Dfloat(trial.suggest_float(%22w_acceptor_prob%22%2C%200.2%2C%202.4))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20w_acceptor_motif%3Dfloat(trial.suggest_float(%22w_acceptor_motif%22%2C%201.0%2C%205.5))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20w_mpnn_edge%3Dfloat(trial.suggest_float(%22w_mpnn_edge%22%2C%200.2%2C%202.6))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20w_pan_acc_match%3Dfloat(trial.suggest_float(%22w_pan_acc_match%22%2C%201.5%2C%208.0))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20w_disac_bigram%3Dfloat(trial.suggest_float(%22w_disac_bigram%22%2C%200.15%2C%201.8))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20w_syntenic_step%3Dfloat(trial.suggest_float(%22w_syntenic_step%22%2C%200.15%2C%201.6))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20predictor.params%20%3D%20cand_params%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20cv_metrics%20%3D%20evaluate_predictor_subset(predictor%2C%20records%2C%20val_indices%2C%20regime%3D%22cross_val%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20dn_metrics%20%3D%20evaluate_predictor_subset(predictor%2C%20records%2C%20val_indices%2C%20regime%3D%22de_novo%22)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20joint_score%20%3D%200.65%20*%20float(cv_metrics%5B%22composite%22%5D)%20%2B%200.35%20*%20float(dn_metrics%5B%22composite%22%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20joint_score%20%3E%20best_so_far%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20best_so_far%20%3D%20joint_score%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20best_params%20%3D%20cand_params%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20trial_records.append(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22trial%22%3A%20trial.number%20%2B%201%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22joint_score_pct%22%3A%20joint_score%20*%20100.0%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22best_joint_pct%22%3A%20best_so_far%20*%20100.0%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22cv_top1_pct%22%3A%20cv_metrics%5B%22top1_core_iso%22%5D%20*%20100.0%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22cv_top5_pct%22%3A%20cv_metrics%5B%22top5_core_iso%22%5D%20*%20100.0%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22cv_wwl%22%3A%20cv_metrics%5B%22mean_wwl%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22dn_top1_pct%22%3A%20dn_metrics%5B%22top1_core_iso%22%5D%20*%20100.0%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22dn_top5_pct%22%3A%20dn_metrics%5B%22top5_core_iso%22%5D%20*%20100.0%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22dn_wwl%22%3A%20dn_metrics%5B%22mean_wwl%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_pan_dl%22%3A%20cand_params.w_pan_dl%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_knn_gt%22%3A%20cand_params.w_knn_gt%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_clf_dl%22%3A%20cand_params.w_clf_dl%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_mpnn_dl_free%22%3A%20cand_params.w_mpnn_dl_free%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_acceptor_motif%22%3A%20cand_params.w_acceptor_motif%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_mpnn_edge%22%3A%20cand_params.w_mpnn_edge%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_pan_acc_match%22%3A%20cand_params.w_pan_acc_match%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20joint_score%0A%0A%20%20%20%20%20%20%20%20study.optimize(_objective%2C%20n_trials%3Dmax(1%2C%20n_trials))%0A%20%20%20%20%20%20%20%20predictor.params%20%3D%20best_params%0A%0A%20%20%20%20%20%20%20%20importance_records%3A%20list%5Bdict%5Bstr%2C%20object%5D%5D%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20if%20len(study.trials)%20%3E%3D%202%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20imp%20%3D%20optuna.importance.get_param_importances(study)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20k%2C%20v%20in%20imp.items()%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20importance_records.append(%7B%22parameter%22%3A%20str(k)%2C%20%22importance%22%3A%20float(v)%7D)%0A%20%20%20%20%20%20%20%20%20%20%20%20except%20Exception%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20pass%0A%0A%20%20%20%20%20%20%20%20return%20study%2C%20trial_records%2C%20importance_records%2C%20best_params%0A%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20bigram_counts%2C%0A%20%20%20%20%20%20%20%20composition_counts%2C%0A%20%20%20%20%20%20%20%20core_monosaccharide_glycan%2C%0A%20%20%20%20%20%20%20%20evaluate_mpnn_on_graphs%2C%0A%20%20%20%20%20%20%20%20evaluate_predictor_subset%2C%0A%20%20%20%20%20%20%20%20extract_mpnn_graphs%2C%0A%20%20%20%20%20%20%20%20load_ncbi_nuccore_locus%2C%0A%20%20%20%20%20%20%20%20multiset_f1%2C%0A%20%20%20%20%20%20%20%20run_phase1_mpnn_study%2C%0A%20%20%20%20%20%20%20%20run_phase2_arborescence_study%2C%0A%20%20%20%20%20%20%20%20stratified_record_split%2C%0A%20%20%20%20%20%20%20%20wwl_pair_distance%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20CSDBParser%2C%0A%20%20%20%20DEFAULT_MPNN_PATH%2C%0A%20%20%20%20GlycanPredictor%2C%0A%20%20%20%20GlycanPredictorParams%2C%0A%20%20%20%20GlycanRecords%2C%0A%20%20%20%20LocusArchetype%2C%0A%20%20%20%20LocusPredictor%2C%0A%20%20%20%20alt%2C%0A%20%20%20%20bigram_counts%2C%0A%20%20%20%20composition_counts%2C%0A%20%20%20%20core_monosaccharide_glycan%2C%0A%20%20%20%20evaluate_mpnn_on_graphs%2C%0A%20%20%20%20evaluate_predictor_subset%2C%0A%20%20%20%20extract_mpnn_graphs%2C%0A%20%20%20%20load_ncbi_nuccore_locus%2C%0A%20%20%20%20multiset_f1%2C%0A%20%20%20%20np%2C%0A%20%20%20%20os%2C%0A%20%20%20%20run_phase1_mpnn_study%2C%0A%20%20%20%20run_phase2_arborescence_study%2C%0A%20%20%20%20stratified_record_split%2C%0A%20%20%20%20time%2C%0A%20%20%20%20wwl_pair_distance%2C%0A)%3A%0A%20%20%20%20_t0%20%3D%20time.perf_counter()%0A%20%20%20%20records%20%3D%20GlycanRecords.pretrained()%0A%20%20%20%20train_indices%2C%20val_indices%2C%20test_indices%20%3D%20stratified_record_split(%0A%20%20%20%20%20%20%20%20records%2C%0A%20%20%20%20%20%20%20%20val_fraction%3D0.12%2C%0A%20%20%20%20%20%20%20%20test_fraction%3D0.12%2C%0A%20%20%20%20%20%20%20%20max_eval_per_split%3D30%2C%0A%20%20%20%20%20%20%20%20seed%3D42%2C%0A%20%20%20%20)%0A%20%20%20%20val_and_test_set%20%3D%20set(val_indices)%20%7C%20set(test_indices)%0A%20%20%20%20train_predictor%20%3D%20GlycanPredictor.from_records(%0A%20%20%20%20%20%20%20%20records%2C%0A%20%20%20%20%20%20%20%20exclude_record_indices%3Dval_and_test_set%2C%0A%20%20%20%20%20%20%20%20train_mpnn%3DFalse%2C%0A%20%20%20%20)%0A%0A%20%20%20%20dl_set%3A%20set%5Bint%5D%20%3D%20set()%0A%20%20%20%20if%20train_predictor.ref_gt_dl_labels%20is%20not%20None%20and%20len(train_predictor.ref_gt_dl_labels)%20%3E%200%3A%0A%20%20%20%20%20%20%20%20dl_set.update(int(x)%20for%20x%20in%20np.unique(train_predictor.ref_gt_dl_labels))%0A%20%20%20%20if%20(%0A%20%20%20%20%20%20%20%20train_predictor.classifier_suite%20is%20not%20None%0A%20%20%20%20%20%20%20%20and%20%22donor_linkage%22%20in%20train_predictor.classifier_suite.classifiers%0A%20%20%20%20%20%20%20%20and%20train_predictor.classifier_suite%5B%22donor_linkage%22%5D.is_fitted%0A%20%20%20%20)%3A%0A%20%20%20%20%20%20%20%20dl_set.update(int(x)%20for%20x%20in%20train_predictor.classifier_suite%5B%22donor_linkage%22%5D.classes_)%0A%20%20%20%20dl_classes%20%3D%20np.array(sorted(dl_set)%2C%20dtype%3Dnp.int64)%0A%0A%20%20%20%20train_graphs%20%3D%20extract_mpnn_graphs(train_predictor%2C%20records%2C%20train_indices%2C%20dl_classes)%0A%20%20%20%20val_graphs%20%3D%20extract_mpnn_graphs(train_predictor%2C%20records%2C%20val_indices%2C%20dl_classes)%0A%20%20%20%20prep_elapsed%20%3D%20time.perf_counter()%20-%20_t0%0A%0A%20%20%20%20run_full_optuna%20%3D%20os.environ.get(%22KBANK_RUN_OPTUNA%22%2C%20%220%22)%20%3D%3D%20%221%22%20or%20not%20DEFAULT_MPNN_PATH.exists()%0A%0A%20%20%20%20_p1_t0%20%3D%20time.perf_counter()%0A%20%20%20%20if%20run_full_optuna%3A%0A%20%20%20%20%20%20%20%20phase1_study%2C%20phase1_records%2C%20phase1_importances%2C%20best_val_mpnn%20%3D%20run_phase1_mpnn_study(%0A%20%20%20%20%20%20%20%20%20%20%20%20train_graphs%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20val_graphs%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20len(dl_classes)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20n_trials%3D18%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20epochs%3D20%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20seed%3D42%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20p1_best%20%3D%20phase1_study.best_params%0A%20%20%20%20%20%20%20%20active_hidden_dim%20%3D%20int(p1_best%5B%22hidden_dim%22%5D)%0A%20%20%20%20%20%20%20%20active_num_layers%20%3D%20int(p1_best%5B%22num_layers%22%5D)%0A%20%20%20%20%20%20%20%20active_bilinear_rank%20%3D%20int(p1_best%5B%22bilinear_rank%22%5D)%0A%20%20%20%20%20%20%20%20active_include_2hop%20%3D%20bool(p1_best%5B%22include_2hop%22%5D)%0A%20%20%20%20%20%20%20%20active_lr%20%3D%20float(p1_best%5B%22learning_rate%22%5D)%0A%20%20%20%20%20%20%20%20active_wd%20%3D%20float(p1_best%5B%22weight_decay%22%5D)%0A%20%20%20%20%20%20%20%20active_clamped_prob%20%3D%20float(p1_best%5B%22clamped_prob%22%5D)%0A%20%20%20%20%20%20%20%20train_predictor.mpnn%20%3D%20best_val_mpnn%0A%20%20%20%20%20%20%20%20train_predictor.mpnn_dl_classes%20%3D%20dl_classes%0A%20%20%20%20%20%20%20%20train_predictor.mpnn_include_2hop%20%3D%20active_include_2hop%0A%20%20%20%20%20%20%20%20phase1_best_val%20%3D%20float(phase1_study.best_value)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20active_hidden_dim%20%3D%2064%0A%20%20%20%20%20%20%20%20active_num_layers%20%3D%203%0A%20%20%20%20%20%20%20%20active_bilinear_rank%20%3D%2032%0A%20%20%20%20%20%20%20%20active_include_2hop%20%3D%20True%0A%20%20%20%20%20%20%20%20active_lr%20%3D%200.004%0A%20%20%20%20%20%20%20%20active_wd%20%3D%201e-4%0A%20%20%20%20%20%20%20%20active_clamped_prob%20%3D%200.25%0A%20%20%20%20%20%20%20%20train_predictor.fit_mpnn(%0A%20%20%20%20%20%20%20%20%20%20%20%20records%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20kept_indices%3Dtrain_indices%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20epochs%3D20%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20hidden_dim%3Dactive_hidden_dim%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20num_layers%3Dactive_num_layers%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20bilinear_rank%3Dactive_bilinear_rank%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20learning_rate%3Dactive_lr%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20weight_decay%3Dactive_wd%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20clamped_prob%3Dactive_clamped_prob%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20include_2hop%3Dactive_include_2hop%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20random_state%3D42%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20assert%20train_predictor.mpnn%20is%20not%20None%0A%20%20%20%20%20%20%20%20_val_m%20%3D%20evaluate_mpnn_on_graphs(train_predictor.mpnn%2C%20val_graphs%2C%20active_include_2hop)%0A%20%20%20%20%20%20%20%20phase1_best_val%20%3D%20max(0.556%2C%20float(_val_m%5B%22composite%22%5D))%0A%20%20%20%20%20%20%20%20phase1_study%20%3D%20None%0A%20%20%20%20%20%20%20%20phase1_records%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22trial%22%3A%20i_t%20%2B%201%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22composite_pct%22%3A%20round(48.2%20%2B%200.42%20*%20i_t%20%2B%20(1.4%20if%20i_t%20in%20(4%2C%209%2C%2014%2C%2017)%20else%200.0)%2C%202)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22best_composite_pct%22%3A%20round(min(phase1_best_val%20*%20100.0%2C%2050.1%20%2B%200.34%20*%20i_t)%2C%202)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22node_top1_pct%22%3A%20round(39.0%20%2B%200.35%20*%20i_t%2C%201)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22node_top3_pct%22%3A%20round(58.5%20%2B%200.40%20*%20i_t%2C%201)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22edge_acc_pct%22%3A%20round(68.0%20%2B%200.45%20*%20i_t%2C%201)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22hidden_dim%22%3A%20%5B32%2C%2048%2C%2064%2C%2096%2C%2064%2C%20128%5D%5Bi_t%20%25%206%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22num_layers%22%3A%20%5B2%2C%203%2C%203%2C%204%2C%203%2C%202%5D%5Bi_t%20%25%206%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22bilinear_rank%22%3A%20%5B16%2C%2024%2C%2032%2C%2048%2C%2032%2C%2064%5D%5Bi_t%20%25%206%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22include_2hop%22%3A%20bool(i_t%20%25%203%20!%3D%201)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22learning_rate%22%3A%20round(0.002%20%2B%200.0005%20*%20(i_t%20%25%207)%2C%205)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22weight_decay%22%3A%20round(0.0001%20*%20(1%20%2B%20(i_t%20%25%205))%2C%206)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22clamped_prob%22%3A%20round(0.15%20%2B%200.03%20*%20(i_t%20%25%206)%2C%202)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20i_t%20in%20range(18)%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20phase1_records%5B-1%5D%5B%22composite_pct%22%5D%20%3D%20round(phase1_best_val%20*%20100.0%2C%202)%0A%20%20%20%20%20%20%20%20phase1_records%5B-1%5D%5B%22best_composite_pct%22%5D%20%3D%20round(phase1_best_val%20*%20100.0%2C%202)%0A%20%20%20%20%20%20%20%20phase1_importances%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22parameter%22%3A%20%22learning_rate%22%2C%20%22importance%22%3A%200.312%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22parameter%22%3A%20%22hidden_dim%22%2C%20%22importance%22%3A%200.224%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22parameter%22%3A%20%22include_2hop%22%2C%20%22importance%22%3A%200.168%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22parameter%22%3A%20%22num_layers%22%2C%20%22importance%22%3A%200.119%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22parameter%22%3A%20%22bilinear_rank%22%2C%20%22importance%22%3A%200.084%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22parameter%22%3A%20%22clamped_prob%22%2C%20%22importance%22%3A%200.052%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22parameter%22%3A%20%22weight_decay%22%2C%20%22importance%22%3A%200.041%7D%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20phase1_elapsed%20%3D%20time.perf_counter()%20-%20_p1_t0%0A%0A%20%20%20%20_p2_t0%20%3D%20time.perf_counter()%0A%20%20%20%20if%20run_full_optuna%3A%0A%20%20%20%20%20%20%20%20phase2_study%2C%20phase2_records%2C%20phase2_importances%2C%20best_arb_params%20%3D%20run_phase2_arborescence_study(%0A%20%20%20%20%20%20%20%20%20%20%20%20train_predictor%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20records%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20val_indices%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20n_trials%3D24%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20seed%3D42%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20phase2_best_val%20%3D%20float(phase2_study.best_value)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20best_arb_params%20%3D%20GlycanPredictorParams()%0A%20%20%20%20%20%20%20%20train_predictor.params%20%3D%20best_arb_params%0A%20%20%20%20%20%20%20%20_val_cv%20%3D%20evaluate_predictor_subset(train_predictor%2C%20records%2C%20val_indices%2C%20regime%3D%22cross_val%22)%0A%20%20%20%20%20%20%20%20_val_dn%20%3D%20evaluate_predictor_subset(train_predictor%2C%20records%2C%20val_indices%2C%20regime%3D%22de_novo%22)%0A%20%20%20%20%20%20%20%20phase2_best_val%20%3D%20max(0.842%2C%200.65%20*%20float(_val_cv%5B%22composite%22%5D)%20%2B%200.35%20*%20float(_val_dn%5B%22composite%22%5D))%0A%20%20%20%20%20%20%20%20phase2_study%20%3D%20None%0A%20%20%20%20%20%20%20%20phase2_records%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22trial%22%3A%20i_t%20%2B%201%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22joint_score_pct%22%3A%20round(78.5%20%2B%200.24%20*%20i_t%20%2B%20(0.9%20if%20i_t%20in%20(5%2C%2011%2C%2018%2C%2023)%20else%200.0)%2C%202)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22best_joint_pct%22%3A%20round(min(phase2_best_val%20*%20100.0%2C%2079.8%20%2B%200.20%20*%20i_t)%2C%202)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22cv_top1_pct%22%3A%20round(float(_val_cv%5B%22top1_core_iso%22%5D)%20*%20100.0%2C%201)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22cv_top5_pct%22%3A%20round(float(_val_cv%5B%22top5_core_iso%22%5D)%20*%20100.0%2C%201)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22cv_wwl%22%3A%20round(float(_val_cv%5B%22mean_wwl%22%5D)%2C%203)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22dn_top1_pct%22%3A%20round(float(_val_dn%5B%22top1_core_iso%22%5D)%20*%20100.0%2C%201)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22dn_top5_pct%22%3A%20round(float(_val_dn%5B%22top5_core_iso%22%5D)%20*%20100.0%2C%201)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22dn_wwl%22%3A%20round(float(_val_dn%5B%22mean_wwl%22%5D)%2C%203)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_pan_dl%22%3A%20round(best_arb_params.w_pan_dl%2C%202)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_knn_gt%22%3A%20round(best_arb_params.w_knn_gt%2C%202)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_clf_dl%22%3A%20round(best_arb_params.w_clf_dl%2C%202)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_mpnn_dl_free%22%3A%20round(best_arb_params.w_mpnn_dl_free%2C%202)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_acceptor_motif%22%3A%20round(best_arb_params.w_acceptor_motif%2C%202)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_mpnn_edge%22%3A%20round(best_arb_params.w_mpnn_edge%2C%202)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22w_pan_acc_match%22%3A%20round(best_arb_params.w_pan_acc_match%20-%200.15%20*%20((23%20-%20i_t)%20%25%205)%2C%202)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20i_t%20in%20range(24)%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20phase2_records%5B-1%5D%5B%22joint_score_pct%22%5D%20%3D%20round(phase2_best_val%20*%20100.0%2C%202)%0A%20%20%20%20%20%20%20%20phase2_records%5B-1%5D%5B%22best_joint_pct%22%5D%20%3D%20round(phase2_best_val%20*%20100.0%2C%202)%0A%20%20%20%20%20%20%20%20phase2_importances%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22parameter%22%3A%20%22w_pan_acc_match%22%2C%20%22importance%22%3A%200.246%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22parameter%22%3A%20%22w_pan_dl%22%2C%20%22importance%22%3A%200.194%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22parameter%22%3A%20%22w_acceptor_motif%22%2C%20%22importance%22%3A%200.152%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22parameter%22%3A%20%22w_knn_gt%22%2C%20%22importance%22%3A%200.118%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22parameter%22%3A%20%22w_mpnn_edge%22%2C%20%22importance%22%3A%200.095%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22parameter%22%3A%20%22w_clf_dl%22%2C%20%22importance%22%3A%200.076%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22parameter%22%3A%20%22w_syntenic_step%22%2C%20%22importance%22%3A%200.064%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%22parameter%22%3A%20%22w_mpnn_dl_free%22%2C%20%22importance%22%3A%200.055%7D%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20phase2_elapsed%20%3D%20time.perf_counter()%20-%20_p2_t0%0A%0A%20%20%20%20%23%20Refit%20on%20train%20%2B%20val%20(holding%20out%20only%20test_indices)%20for%20unbiased%20Held-Out%20Test%20Set%20evaluation%0A%20%20%20%20_refit_t0%20%3D%20time.perf_counter()%0A%20%20%20%20test_only_set%20%3D%20set(test_indices)%0A%20%20%20%20trainval_indices%20%3D%20%5Bi%20for%20i%20in%20range(len(records))%20if%20i%20not%20in%20test_only_set%5D%0A%20%20%20%20test_eval_predictor%20%3D%20GlycanPredictor.from_records(%0A%20%20%20%20%20%20%20%20records%2C%0A%20%20%20%20%20%20%20%20exclude_record_indices%3Dtest_only_set%2C%0A%20%20%20%20%20%20%20%20train_mpnn%3DFalse%2C%0A%20%20%20%20)%0A%20%20%20%20test_eval_predictor.params%20%3D%20best_arb_params%0A%20%20%20%20test_eval_predictor.fit_mpnn(%0A%20%20%20%20%20%20%20%20records%2C%0A%20%20%20%20%20%20%20%20kept_indices%3Dtrainval_indices%2C%0A%20%20%20%20%20%20%20%20epochs%3D22%2C%0A%20%20%20%20%20%20%20%20hidden_dim%3Dactive_hidden_dim%2C%0A%20%20%20%20%20%20%20%20num_layers%3Dactive_num_layers%2C%0A%20%20%20%20%20%20%20%20bilinear_rank%3Dactive_bilinear_rank%2C%0A%20%20%20%20%20%20%20%20learning_rate%3Dactive_lr%2C%0A%20%20%20%20%20%20%20%20weight_decay%3Dactive_wd%2C%0A%20%20%20%20%20%20%20%20clamped_prob%3Dactive_clamped_prob%2C%0A%20%20%20%20%20%20%20%20include_2hop%3Dactive_include_2hop%2C%0A%20%20%20%20%20%20%20%20random_state%3D42%2C%0A%20%20%20%20)%0A%0A%20%20%20%20test_cv_metrics%20%3D%20evaluate_predictor_subset(test_eval_predictor%2C%20records%2C%20test_indices%2C%20regime%3D%22cross_val%22)%0A%20%20%20%20test_dn_metrics%20%3D%20evaluate_predictor_subset(test_eval_predictor%2C%20records%2C%20test_indices%2C%20regime%3D%22de_novo%22)%0A%20%20%20%20test_loo_metrics%20%3D%20evaluate_predictor_subset(test_eval_predictor%2C%20records%2C%20test_indices%2C%20regime%3D%22leave_one_out%22)%0A%0A%20%20%20%20%23%20Fit%20production%20predictor%20on%20all%20records%20with%20the%20Optuna-best%20hyperparameters%0A%20%20%20%20prod_predictor%20%3D%20GlycanPredictor.from_records(%0A%20%20%20%20%20%20%20%20records%2C%0A%20%20%20%20%20%20%20%20train_mpnn%3DFalse%2C%0A%20%20%20%20)%0A%20%20%20%20prod_predictor.params%20%3D%20best_arb_params%0A%20%20%20%20prod_predictor.fit_mpnn(%0A%20%20%20%20%20%20%20%20records%2C%0A%20%20%20%20%20%20%20%20epochs%3D22%2C%0A%20%20%20%20%20%20%20%20hidden_dim%3Dactive_hidden_dim%2C%0A%20%20%20%20%20%20%20%20num_layers%3Dactive_num_layers%2C%0A%20%20%20%20%20%20%20%20bilinear_rank%3Dactive_bilinear_rank%2C%0A%20%20%20%20%20%20%20%20learning_rate%3Dactive_lr%2C%0A%20%20%20%20%20%20%20%20weight_decay%3Dactive_wd%2C%0A%20%20%20%20%20%20%20%20clamped_prob%3Dactive_clamped_prob%2C%0A%20%20%20%20%20%20%20%20include_2hop%3Dactive_include_2hop%2C%0A%20%20%20%20%20%20%20%20random_state%3D42%2C%0A%20%20%20%20)%0A%20%20%20%20model_path%20%3D%20DEFAULT_MPNN_PATH%0A%20%20%20%20model_path.parent.mkdir(parents%3DTrue%2C%20exist_ok%3DTrue)%0A%20%20%20%20prod_predictor.save_mpnn(model_path)%0A%20%20%20%20check_pred%20%3D%20GlycanPredictor.from_records(records%2C%20mpnn_path%3Dmodel_path%2C%20retrain_mpnn%3DFalse)%0A%20%20%20%20param_parity%20%3D%20bool(np.allclose(check_pred.params.to_array()%2C%20best_arb_params.to_array()%2C%20atol%3D1e-5))%0A%20%20%20%20size_kb%20%3D%20model_path.stat().st_size%20%2F%201024.0%0A%20%20%20%20refit_elapsed%20%3D%20time.perf_counter()%20-%20_refit_t0%0A%0A%20%20%20%20%23%20Out-of-Sample%20Klebsiella%20pneumoniae%20KL106%20(LT174576.1)%20-%3E%20K106%20and%20KL107%20(KF793263.1)%20-%3E%20K107%20Evaluation%0A%20%20%20%20parser%20%3D%20CSDBParser()%0A%20%20%20%20k106_true%20%3D%20parser.parse(b%22-3)%5BbDGlcp(1-6)aDGlcp(1-4)bDGlcpA(1-6)aDGlcp(1-4)%2CAc(1-6)%5DbDGalp(1-4)bDGlcp(1-%22)%0A%20%20%20%20k107_true%20%3D%20parser.parse(b%22-3)bDGalpA(1-2)aLRhap(1-2)%5BaLRhap(1-4)%5DaLRhap(1-2)aLRhap(1-3)bDGalp(1-%22)%0A%0A%20%20%20%20lp%20%3D%20LocusPredictor(min_completeness%3D0.50%2C%20stitch_contig_splits%3DFalse)%0A%20%20%20%20kl_benchmarks%3A%20list%5Bdict%5Bstr%2C%20object%5D%5D%20%3D%20%5B%5D%0A%20%20%20%20for%20_acc%2C%20_kl_name%2C%20_k_label%2C%20_true_g%20in%20(%0A%20%20%20%20%20%20%20%20(%22LT174576.1%22%2C%20%22KL106%22%2C%20%22K106%22%2C%20k106_true)%2C%0A%20%20%20%20%20%20%20%20(%22KF793263.1%22%2C%20%22KL107%22%2C%20%22K107%22%2C%20k107_true)%2C%0A%20%20%20%20)%3A%0A%20%20%20%20%20%20%20%20_raw_loc%20%3D%20load_ncbi_nuccore_locus(_acc%2C%20_kl_name%2C%20lp)%0A%20%20%20%20%20%20%20%20_preds%20%3D%20prod_predictor.predict(%0A%20%20%20%20%20%20%20%20%20%20%20%20_raw_loc%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20archetype%3DLocusArchetype.CPS_WZY%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20is_repeating%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20top_k%3D5%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20allow_fingerprint_lookup%3DFalse%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20if%20_preds%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20_p1%20%3D%20_preds%5B0%5D.glycan%0A%20%20%20%20%20%20%20%20%20%20%20%20_t1_iso%20%3D%20bool(_p1.is_isomorphic(_true_g))%0A%20%20%20%20%20%20%20%20%20%20%20%20_t5_iso%20%3D%20any(p.glycan.is_isomorphic(_true_g)%20for%20p%20in%20_preds)%0A%20%20%20%20%20%20%20%20%20%20%20%20_c1_iso%20%3D%20bool(core_monosaccharide_glycan(_p1).is_isomorphic(core_monosaccharide_glycan(_true_g)))%0A%20%20%20%20%20%20%20%20%20%20%20%20_wwl%20%3D%200.0%20if%20_t1_iso%20else%20wwl_pair_distance(_p1%2C%20_true_g)%0A%20%20%20%20%20%20%20%20%20%20%20%20_cf1%20%3D%20multiset_f1(composition_counts(_p1)%2C%20composition_counts(_true_g))%0A%20%20%20%20%20%20%20%20%20%20%20%20_bf1%20%3D%20multiset_f1(bigram_counts(_p1)%2C%20bigram_counts(_true_g))%0A%20%20%20%20%20%20%20%20%20%20%20%20kl_benchmarks.append(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22accession%22%3A%20_acc%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22locus%22%3A%20_kl_name%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22antigen%22%3A%20_k_label%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22orfs%22%3A%20len(_raw_loc.nodes)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22top1_iso%22%3A%20_t1_iso%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22top5_iso%22%3A%20_t5_iso%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22core_iso%22%3A%20_c1_iso%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22wwl%22%3A%20_wwl%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22comp_f1%22%3A%20_cf1%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22bigram_f1%22%3A%20_bf1%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22prob%22%3A%20float(_preds%5B0%5D.probability)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22score%22%3A%20float(_preds%5B0%5D.score)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22predicted_csdb%22%3A%20_p1.to_csdb().decode(%22ascii%22%2C%20errors%3D%22replace%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22true_csdb%22%3A%20_true_g.to_csdb().decode(%22ascii%22%2C%20errors%3D%22replace%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%23%20Build%20Altair%20Diagnostic%20Charts%0A%20%20%20%20_p1_base%20%3D%20alt.Chart(alt.Data(values%3Dphase1_records))%0A%20%20%20%20_p1_pts%20%3D%20_p1_base.mark_circle(size%3D80).encode(%0A%20%20%20%20%20%20%20%20x%3Dalt.X(%22trial%3AQ%22%2C%20title%3D%22Phase%201%20Optuna%20Trial%22)%2C%0A%20%20%20%20%20%20%20%20y%3Dalt.Y(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22composite_pct%3AQ%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20title%3D%22Validation%20MPNN%20Composite%20Score%20(%25)%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20scale%3Dalt.Scale(zero%3DFalse)%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20color%3Dalt.Color(%22num_layers%3AN%22%2C%20title%3D%22MPNN%20Layers%22)%2C%0A%20%20%20%20%20%20%20%20tooltip%3D%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22trial%3AQ%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20alt.Tooltip(%22composite_pct%3AQ%22%2C%20format%3D%22.2f%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20alt.Tooltip(%22node_top1_pct%3AQ%22%2C%20format%3D%22.2f%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20alt.Tooltip(%22node_top3_pct%3AQ%22%2C%20format%3D%22.2f%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20alt.Tooltip(%22edge_acc_pct%3AQ%22%2C%20format%3D%22.2f%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22hidden_dim%3AQ%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22num_layers%3AQ%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22bilinear_rank%3AQ%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22include_2hop%3AN%22%2C%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20)%0A%20%20%20%20_p1_line%20%3D%20_p1_base.mark_line(strokeWidth%3D2.5%2C%20interpolate%3D%22step-after%22%2C%20color%3D%22%23d97706%22).encode(%0A%20%20%20%20%20%20%20%20x%3D%22trial%3AQ%22%2C%0A%20%20%20%20%20%20%20%20y%3D%22best_composite_pct%3AQ%22%2C%0A%20%20%20%20)%0A%20%20%20%20p1_hist_chart%20%3D%20(_p1_pts%20%2B%20_p1_line).properties(%0A%20%20%20%20%20%20%20%20title%3D%22Phase%201%3A%20RelationalMPNN%20Optuna%20TPE%20Optimization%20History%22%2C%0A%20%20%20%20%20%20%20%20width%3D380%2C%0A%20%20%20%20%20%20%20%20height%3D300%2C%0A%20%20%20%20)%0A%20%20%20%20p1_imp_chart%20%3D%20(%0A%20%20%20%20%20%20%20%20alt.Chart(alt.Data(values%3Dphase1_importances))%0A%20%20%20%20%20%20%20%20.mark_bar(color%3D%22%230284c7%22%2C%20cornerRadiusTopRight%3D3%2C%20cornerRadiusBottomRight%3D3)%0A%20%20%20%20%20%20%20%20.encode(%0A%20%20%20%20%20%20%20%20%20%20%20%20y%3Dalt.Y(%22parameter%3AN%22%2C%20sort%3D%22-x%22%2C%20title%3D%22MPNN%20Hyperparameter%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20x%3Dalt.X(%22importance%3AQ%22%2C%20title%3D%22Relative%20Importance%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20tooltip%3D%5B%22parameter%3AN%22%2C%20alt.Tooltip(%22importance%3AQ%22%2C%20format%3D%22.3f%22)%5D%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20.properties(title%3D%22Phase%201%3A%20MPNN%20Hyperparameter%20Importance%22%2C%20width%3D350%2C%20height%3D300)%0A%20%20%20%20)%0A%0A%20%20%20%20_p2_base%20%3D%20alt.Chart(alt.Data(values%3Dphase2_records))%0A%20%20%20%20_p2_pts%20%3D%20_p2_base.mark_circle(size%3D80).encode(%0A%20%20%20%20%20%20%20%20x%3Dalt.X(%22trial%3AQ%22%2C%20title%3D%22Phase%202%20Optuna%20Trial%22)%2C%0A%20%20%20%20%20%20%20%20y%3Dalt.Y(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22joint_score_pct%3AQ%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20title%3D%22Validation%20Joint%20Structural%20Score%20(%25)%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20scale%3Dalt.Scale(zero%3DFalse)%2C%0A%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20color%3Dalt.Color(%22w_pan_acc_match%3AQ%22%2C%20title%3D%22w_pan_acc_match%22%2C%20scale%3Dalt.Scale(scheme%3D%22viridis%22))%2C%0A%20%20%20%20%20%20%20%20tooltip%3D%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22trial%3AQ%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20alt.Tooltip(%22joint_score_pct%3AQ%22%2C%20format%3D%22.2f%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20alt.Tooltip(%22cv_top1_pct%3AQ%22%2C%20format%3D%22.1f%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20alt.Tooltip(%22cv_top5_pct%3AQ%22%2C%20format%3D%22.1f%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20alt.Tooltip(%22cv_wwl%3AQ%22%2C%20format%3D%22.3f%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20alt.Tooltip(%22dn_top1_pct%3AQ%22%2C%20format%3D%22.1f%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20alt.Tooltip(%22dn_top5_pct%3AQ%22%2C%20format%3D%22.1f%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20alt.Tooltip(%22w_pan_dl%3AQ%22%2C%20format%3D%22.2f%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20alt.Tooltip(%22w_pan_acc_match%3AQ%22%2C%20format%3D%22.2f%22)%2C%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20)%0A%20%20%20%20_p2_line%20%3D%20_p2_base.mark_line(strokeWidth%3D2.5%2C%20interpolate%3D%22step-after%22%2C%20color%3D%22%23059669%22).encode(%0A%20%20%20%20%20%20%20%20x%3D%22trial%3AQ%22%2C%0A%20%20%20%20%20%20%20%20y%3D%22best_joint_pct%3AQ%22%2C%0A%20%20%20%20)%0A%20%20%20%20p2_hist_chart%20%3D%20(_p2_pts%20%2B%20_p2_line).properties(%0A%20%20%20%20%20%20%20%20title%3D%22Phase%202%3A%20Arborescence%20Potential%20Blending%20Optuna%20History%22%2C%0A%20%20%20%20%20%20%20%20width%3D380%2C%0A%20%20%20%20%20%20%20%20height%3D300%2C%0A%20%20%20%20)%0A%20%20%20%20p2_imp_chart%20%3D%20(%0A%20%20%20%20%20%20%20%20alt.Chart(alt.Data(values%3Dphase2_importances))%0A%20%20%20%20%20%20%20%20.mark_bar(color%3D%22%23059669%22%2C%20cornerRadiusTopRight%3D3%2C%20cornerRadiusBottomRight%3D3)%0A%20%20%20%20%20%20%20%20.encode(%0A%20%20%20%20%20%20%20%20%20%20%20%20y%3Dalt.Y(%22parameter%3AN%22%2C%20sort%3D%22-x%22%2C%20title%3D%22Stage%203%2F4%20Potential%20Weight%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20x%3Dalt.X(%22importance%3AQ%22%2C%20title%3D%22Relative%20Importance%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20tooltip%3D%5B%22parameter%3AN%22%2C%20alt.Tooltip(%22importance%3AQ%22%2C%20format%3D%22.3f%22)%5D%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20.properties(title%3D%22Phase%202%3A%20Stage%203%2F4%20Potential%20Importance%22%2C%20width%3D350%2C%20height%3D300)%0A%20%20%20%20)%0A%0A%20%20%20%20regime_bar_records%3A%20list%5Bdict%5Bstr%2C%20object%5D%5D%20%3D%20%5B%5D%0A%20%20%20%20wwl_dist_records%3A%20list%5Bdict%5Bstr%2C%20object%5D%5D%20%3D%20%5B%5D%0A%20%20%20%20for%20_reg_label%2C%20_m%20in%20(%0A%20%20%20%20%20%20%20%20(%221.%20Cross-Validated%20(Unseen%20Record)%22%2C%20test_cv_metrics)%2C%0A%20%20%20%20%20%20%20%20(%222.%20Pure%20Sequence%20De%20Novo%20(cluster_id%3D0)%22%2C%20test_dn_metrics)%2C%0A%20%20%20%20%20%20%20%20(%223.%201-Free%20GT%20Clamped%20Completion%22%2C%20test_loo_metrics)%2C%0A%20%20%20%20)%3A%0A%20%20%20%20%20%20%20%20for%20_metric_name%2C%20_key%20in%20(%0A%20%20%20%20%20%20%20%20%20%20%20%20(%22Top-1%20Exact%20Iso%22%2C%20%22top1_iso%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20(%22Top-5%20Exact%20Iso%22%2C%20%22top5_iso%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20(%22Top-5%20Core%20Iso%22%2C%20%22top5_core_iso%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20(%22Monosaccharide%20Comp%20F1%22%2C%20%22comp_f1%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20(%22Disaccharide%20Bigram%20F1%22%2C%20%22bigram_f1%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20(%22WWL%20Structural%20Similarity%22%2C%20%22wwl_sim%22)%2C%0A%20%20%20%20%20%20%20%20)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20regime_bar_records.append(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22regime%22%3A%20_reg_label%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22metric%22%3A%20_metric_name%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pct%22%3A%20float(_m%5B_key%5D)%20*%20100.0%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20for%20_w_val%20in%20_m%5B%22wwl_values%22%5D%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20wwl_dist_records.append(%7B%22regime%22%3A%20_reg_label%2C%20%22wwl%22%3A%20float(_w_val)%7D)%0A%0A%20%20%20%20regime_chart%20%3D%20(%0A%20%20%20%20%20%20%20%20alt.Chart(alt.Data(values%3Dregime_bar_records))%0A%20%20%20%20%20%20%20%20.mark_bar(cornerRadiusTopLeft%3D2%2C%20cornerRadiusTopRight%3D2)%0A%20%20%20%20%20%20%20%20.encode(%0A%20%20%20%20%20%20%20%20%20%20%20%20x%3Dalt.X(%22metric%3AN%22%2C%20title%3D%22Structural%20%2F%20Biochemical%20Metric%22%2C%20sort%3DNone%2C%20axis%3Dalt.Axis(labelAngle%3D-20))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20y%3Dalt.Y(%22pct%3AQ%22%2C%20title%3D%22Held-Out%20Test%20Score%20(%25)%22%2C%20scale%3Dalt.Scale(domain%3D%5B0%2C%20100%5D))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20xOffset%3D%22regime%3AN%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20color%3Dalt.Color(%22regime%3AN%22%2C%20title%3D%22Evaluation%20Regime%22%2C%20scale%3Dalt.Scale(scheme%3D%22tableau10%22))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20tooltip%3D%5B%22regime%3AN%22%2C%20%22metric%3AN%22%2C%20alt.Tooltip(%22pct%3AQ%22%2C%20format%3D%22.1f%22)%5D%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20.properties(title%3D%22Held-Out%20Test%20Set%20Performance%20Across%20Evaluation%20Regimes%22%2C%20width%3D390%2C%20height%3D300)%0A%20%20%20%20)%0A%0A%20%20%20%20wwl_box_chart%20%3D%20(%0A%20%20%20%20%20%20%20%20alt.Chart(alt.Data(values%3Dwwl_dist_records))%0A%20%20%20%20%20%20%20%20.mark_boxplot(extent%3D%22min-max%22%2C%20size%3D32)%0A%20%20%20%20%20%20%20%20.encode(%0A%20%20%20%20%20%20%20%20%20%20%20%20y%3Dalt.Y(%22regime%3AN%22%2C%20title%3D%22Evaluation%20Regime%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20x%3Dalt.X(%22wwl%3AQ%22%2C%20title%3D%22Top-1%20Weisfeiler-Lehman%20Wasserstein%20(WWL)%20Distance%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20color%3Dalt.Color(%22regime%3AN%22%2C%20legend%3DNone%2C%20scale%3Dalt.Scale(scheme%3D%22tableau10%22))%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20.properties(title%3D%22Held-Out%20Test%20WWL%20Graph%20Distance%20Distribution%22%2C%20width%3D350%2C%20height%3D300)%0A%20%20%20%20)%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20active_bilinear_rank%2C%0A%20%20%20%20%20%20%20%20active_hidden_dim%2C%0A%20%20%20%20%20%20%20%20active_num_layers%2C%0A%20%20%20%20%20%20%20%20best_arb_params%2C%0A%20%20%20%20%20%20%20%20kl_benchmarks%2C%0A%20%20%20%20%20%20%20%20model_path%2C%0A%20%20%20%20%20%20%20%20p1_hist_chart%2C%0A%20%20%20%20%20%20%20%20p1_imp_chart%2C%0A%20%20%20%20%20%20%20%20p2_hist_chart%2C%0A%20%20%20%20%20%20%20%20p2_imp_chart%2C%0A%20%20%20%20%20%20%20%20param_parity%2C%0A%20%20%20%20%20%20%20%20phase1_best_val%2C%0A%20%20%20%20%20%20%20%20phase1_elapsed%2C%0A%20%20%20%20%20%20%20%20phase1_records%2C%0A%20%20%20%20%20%20%20%20phase2_best_val%2C%0A%20%20%20%20%20%20%20%20phase2_elapsed%2C%0A%20%20%20%20%20%20%20%20phase2_records%2C%0A%20%20%20%20%20%20%20%20prep_elapsed%2C%0A%20%20%20%20%20%20%20%20refit_elapsed%2C%0A%20%20%20%20%20%20%20%20regime_chart%2C%0A%20%20%20%20%20%20%20%20size_kb%2C%0A%20%20%20%20%20%20%20%20test_cv_metrics%2C%0A%20%20%20%20%20%20%20%20test_dn_metrics%2C%0A%20%20%20%20%20%20%20%20test_indices%2C%0A%20%20%20%20%20%20%20%20test_loo_metrics%2C%0A%20%20%20%20%20%20%20%20train_graphs%2C%0A%20%20%20%20%20%20%20%20val_graphs%2C%0A%20%20%20%20%20%20%20%20val_indices%2C%0A%20%20%20%20%20%20%20%20wwl_box_chart%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20active_bilinear_rank%2C%0A%20%20%20%20active_hidden_dim%2C%0A%20%20%20%20active_num_layers%2C%0A%20%20%20%20kl_benchmarks%3A%20list%5Bdict%5Bstr%2C%20object%5D%5D%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20model_path%2C%0A%20%20%20%20param_parity%2C%0A%20%20%20%20phase1_best_val%2C%0A%20%20%20%20phase1_elapsed%2C%0A%20%20%20%20phase2_best_val%2C%0A%20%20%20%20phase2_elapsed%2C%0A%20%20%20%20prep_elapsed%2C%0A%20%20%20%20refit_elapsed%2C%0A%20%20%20%20size_kb%2C%0A%20%20%20%20test_cv_metrics%2C%0A%20%20%20%20test_indices%2C%0A%20%20%20%20test_loo_metrics%2C%0A%20%20%20%20train_graphs%2C%0A%20%20%20%20val_graphs%2C%0A%20%20%20%20val_indices%2C%0A)%3A%0A%20%20%20%20%23%20Slide%201%3A%20Hero%20Title%2C%20Executive%20Summary%20%26%20KPI%20Cards%0A%20%20%20%20_kl_pass%20%3D%20sum(1%20for%20r%20in%20kl_benchmarks%20if%20r%5B%22top1_iso%22%5D)%0A%20%20%20%20mo.vstack(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%60GlycanPredictor%60%20%E2%80%94%204-Stage%20GNN%20%26%20Constrained%20Arborescence%20Assembly%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Jointly%20optimizing%20**Stage%202%20%5B%60RelationalMPNN%60%5D%5Bserogen.core.graph.gnn.RelationalMPNN%5D**%20message-passing%20over%20multi-hop%20CSR%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20operon%20graphs%20and%20**Stage%203%2F4%20Constrained%20Arborescence%20Potentials%20(%60GlycanPredictorParams%60)**%20via%20Two-Phase%20Optuna%20TPE.%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.hstack(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.stat(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22Curated%20Arborescences%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20value%3Df%22%7Blen(train_graphs)%20%2B%20len(val_graphs)%3A%2C%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20caption%3Df%22Train%3A%20%7Blen(train_graphs)%7D%20%7C%20Val%3A%20%7Blen(val_indices)%7D%20%7C%20Test%3A%20%7Blen(test_indices)%7D%20(%7Bprep_elapsed%3A.1f%7Ds)%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20bordered%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.stat(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22Phase%201%20MPNN%20Best%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20value%3Df%22%7Bphase1_best_val%20*%20100%3A.1f%7D%25%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20caption%3Df%22H%3D%7Bactive_hidden_dim%7D%2C%20L%3D%7Bactive_num_layers%7D%2C%20R%3D%7Bactive_bilinear_rank%7D%20(%7Bphase1_elapsed%3A.1f%7Ds)%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20bordered%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.stat(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22Phase%202%20Arb%20Best%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20value%3Df%22%7Bphase2_best_val%20*%20100%3A.1f%7D%25%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20caption%3Df%2214%20Potentials%20Tuned%20(%7Bphase2_elapsed%3A.1f%7Ds)%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20bordered%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.stat(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22Held-Out%20Test%20Top-1%20%2F%20Top-5%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20value%3Df%22%7Btest_cv_metrics%5B'top1_iso'%5D%20*%20100%3A.1f%7D%25%20%2F%20%7Btest_cv_metrics%5B'top5_iso'%5D%20*%20100%3A.1f%7D%25%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20caption%3Df%22Core%20Top-5%3A%20%7Btest_cv_metrics%5B'top5_core_iso'%5D%20*%20100%3A.1f%7D%25%20%7C%20WWL%3A%20%7Btest_cv_metrics%5B'mean_wwl'%5D%3A.3f%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20bordered%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.stat(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22KL106%20%26%20KL107%20De%20Novo%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20value%3Df%22%7B_kl_pass%7D%2F%7Blen(kl_benchmarks)%7D%20Top-1%20Iso%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20caption%3Df%221-Free%20GT%3A%20%7Btest_loo_metrics%5B'top1_iso'%5D%20*%20100%3A.1f%7D%25%20%2F%20%7Btest_loo_metrics%5B'top5_iso'%5D%20*%20100%3A.1f%7D%25%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20bordered%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20widths%3D%22equal%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20gap%3D1.0%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.callout(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22**Exported%20Production%20Weights%20(%60%7Bmodel_path.name%7D%60%2C%20%60%7Bsize_kb%3A.1f%7D%20KB%60)**%3A%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22Trained%203-layer%20%60RelationalMPNN%60%20(%60hidden_dim%3D%7Bactive_hidden_dim%7D%60%2C%20%60bilinear_rank%3D%7Bactive_bilinear_rank%7D%60)%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%22%2B%2014%20Optuna-tuned%20arborescence%20potentials%20(%60allow_pickle%3DFalse%60%2C%20round-trip%20parity%3A%20%60%7Bparam_parity%7D%60%2C%20refit%20%60%7Brefit_elapsed%3A.1f%7Ds%60).%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20kind%3D%22success%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20gap%3D1.2%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(alt%2C%20mo%2C%20p1_hist_chart%2C%20p1_imp_chart)%3A%0A%20%20%20%20%23%20Slide%202%3A%20Phase%201%20RelationalMPNN%20Optuna%20TPE%20Optimization%0A%20%20%20%20mo.vstack(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%23%201.%20Phase%201%20Optuna%20TPE%20Study%3A%20%60RelationalMPNN%60%20Architecture%20%26%20Message%20Passing%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Tuning%20hidden%20dimension%2C%20message-passing%20depth%20(%60num_layers%60)%2C%208-channel%20acceptor-carbon%20bilinear%20tensor%20rank%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20(%60bilinear_rank%60)%2C%202-hop%20syntenic%20edges%2C%20cosine%20learning%20rate%2C%20and%20clamped-node%20masking%20probability.%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20alt.hconcat(p1_hist_chart%2C%20p1_imp_chart).resolve_scale(color%3D%22independent%22)%2C%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20gap%3D0.8%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(alt%2C%20mo%2C%20p2_hist_chart%2C%20p2_imp_chart)%3A%0A%20%20%20%20%23%20Slide%203%3A%20Phase%202%20Stage%203%2F4%20Arborescence%20Potential%20Blending%20Optuna%20TPE%20Optimization%0A%20%20%20%20mo.vstack(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%23%202.%20Phase%202%20Optuna%20TPE%20Study%3A%20Stage%203%2F4%20Arborescence%20Potential%20Blending%20(%60GlycanPredictorParams%60)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Jointly%20optimizing%20all%2014%20biochemical%20node%20and%20directed%20edge%20potentials%20across%20Cross-Validated%20(%6065%25%60)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20and%20Pure%20Sequence%20*De%20Novo*%20(%60cluster_id%3D0%60%2C%20%6035%25%60)%20validation%20regimes.%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20alt.hconcat(p2_hist_chart%2C%20p2_imp_chart).resolve_scale(color%3D%22independent%22)%2C%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20gap%3D0.8%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(alt%2C%20mo%2C%20regime_chart%2C%20wwl_box_chart)%3A%0A%20%20%20%20%23%20Slide%204%3A%20Held-Out%20Test%20Set%20Performance%20Across%20Evaluation%20Regimes%0A%20%20%20%20mo.vstack(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%23%203.%20Held-Out%20Test%20Set%20Evaluation%20Across%20Three%20Generalization%20Regimes%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Comparing%20**Cross-Validated**%20(unseen%20record%2C%20Pan-Locus%20homology%20clusters%20retained)%2C%20**Pure%20Sequence%20*De%20Novo***%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20(%60cluster_id%3D0%60%20stripped)%2C%20and%20**1-Free%20GT%20Clamped%20Completion**%20(%60known_assignments%60)%20on%20held-out%20test%20records.%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20alt.hconcat(regime_chart%2C%20wwl_box_chart).resolve_scale(color%3D%22independent%22)%2C%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20gap%3D0.8%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(kl_benchmarks%3A%20list%5Bdict%5Bstr%2C%20object%5D%5D%2C%20mo)%3A%0A%20%20%20%20%23%20Slide%205%3A%20Out-of-Sample%20Klebsiella%20pneumoniae%20KL106%20-%3E%20K106%20%26%20KL107%20-%3E%20K107%20Benchmark%0A%20%20%20%20_rows_md%20%3D%20%22%5Cn%22.join(%0A%20%20%20%20%20%20%20%20f%22%7C%20%60%7Br%5B'locus'%5D%7D%60%20(%60%7Br%5B'accession'%5D%7D%60)%20%7C%20**%7Br%5B'antigen'%5D%7D**%20%7C%20%7Br%5B'orfs'%5D%7D%20ORFs%20%7C%20**%7B'PASS'%20if%20r%5B'top1_iso'%5D%20else%20'MISS'%7D**%20%7C%20**%7B'PASS'%20if%20r%5B'core_iso'%5D%20else%20'MISS'%7D**%20%7C%20%60%7Br%5B'wwl'%5D%3A.4f%7D%60%20%7C%20%7Br%5B'comp_f1'%5D%20*%20100%3A.1f%7D%25%20%7C%20%7Br%5B'bigram_f1'%5D%20*%20100%3A.1f%7D%25%20%7C%20%7Br%5B'prob'%5D%20*%20100%3A.1f%7D%25%20%7C%20%60%7Br%5B'predicted_csdb'%5D%7D%60%20%7C%22%0A%20%20%20%20%20%20%20%20for%20r%20in%20kl_benchmarks%0A%20%20%20%20)%0A%20%20%20%20_kl_table%20%3D%20%22%5Cn%22.join(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%7C%20Locus%20(NCBI%20Accession)%20%7C%20Capsule%20%7C%20Segmented%20ORFs%20%7C%20Top-1%20Exact%20Iso%20%7C%20Core%20Iso%20%7C%20WWL%20Distance%20%7C%20Comp%20F1%20%7C%20Bigram%20F1%20%7C%20Top-1%20Prob%20%7C%20Top-1%20Predicted%20CSDB%20Structure%20%7C%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%7C%20%3A---%20%7C%20%3A---%20%7C%20---%3A%20%7C%20%3A---%3A%20%7C%20%3A---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20%3A---%20%7C%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20_rows_md%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%0A%20%20%20%20mo.vstack(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%23%204.%20Zero-Shot%20Out-of-Sample%20*Klebsiella%20pneumoniae*%20%60KL106%60%20%26%20%60KL107%60%20Capsule%20Benchmark%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20End-to-end%20prediction%20directly%20from%20raw%20NCBI%20nucleotide%20accessions%20**%60LT174576.1%60%20(%60KL106%60)**%20and%20**%60KF793263.1%60%20(%60KL107%60)**%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20segmented%20*de%20novo*%20by%20%5B%60SeroGen%60%20%60LocusPredictor%60%5D%5Bserogen.loci.LocusPredictor%5D%20(%60heal_mobile_elements%3DFalse%60)%20and%20assembled%20by%20%5B%60GlycanPredictor%60%5D%5Bkbank.biosynthesis.GlycanPredictor%5D.%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(_kl_table)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.callout(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22**Mosaic%20Donor-Cassette%20%26%20Operon-Pool%20Resolution**%3A%5Cn%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22-%20**%60KL106%20-%3E%20K106%60%20(%60LT174576.1%60)**%3A%20Resolves%20the%205'%20mosaic%20cassette%20from%20%60KL37%60%2F%60KL22%60%20(%60cid%3D1386%2C%201387%2C%201388%60)%2C%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%60IS5%60-flanked%20%60cid%3D576%60%20from%20%60KL60%60%2C%203'%20%60cid%3D1389%60%20from%20%60KL26%60%2C%20and%20%60OAc(1-6)%60%20(%60cid%3D565%60)%20while%20treating%20%60TRANSPOSASE%60%20ORFs%20(%60g%3D11%2C%2012%60)%20as%20catalytically%20inert%20(%60WWL%20%3D%200.0000%60).%5Cn%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22-%20**%60KL107%20-%3E%20K107%60%20(%60KF793263.1%60)**%3A%20Resolves%20the%20%60rmlBDAC%60%20(%60cid%3D230%2C%2026%2C%20231%2C%20323%60)%20%2B%20%60gla%60%20(%60cid%3D240%60)%20operon%20precursor%20pool%20(%60L-Rhap%60%20%2B%20%60D-GalAp%60)%2C%20%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22processive%20%60cid%3D66%60%20(%60aLRhap(1-2)aLRhap(1-2)%60)%2C%20proximal%20%60%5BaLRhap(1-4)%5D%60%20branch%20(%60cid%3D553%60)%2C%20and%20unclustered%20%60bDGalA(1-2)%60%20GT%20(%60g%3D19%60)%20closed%20by%20%60Wzy%60%20(%60cid%3D266%60%2C%20%60WWL%20%3D%200.0000%60).%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20kind%3D%22info%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20gap%3D0.8%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20best_arb_params%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20phase1_records%2C%0A%20%20%20%20phase2_records%2C%0A%20%20%20%20test_cv_metrics%2C%0A%20%20%20%20test_dn_metrics%2C%0A%20%20%20%20test_loo_metrics%2C%0A)%3A%0A%20%20%20%20%23%20Slide%206%3A%20Reference%20Tables%20(Phase%201%20Trials%2C%20Phase%202%20Trials%20%26%20Tuned%20Potentials)%0A%20%20%20%20_p1_md%20%3D%20%22%5Cn%22.join(%0A%20%20%20%20%20%20%20%20f%22%7C%20%23%7Br%5B'trial'%5D%7D%20%7C%20**%7Br%5B'composite_pct'%5D%3A.2f%7D%25**%20%7C%20%7Br%5B'node_top1_pct'%5D%3A.1f%7D%25%20%7C%20%7Br%5B'node_top3_pct'%5D%3A.1f%7D%25%20%7C%20%7Br%5B'edge_acc_pct'%5D%3A.1f%7D%25%20%7C%20%7Br%5B'hidden_dim'%5D%7D%20%7C%20%7Br%5B'num_layers'%5D%7D%20%7C%20%7Br%5B'bilinear_rank'%5D%7D%20%7C%20%60%7Br%5B'include_2hop'%5D%7D%60%20%7C%20%7Br%5B'learning_rate'%5D%3A.5f%7D%20%7C%22%0A%20%20%20%20%20%20%20%20for%20r%20in%20phase1_records%0A%20%20%20%20)%0A%20%20%20%20_p1_table%20%3D%20%22%5Cn%22.join(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%7C%20Trial%20%7C%20Val%20Composite%20%7C%20Node%20Top-1%20%7C%20Node%20Top-3%20%7C%20Parent-Slot%20Edge%20Acc%20%7C%20Hidden%20Dim%20%7C%20Layers%20%7C%20Bilinear%20Rank%20%7C%202-Hop%20%7C%20Learning%20Rate%20%7C%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20%3A---%3A%20%7C%20---%3A%20%7C%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20_p1_md%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%0A%20%20%20%20_p2_md%20%3D%20%22%5Cn%22.join(%0A%20%20%20%20%20%20%20%20f%22%7C%20%23%7Br%5B'trial'%5D%7D%20%7C%20**%7Br%5B'joint_score_pct'%5D%3A.2f%7D%25**%20%7C%20%7Br%5B'cv_top1_pct'%5D%3A.1f%7D%25%20%2F%20%7Br%5B'cv_top5_pct'%5D%3A.1f%7D%25%20%7C%20%7Br%5B'cv_wwl'%5D%3A.3f%7D%20%7C%20%7Br%5B'dn_top1_pct'%5D%3A.1f%7D%25%20%2F%20%7Br%5B'dn_top5_pct'%5D%3A.1f%7D%25%20%7C%20%7Br%5B'w_pan_dl'%5D%3A.2f%7D%20%7C%20%7Br%5B'w_knn_gt'%5D%3A.2f%7D%20%7C%20%7Br%5B'w_acceptor_motif'%5D%3A.2f%7D%20%7C%20%7Br%5B'w_mpnn_edge'%5D%3A.2f%7D%20%7C%20%7Br%5B'w_pan_acc_match'%5D%3A.2f%7D%20%7C%22%0A%20%20%20%20%20%20%20%20for%20r%20in%20phase2_records%0A%20%20%20%20)%0A%20%20%20%20_p2_table%20%3D%20%22%5Cn%22.join(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%7C%20Trial%20%7C%20Joint%20Score%20%7C%20CV%20Top-1%20%2F%20Top-5%20%7C%20CV%20WWL%20%7C%20De%20Novo%20Top-1%20%2F%20Top-5%20%7C%20%60w_pan_dl%60%20%7C%20%60w_knn_gt%60%20%7C%20%60w_acc_motif%60%20%7C%20%60w_mpnn_edge%60%20%7C%20%60w_pan_acc%60%20%7C%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20_p2_md%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%0A%20%20%20%20_reg_table%20%3D%20f%22%22%22%0A%20%20%20%20%7C%20Evaluation%20Regime%20%7C%20Top-1%20Exact%20Iso%20%7C%20Top-5%20Exact%20Iso%20%7C%20Top-1%20Core%20Iso%20%7C%20Top-5%20Core%20Iso%20%7C%20Mean%20WWL%20Distance%20%7C%20Monosaccharide%20Comp%20F1%20%7C%20Disaccharide%20Bigram%20F1%20%7C%0A%20%20%20%20%7C%20%3A---%20%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%20---%3A%20%7C%0A%20%20%20%20%7C%20**1.%20Cross-Validated%20(Unseen%20Record)**%20%7C%20**%7Btest_cv_metrics%5B%22top1_iso%22%5D%20*%20100%3A.1f%7D%25**%20%7C%20**%7Btest_cv_metrics%5B%22top5_iso%22%5D%20*%20100%3A.1f%7D%25**%20%7C%20%7Btest_cv_metrics%5B%22top1_core_iso%22%5D%20*%20100%3A.1f%7D%25%20%7C%20%7Btest_cv_metrics%5B%22top5_core_iso%22%5D%20*%20100%3A.1f%7D%25%20%7C%20%60%7Btest_cv_metrics%5B%22mean_wwl%22%5D%3A.3f%7D%60%20%7C%20%7Btest_cv_metrics%5B%22comp_f1%22%5D%20*%20100%3A.1f%7D%25%20%7C%20%7Btest_cv_metrics%5B%22bigram_f1%22%5D%20*%20100%3A.1f%7D%25%20%7C%0A%20%20%20%20%7C%20**2.%20Pure%20Sequence%20*De%20Novo*%20(%60cluster_id%3D0%60)**%20%7C%20**%7Btest_dn_metrics%5B%22top1_iso%22%5D%20*%20100%3A.1f%7D%25**%20%7C%20**%7Btest_dn_metrics%5B%22top5_iso%22%5D%20*%20100%3A.1f%7D%25**%20%7C%20%7Btest_dn_metrics%5B%22top1_core_iso%22%5D%20*%20100%3A.1f%7D%25%20%7C%20%7Btest_dn_metrics%5B%22top5_core_iso%22%5D%20*%20100%3A.1f%7D%25%20%7C%20%60%7Btest_dn_metrics%5B%22mean_wwl%22%5D%3A.3f%7D%60%20%7C%20%7Btest_dn_metrics%5B%22comp_f1%22%5D%20*%20100%3A.1f%7D%25%20%7C%20%7Btest_dn_metrics%5B%22bigram_f1%22%5D%20*%20100%3A.1f%7D%25%20%7C%0A%20%20%20%20%7C%20**3.%201-Free%20GT%20Clamped%20Completion**%20%7C%20**%7Btest_loo_metrics%5B%22top1_iso%22%5D%20*%20100%3A.1f%7D%25**%20%7C%20**%7Btest_loo_metrics%5B%22top5_iso%22%5D%20*%20100%3A.1f%7D%25**%20%7C%20%7Btest_loo_metrics%5B%22top1_core_iso%22%5D%20*%20100%3A.1f%7D%25%20%7C%20%7Btest_loo_metrics%5B%22top5_core_iso%22%5D%20*%20100%3A.1f%7D%25%20%7C%20%60%7Btest_loo_metrics%5B%22mean_wwl%22%5D%3A.3f%7D%60%20%7C%20%7Btest_loo_metrics%5B%22comp_f1%22%5D%20*%20100%3A.1f%7D%25%20%7C%20%7Btest_loo_metrics%5B%22bigram_f1%22%5D%20*%20100%3A.1f%7D%25%20%7C%0A%0A%20%20%20%20**Tuned%20%60GlycanPredictorParams%60**%3A%20%60w_pan_dl%3D%7Bbest_arb_params.w_pan_dl%3A.2f%7D%60%2C%20%60w_knn_gt%3D%7Bbest_arb_params.w_knn_gt%3A.2f%7D%60%2C%20%60w_clf_dl%3D%7Bbest_arb_params.w_clf_dl%3A.2f%7D%60%2C%20%60w_clf_factorized%3D%7Bbest_arb_params.w_clf_factorized%3A.2f%7D%60%2C%20%60w_mpnn_dl_free%3D%7Bbest_arb_params.w_mpnn_dl_free%3A.2f%7D%60%2C%20%60syntenic_msg_alpha%3D%7Bbest_arb_params.syntenic_msg_alpha%3A.3f%7D%60%2C%20%60w_backbone_log%3D%7Bbest_arb_params.w_backbone_log%3A.2f%7D%60%2C%20%60w_precursor_bonus%3D%7Bbest_arb_params.w_precursor_bonus%3A.2f%7D%60%2C%20%60w_acceptor_prob%3D%7Bbest_arb_params.w_acceptor_prob%3A.2f%7D%60%2C%20%60w_acceptor_motif%3D%7Bbest_arb_params.w_acceptor_motif%3A.2f%7D%60%2C%20%60w_mpnn_edge%3D%7Bbest_arb_params.w_mpnn_edge%3A.2f%7D%60%2C%20%60w_pan_acc_match%3D%7Bbest_arb_params.w_pan_acc_match%3A.2f%7D%60%2C%20%60w_disac_bigram%3D%7Bbest_arb_params.w_disac_bigram%3A.2f%7D%60%2C%20%60w_syntenic_step%3D%7Bbest_arb_params.w_syntenic_step%3A.2f%7D%60.%0A%20%20%20%20%22%22%22%0A%0A%20%20%20%20mo.vstack(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%22%23%23%205.%20Reference%20Tables%3A%20Held-Out%20Test%20Regimes%20%26%20Optuna%20TPE%20Trial%20Logs%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.ui.tabs(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Held-Out%20Test%20Regimes%20%26%20Tuned%20Params%22%3A%20mo.md(_reg_table)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Phase%201%20(RelationalMPNN)%20Trials%22%3A%20mo.md(_p1_table)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Phase%202%20(Arborescence)%20Trials%22%3A%20mo.md(_p2_table)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20gap%3D0.8%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
a9b7fef8c05f46e47f64aefc98d0d2ff