scripts/rank_islet1_stacks.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/rank_islet1_stacks.py · SHA-256: c05d5fe606219e88…
d4_cond = _frechet_couple_new_arm_iip0034(d4_inc, p_y[3] / 0.85, 1.0, lambda mi: bool(mi & 2))
d4 = [0.0] * 16
d4[0] += 0.15
for k in range(16):
d4[k] += 0.85 * d4_cond[k]
c4_e = 0.85
routes = ('R1', 'R2', 'R1', 'R2')
y_cell_class = 'DESIGN_Y_HYPOTHETICAL_R2_COUNTERFACTUAL'
eff_stage0_status = 'HYPOTHETICAL_UNREGISTERED_LEGACY_R2_COUNTERFACTUAL'
elif h4_mode == "ORTHOG_R3P":
biv4 = _bivariate_bernoulli_iip0034(0.85 / c4_univ, c4_r3 / c4_univ, phi_h4)
u_y4 = p_y[3] / c4_r3
d4 = [0.0] * 16
d4[0] += 1.0 - c4_univ
for (s0, s1), wp in biv4.items():
w = c4_univ * wp
if s0 == 0 and s1 == 0:
d4[0] += w
elif s0 == 1 and s1 == 0:
for mi in range(8):
d4[mi] += w * d4_inc[mi]
elif s0 == 0 and s1 == 1:
d4[0] += w * (1.0 - u_y4)
d4[8] += w * u_y4
else:
for mi in range(8):
d4[mi] += w * d4_inc[mi] * (1.0 - u_y4)
d4[mi | 8] += w * d4_inc[mi] * u_y4
c4_e = c4_univ * (1.0 - biv4[(0, 0)])
routes = ('R1', 'R2', 'R1', 'R3P')
y_cell_class = 'DESIGN_Y_FULLSTACK_V2'
eff_stage0_status = stage0_status
else:
raise ValueError(h4_mode)
return _run_dp_and_verify_parity_iip0034(
label,
[pa, pb, px, p_y],
[d1, d2, d3, d4],
[0.88, c2_e, c3_e, c4_e],
p0_l,
p0_m,
c0,
stage0_status=eff_stage0_status,
cell_classes=('UNHARDENED_A_B_X', 'UNHARDENED_A_B_X', 'UNHARDENED_A_B_X', y_cell_class),
route_ids=routes,
)
def _eval_5arm(
label: str,
p_y: tuple[float, float, float, float],
p_d1: tuple[float, float, float, float],
*,
c2_y: float,
c3_y: float,
phi_c: float,
d1_on_r3: bool,
c4_univ: float,
c4_r3: float,
stage0_status: str,
) -> dict:
c2_univ, c2_auto, phi_yx = 0.95, 0.93, 0.75
u_d1 = p_d1[0] / 0.88
d1 = [0.0] * 32
d1[0] = 0.12
d1[15] = 0.88 * (1.0 - u_d1)
d1[31] = 0.88 * u_d1
d2_inc = _frechet_bernoulli_joint_iip0034([pa[1] / 0.87, pb[1] / 0.87, px[1] / 0.87], 0.0)
r2 = 0.87 / c2_y
u_y2 = p_y[1] / c2_y
d2_both = _frechet_couple_new_arm_iip0034(d2_inc, u_y2, phi_yx, lambda mi: bool(mi & 4))
d2_allo4 = [0.0] * 16
for k in range(16):
d2_allo4[k] += r2 * d2_both[k]
d2_allo4[0] += (1.0 - r2) * (1.0 - u_y2)
d2_allo4[8] += (1.0 - r2) * u_y2
biv2 = _bivariate_bernoulli_iip0034(c2_y / c2_univ, c2_auto / c2_univ, phi_c)
u_d2 = p_d1[1] / c2_auto
d2 = [0.0] * 32
d2[0] += 1.0 - c2_univ
for (s0, s1), wp in biv2.items():
w = c2_univ * wp
if s0 == 0 and s1 == 0:
d2[0] += w
elif s0 == 1 and s1 == 0:
for m4 in range(16):
d2[m4] += w * d2_allo4[m4]
elif s0 == 0 and s1 == 1:
d2[0] += w * (1.0 - u_d2)
d2[16] += w * u_d2
else:
for m4 in range(16):
d2[m4] += w * d2_allo4[m4] * (1.0 - u_d2)
d2[m4 | 16] += w * d2_allo4[m4] * u_d2
c2_e = c2_univ * (1.0 - biv2[(0, 0)])
d3_inc = _frechet_bernoulli_joint_iip0034([pa[2] / 0.89, pb[2] / 0.89, px[2] / 0.89], 0.0)
r3 = 0.89 / c3_y
u_y3 = p_y[2] / c3_y
d3_both = _frechet_couple_new_arm_iip0034(d3_inc, u_y3, phi_yx, lambda mi: bool(mi & 4))
d3_allo4 = [0.0] * 16
for k in range(16):
d3_allo4[k] += r3 * d3_both[k]
d3_allo4[0] += (1.0 - r3) * (1.0 - u_y3)
d3_allo4[8] += (1.0 - r3) * u_y3
d3_5cond = _frechet_couple_new_arm_iip0034(d3_allo4, p_d1[2] / c3_y, phi_c, lambda m4: m4 != 0)
d3 = [0.0] * 32
d3[0] += 1.0 - c3_y
for k in range(32):
d3[k] += c3_y * d3_5cond[k]
c3_e = c3_y
d4_inc = _live_incumbent_h4_cond_iip0034()
biv4 = _bivariate_bernoulli_iip0034(0.85 / c4_univ, c4_r3 / c4_univ, phi_c)
d4 = [0.0] * 32
d4[0] += 1.0 - c4_univ
if d1_on_r3:
d4_r3 = _frechet_bernoulli_joint_iip0034([p_y[3] / c4_r3, p_d1[3] / c4_r3], 1.0)
for (s0, s1), wp in biv4.items():
w = c4_univ * wp
if s0 == 0 and s1 == 0:
d4[0] += w
elif s0 == 1 and s1 == 0:
for m3 in range(8):
d4[m3] += w * d4_inc[m3]
elif s0 == 0 and s1 == 1:
for mr in range(4):
m5 = ((mr & 1) << 3) | (((mr >> 1) & 1) << 4)
d4[m5] += w * d4_r3[mr]
else:
for m3 in range(8):
for mr in range(4):
m5 = m3 | ((mr & 1) << 3) | (((mr >> 1) & 1) << 4)
d4[m5] += w * d4_inc[m3] * d4_r3[mr]
routes = ('R1', 'R2', 'R1', 'R3P', 'R3P')
else:
d4_pouch_d1 = _frechet_couple_new_arm_iip0034(d4_inc, p_d1[3] / 0.85, 1.0, lambda m3: bool(m3 & 2))
d4_p0 = [0.0] * 32
for m4 in range(16):
d4_p0[(m4 & 7) | (((m4 >> 3) & 1) << 4)] = d4_pouch_d1[m4]
u_y4 = p_y[3] / c4_r3
for (s0, s1), wp in biv4.items():
w = c4_univ * wp
if s0 == 0 and s1 == 0:
d4[0] += w
elif s0 == 1 and s1 == 0:
for m5 in range(32):
if d4_p0[m5]:
d4[m5] += w * d4_p0[m5]
elif s0 == 0 and s1 == 1:
d4[0] += w * (1.0 - u_y4)
d4[8] += w * u_y4
else:
for m5 in range(32):
if d4_p0[m5]:
d4[m5] += w * d4_p0[m5] * (1.0 - u_y4)
d4[m5 | 8] += w * d4_p0[m5] * u_y4
routes = ('R1', 'R2', 'R1', 'R3P', 'R2')
c4_e = c4_univ * (1.0 - biv4[(0, 0)])
return _run_dp_and_verify_parity_iip0034(
label,
[pa, pb, px, p_y, p_d1],
[d1, d2, d3, d4],
[0.88, c2_e, c3_e, c4_e],
p0_l,
p0_m,
c0,
stage0_status=stage0_status,
cell_classes=('UNHARDENED_A_B_X', 'UNHARDENED_A_B_X', 'UNHARDENED_A_B_X', 'DESIGN_Y_FULLSTACK_V2', 'D1B_AUTO_C_V2'),
route_ids=routes,
)
zero_lift_4arm = [
_eval_4arm(lbl, py, c2_y=0.87, c3_y=0.89, phi_yx=phi_yx, h4_mode=h4m, c4_univ=c4u, c4_r3=c4r3, phi_h4=phi_h4, stage0_status="CONSERVATIVE_ZERO_H2_H3_LIFT_ARCHITECTURAL_BOUND")
for lbl, py, h4m, phi_yx, c4u, c4r3, phi_h4 in [
("W_B0_4Arm_Y@R2_ZeroLift_phiYX0.75 (No Route 3P)", (0.88, 0.84, 0.80, 0.70), "SHARED_R2", 0.75, 0.85, 0.85, 1.00),
("W_B1_4Arm_Y@PrePerf3P_ZeroLift_c4u0.92_phiYX0.75_phiH4=0.25", (0.88, 0.84, 0.80, 0.72), "ORTHOG_R3P", 0.75, 0.92, 0.85, 0.25),
("W_B2_4Arm_Y@PrePerf3P_ZeroLift_c4u0.92_phiYX0.75_phiH4=0.50", (0.88, 0.84, 0.80, 0.72), "ORTHOG_R3P", 0.75, 0.92, 0.85, 0.50),
("W_B3_4Arm_Y@Hybrid3P_ZeroLift_c4u0.92_phiYX0.75_phiH4=0.25", (0.88, 0.84, 0.80, 0.75), "ORTHOG_R3P", 0.75, 0.92, 0.87, 0.25),
("W_B4_4Arm_Y@Hybrid3P_ZeroLift_c4u0.92_phiYX0.75_phiH4=0.50", (0.88, 0.84, 0.80, 0.75), "ORTHOG_R3P", 0.75, 0.92, 0.87, 0.50),
]
]
conditional_4arm = [
_eval_4arm(lbl, py, c2_y=c2y, c3_y=c3y, phi_yx=phi_yx, h4_mode="ORTHOG_R3P", c4_univ=c4u, c4_r3=c4r3, phi_h4=phi_h4, stage0_status="STAGE0_GATED_CONDITIONAL_POST_QUALIFICATION_ONLY")
for lbl, py, c2y, c3y, phi_yx, c4u, c4r3, phi_h4 in [
("W_B5_4Arm_Y@PrePerf3P_Nested(90/92)_c4u0.92_phiYX0.75_phiH4=0.25", (0.88, 0.84, 0.80, 0.72), 0.90, 0.92, 0.75, 0.92, 0.85, 0.25),
("W_B6_4Arm_Y@PrePerf3P_Nested(90/92)_c4u0.92_phiYX0.75_phiH4=0.50", (0.88, 0.84, 0.80, 0.72), 0.90, 0.92, 0.75, 0.92, 0.85, 0.50),
("W_B7_4Arm_Y@PrePerf3P_Nested(90/92)_c4u0.90_phiYX0.75_phiH4=0.50", (0.88, 0.84, 0.80, 0.72), 0.90, 0.92, 0.75, 0.90, 0.85, 0.50),
("W_B8_4Arm_Y@PrePerf3P_Nested(90/92)_c4u0.90_phiYX1.00_phiH4=0.50", (0.88, 0.84, 0.80, 0.72), 0.90, 0.92, 1.00, 0.90, 0.85, 0.50),
("W_B9_4Arm_Y@PrePerf3P_Nested(90/92)_pY4=0.68_c4u0.90_phi1.0_50", (0.88, 0.84, 0.80, 0.68), 0.90, 0.92, 1.00, 0.90, 0.85, 0.50),
("W_B10_4Arm_Y@Hybrid3P_Nested(90/92)_c4u0.92_phiYX0.75_phiH4=0.25", (0.88, 0.84, 0.80, 0.75), 0.90, 0.92, 0.75, 0.92, 0.87, 0.25),
("W_B11_4Arm_Y@Hybrid3P_Nested(90/92)_c4u0.92_phiYX0.75_phiH4=0.50", (0.88, 0.84, 0.80, 0.75), 0.90, 0.92, 0.75, 0.92, 0.87, 0.50),
("W_B12_4Arm_Y@Hybrid3P_Nested(90/92)_c4u0.90_phiYX1.00_phiH4=0.50", (0.88, 0.84, 0.80, 0.75), 0.90, 0.92, 1.00, 0.90, 0.87, 0.50),
("W_B13_4Arm_Y@PrePerf3P_PartialLift(89/91)_c4u0.92_phiYX0.75_25", (0.88, 0.84, 0.80, 0.72), 0.89, 0.91, 0.75, 0.92, 0.85, 0.25),
("W_B14_4Arm_Y@PrePerf3P_PartialLift(89/91)_c4u0.92_phiYX0.75_50", (0.88, 0.84, 0.80, 0.72), 0.89, 0.91, 0.75, 0.92, 0.85, 0.50),
]
]
phi_h4_sensitivity_counterexamples = [
_eval_4arm(
"W_B9_SENSITIVITY_phiH4=0.60_BELOW_57p92_CEILING",
(0.88, 0.84, 0.80, 0.68),
c2_y=0.90,
c3_y=0.92,
phi_yx=1.00,
h4_mode="ORTHOG_R3P",
c4_univ=0.90,
c4_r3=0.85,
phi_h4=0.60,
stage0_status="SENSITIVITY_COUNTEREXAMPLE_PHI_H4_GT_0P50",
),
_eval_4arm(
"W_B3_SENSITIVITY_Y_H2H3_MARGINALS_EQUALIZED_TO_X_BELOW_57p92",
(0.88, 0.82, 0.73, 0.75),
c2_y=0.87,
c3_y=0.89,
phi_yx=0.75,
h4_mode="ORTHOG_R3P",
c4_univ=0.92,
c4_r3=0.87,
phi_h4=0.25,
stage0_status="SENSITIVITY_COUNTEREXAMPLE_EQUALIZED_H2H3_MARGINALS",
),
]
def _eval_4arm_negative_cross_hurdle_sensitivity(
label: str,
p_y: tuple[float, float, float, float],
*,
c2_y: float,
c3_y: float,
phi_yx: float,
c4_univ: float,
c4_r3: float,
phi_h4: float,
adverse_mix_weight: float = 0.10,
) -> dict:
d1 = [0.0] * 16
d1[0] = 0.12
d1[15] = 0.88
def _nested_h(inc_probs: list[float], c_inc: float, p_arm_y: float, c_arm_y: float) -> list[float]:
d_inc = _frechet_bernoulli_joint_iip0034([p / c_inc for p in inc_probs], 0.0)
r = c_inc / c_arm_y
u_y = p_arm_y / c_arm_y
d_both = _frechet_couple_new_arm_iip0034(d_inc, u_y, phi_yx, lambda mi: bool(mi & 4))
d = [0.0] * 16
d[0] += 1.0 - c_arm_y