{"variant":"small Gaussian mixture posterior of z=ln(p/spot), <=4 components, latent arb/retail branches on first callback per step, moment-matched truncation, pairwise moment-matched merge with Ward-style merge cost logged; replicate A","status":"complete for replica evaluation; target gap<=2 NOT met (gap 7.68)","engine":"pure-Python replica.py (gtmcknight/amm-sim research), NOT the Rust engine; no Solidity port; no 5148000.. seeds touched","seeds":{"train":"0..127 (tuning used 0..3 for classifier/router params and 0..31 for one closed-loop check)","frozen_eval":"10000..10255 (256 seeds, 10000 steps each, per-seed sigma/lambda/size drawn by replica from seed)","ablation":"10000..10063"},"inputs":{"urls":{"filter-brief":"https://raw.githubusercontent.com/gtmcknight/amm-sim/main/research/filter-brief.md","oracle_table":"https://raw.githubusercontent.com/gtmcknight/amm-sim/main/research/oracle_table.json","replica":"https://raw.githubusercontent.com/gtmcknight/amm-sim/main/research/replica.py","simulator":"https://github.com/benedictbrady/amm-challenge@6b6921f8d463314aa7c96234e1be25a25245f704"},"sha256":{"filter-brief.md":"0ef2200226b68aa58de6aad268442ba09ada710c54b3fb0ec35c77b491f78a4b","oracle_table.json":"3e9d1fc8874c6d796d4c26948d486b587f2a6b5610b20fba99923a60954cf4b5","replica.py":"d079712fa1f4850ad8337e656e7ee8dbdde806cd4762d597fae50f547ef9c7c4","setup.sh":"dc7fa6a1e59f5b043d3954cf68d538318b7affaf5c0db3ca69a1822680f300d4"}},"parameters_frozen":"ncomp=4, sigma0=0.000945 (midpoint of brief's public range), sigma_prior_n=20 pseudo-obs, R_router_bps=80, router_bias_bps=0, retail_first_prob=0.25, retail_size_mean=20 (midpoint of public 19..21), vmin=1e-12, router=True; sigma updated only from pins with P(arb)>0.9 and gap<=50 steps","aggregate":{"filtered":{"edge":527.54,"retail_edge":565.308,"arb_edge":-37.768,"retail_vol_y":75455.7,"arb_vol_y":25224.4,"callback_rms_bps":16.748,"coverage_95":0.9493,"flag_accuracy_all_callbacks":0.9007},"oracle_truep_trueflag":{"edge":535.217,"retail_edge":566.714,"arb_edge":-31.497,"retail_vol_y":76276.1,"arb_vol_y":23965.9,"callback_rms_bps":16.039,"coverage_95":0.9485,"flag_accuracy_all_callbacks":0.9097},"diag_truep_inferredflag":{"edge":534.967,"retail_edge":566.444,"arb_edge":-31.477,"retail_vol_y":75987.2,"arb_vol_y":23924.7,"callback_rms_bps":16.076,"coverage_95":0.9475,"flag_accuracy_all_callbacks":0.9102},"gap_oracle_minus_filter":{"n":256,"mean":7.6773,"se":0.2603,"ci95":[7.1671,8.1875]},"gap_oracle_minus_diag":{"n":256,"mean":0.25,"se":0.0127,"ci95":[0.225,0.275]},"note":"RMS/coverage for oracle/diag arms are of the filter run passively alongside (closed loop differs)."},"ablation_router_off":{"seeds":"10000..10063","gap_router_off":{"n":64,"mean":6.3819,"se":0.1522,"ci95":[6.0835,6.6802]},"gap_router_on_same_seeds":{"n":64,"mean":7.7431,"se":0.6178,"ci95":[6.5323,8.9539]},"filter_edge_off_minus_on":{"n":64,"mean":1.3612,"se":0.608,"ci95":[0.1695,2.5529]},"filtered_rms_bps_off":15.147,"filtered_rms_bps_on":19.487,"reading":"router likelihood as implemented is net harmful; not retuned per brief"},"per_seed":{"columns":["seed","filt_edge","orac_edge","diag_edge","filt_retail","filt_arb","filt_rv","filt_av","orac_retail","orac_arb","orac_rv","orac_av","filt_sqlog_sum","filt_count","filt_cov95_count","sigma_true","sigma_hat"],"rows":[[10000,438.1,445.68,445.46,462.74,-24.64,61622,21846,465.42,-19.74,62676,20750,0.020991,8491,8040,0.00090664,0.00084125],[10001,566.44,572.59,572.39,597.92,-31.48,88012,27222,598.36,-25.76,88629,26004,0.023346,11725,11189,0.00091221,0.00084905],[10002,518.39,527.97,527.67,555.32,-36.93,68550,25488,555.46,-27.49,69316,23992,0.025761,9623,9129,0.00099732,0.000925],[10003,565.99,573.64,573.58,597.84,-31.85,82165,27340,599.41,-25.77,82804,25936,0.025116,11207,10608,0.00089921,0.00083541],[10004,518.03,524.59,524.39,545.83,-27.8,72978,24700,547.57,-22.98,73742,23809,0.021014,9920,9418,0.00088483,0.00082016],[10005,522.56,527.73,527.84,552.36,-29.8,73006,24620,550.98,-23.25,73539,23415,0.021701,9995,9542,0.00090415,0.00084972],[10006,480.88,487.62,487.22,508.84,-27.97,74708,24129,510.14,-22.51,75296,22988,0.021479,10293,9765,0.00089553,0.00081755],[10007,519.84,527.21,527.09,549.01,-29.17,76566,24831,551.18,-23.97,77243,23735,0.024278,10541,9992,0.00092587,0.00083934],[10008,653.87,664.11,663.67,689.55,-35.68,95363,29092,692.07,-27.96,96184,27361,0.027828,12030,11323,0.00098336,0.00091618],[10009,647.74,653.73,653.66,681.39,-33.65,91983,28614,681.57,-27.83,92586,27195,0.027514,12133,11452,0.00093491,0.00089387],[10010,472.93,479.56,479.34,500.57,-27.65,75394,24100,501.6,-22.04,76561,22847,0.024835,10714,10189,0.0009202,0.00085925],[10011,365.47,371.52,371.21,387.1,-21.63,58271,19450,388.93,-17.41,58838,18499,0.019721,8331,7930,0.00091798,0.00081389],[10012,452.12,459.0,458.61,480.42,-28.3,74073,24006,481.24,-22.24,75283,22751,0.025615,10320,9750,0.00095876,0.0009009],[10013,396.57,402.85,402.32,418.77,-22.2,57152,19833,420.49,-17.64,58206,18876,0.020213,8256,7825,0.00089028,0.00079981],[10014,695.35,702.86,703.06,734.04,-38.69,87068,27728,735.25,-32.39,87676,26631,0.021834,11270,10841,0.00089315,0.00086888],[10015,620.71,632.33,632.15,656.39,-35.68,92176,29194,660.92,-28.59,93499,27734,0.030048,11790,11151,0.00098557,0.00093981],[10016,557.88,569.34,569.22,630.05,-72.17,70875,24656,635.46,-66.12,71953,23389,0.024227,9688,9216,0.00096742,0.00087978],[10017,489.04,494.51,494.23,518.16,-29.12,72367,24950,518.84,-24.33,73105,23875,0.022242,10127,9651,0.0009732,0.00088151],[10018,475.05,482.17,481.99,503.19,-28.14,69650,24618,504.76,-22.59,70469,23390,0.021895,9504,9016,0.00091072,0.00084912],[10019,449.64,455.47,455.14,474.25,-24.61,61101,21478,474.95,-19.49,62126,20408,0.020834,8467,8023,0.00089532,0.00080686],[10020,491.23,498.15,497.78,519.03,-27.8,67906,24191,521.05,-22.89,68460,23206,0.01903,9330,8958,0.00088717,0.00083649],[10021,405.97,413.41,412.77,428.36,-22.39,56801,20510,431.31,-17.9,57696,19503,0.022394,8395,7920,0.00089878,0.00082468],[10022,434.23,442.04,441.56,459.14,-24.91,61087,21458,461.85,-19.82,61813,20259,0.023583,8742,8208,0.00095352,0.00085784],[10023,629.05,635.3,635.06,665.01,-35.96,87004,27721,664.3,-29.0,87931,26226,0.023169,11003,10476,0.00089759,0.00084584],[10024,474.85,483.68,483.43,503.85,-29.0,72860,25015,506.96,-23.29,73875,23743,0.025783,10558,10025,0.00095594,0.00089285],[10025,440.66,447.67,447.21,466.25,-25.58,61647,21564,468.14,-20.47,62444,20480,0.023575,9168,8735,0.00095986,0.00088673],[10026,341.72,347.39,347.13,362.79,-21.07,53786,19188,364.63,-17.24,54625,18426,0.019424,8384,8026,0.00092414,0.00086551],[10027,542.22,549.71,549.85,573.12,-30.9,73143,25423,574.4,-24.69,73914,24197,0.025908,10136,9565,0.0010013,0.00092385],[10028,521.14,527.77,527.68,553.62,-32.48,68082,24199,554.83,-27.06,68638,23007,0.023627,9272,8779,0.00099581,0.00091054],[10029,437.42,444.58,444.04,462.45,-25.03,72112,22478,464.82,-20.23,72761,21296,0.02351,10269,9709,0.00088575,0.00081484],[10030,589.01,597.82,597.49,624.11,-35.1,89193,28698,625.56,-27.74,89760,27047,0.028021,11727,11140,0.00095177,0.00092672],[10031,335.5,343.56,343.41,358.87,-23.37,57026,20893,361.74,-18.18,58012,19671,0.023451,8618,8237,0.00096793,0.00090478],[10032,631.54,637.94,637.84,665.0,-33.47,86191,27701,664.71,-26.78,86666,26072,0.023842,11053,10521,0.00095749,0.00086874],[10033,529.84,536.45,536.36,561.37,-31.53,81456,26397,561.36,-24.91,82156,25100,0.025692,10860,10271,0.00096454,0.00089139],[10034,558.99,566.54,566.19,590.06,-31.07,83913,26023,590.86,-24.32,84710,24619,0.028571,11428,10740,0.00093709,0.00085613],[10035,627.47,636.15,635.76,664.25,-36.78,94012,29289,664.6,-28.45,95097,27580,0.029029,12207,11589,0.00098176,0.00095335],[10036,540.5,546.64,546.33,571.96,-31.47,81614,26149,571.15,-24.51,82299,24462,0.027347,10987,10286,0.00098799,0.00089538],[10037,439.55,445.18,444.95,465.96,-26.41,66516,22799,466.13,-20.94,67466,21412,0.022277,9376,8959,0.00093685,0.00088194],[10038,614.16,620.61,620.42,647.62,-33.45,91693,28315,647.59,-26.99,92528,26776,0.027358,12374,11729,0.00096958,0.00090813],[10039,582.98,590.59,590.26,618.72,-35.74,78512,25762,619.96,-29.38,79367,24324,0.028194,10681,10059,0.00098702,0.00093188],[10040,603.92,609.99,609.94,636.37,-32.45,91107,28196,636.93,-26.95,91586,27149,0.023303,12275,11685,0.00088952,0.00082341],[10041,625.91,632.28,632.06,657.65,-31.74,86057,27247,657.78,-25.51,86756,25890,0.022771,11285,10780,0.00092459,0.0008639],[10042,705.42,711.21,711.23,742.01,-36.59,93490,30179,740.97,-29.76,94010,28685,0.022886,12117,11532,0.0009005,0.00084801],[10043,631.66,639.26,639.1,665.65,-33.99,88555,27893,666.8,-27.54,89320,26457,0.026663,11498,10896,0.00095168,0.00090253],[10044,414.77,421.89,421.66,439.27,-24.5,60997,21492,441.49,-19.6,61837,20569,0.018813,8466,8046,0.00090623,0.00081043],[10045,381.15,388.11,387.95,405.8,-24.65,60734,22007,408.25,-20.14,61893,21022,0.023015,8962,8488,0.00096773,0.00086762],[10046,426.36,434.19,433.5,455.74,-29.38,68997,24712,457.45,-23.26,69992,23413,0.025789,10048,9598,0.0010012,0.00093722],[10047,591.59,599.64,599.45,626.36,-34.77,91254,29165,627.59,-27.95,92300,27514,0.026387,12056,11496,0.00095041,0.00092287],[10048,490.31,497.21,496.86,518.58,-28.27,71133,23854,519.67,-22.46,71939,22580,0.027096,10034,9507,0.00099556,0.00092928],[10049,380.24,385.91,385.57,401.41,-21.17,57117,19560,403.29,-17.38,57914,18882,0.01963,8491,8060,0.00088681,0.00080396],[10050,371.09,378.55,378.3,393.94,-22.84,57554,20737,397.26,-18.71,58404,19888,0.021894,8802,8395,0.00088545,0.00084131],[10051,418.91,424.73,424.46,443.15,-24.24,60263,21679,444.66,-19.93,61022,20861,0.021607,8652,8148,0.00089823,0.00084583],[10052,423.58,431.55,431.16,449.67,-26.09,68758,22997,452.52,-20.98,69601,22038,0.024077,10043,9454,0.00089485,0.00081161],[10053,530.3,537.97,538.02,560.07,-29.77,73116,24642,561.51,-23.54,74077,23256,0.024639,10080,9581,0.00096449,0.00089646],[10054,439.37,444.33,444.18,469.12,-29.76,63684,22519,468.34,-24.01,64445,21140,0.0236,9070,8624,0.00095197,0.00085835],[10055,704.15,710.74,710.45,742.96,-38.81,95569,31139,741.36,-30.62,96637,29556,0.028726,12376,11766,0.00096161,0.00092446],[10056,578.12,583.46,583.37,609.26,-31.14,84100,26432,608.56,-25.1,84401,25291,0.02231,10824,10280,0.00089595,0.00083916],[10057,504.47,510.84,510.58,531.7,-27.24,68847,23452,532.82,-21.98,69679,22303,0.021666,9644,9187,0.00091794,0.00085403],[10058,433.6,440.07,439.48,457.51,-23.91,58510,21093,459.6,-19.53,59357,20169,0.021866,8778,8349,0.00096005,0.00090019],[10059,499.69,509.44,509.44,533.26,-33.56,71945,25681,534.18,-24.74,72850,24404,0.025876,9831,9365,0.00099234,0.00094857],[10060,883.72,928.77,928.4,2072.41,-1188.69,89433,31453,2097.78,-1169.01,92365,30249,0.98289,11378,10754,0.00099953,0.000914],[10061,555.29,562.9,562.24,584.22,-28.93,83112,25698,587.04,-24.13,83914,24669,0.023316,11263,10693,0.00089614,0.00083457],[10062,600.98,610.98,610.8,632.72,-31.75,89960,27425,636.68,-25.7,90989,26017,0.026531,11788,11173,0.00092012,0.00087252],[10063,424.23,429.33,429.27,448.28,-24.05,63953,21227,448.65,-19.32,64899,20338,0.021192,9195,8741,0.00088291,0.00089025],[10064,653.2,662.16,662.0,689.24,-36.04,94802,29093,691.81,-29.65,95371,27644,0.025967,12038,11351,0.00090238,0.00086358],[10065,578.62,586.34,585.77,609.61,-30.99,82367,26139,611.99,-25.65,83055,25086,0.026396,10902,10265,0.00095684,0.00088689],[10066,478.66,486.2,485.71,506.74,-28.08,73379,23981,508.71,-22.51,74211,22714,0.024522,9958,9405,0.00092181,0.00086193],[10067,629.38,635.01,634.62,662.38,-32.99,80131,26776,662.2,-27.19,80615,25592,0.022783,10562,10058,0.00089006,0.00082708],[10068,498.05,504.96,504.78,524.93,-26.88,60527,23218,527.02,-22.06,61436,22260,0.019875,8605,8246,0.00093364,0.00085712],[10069,615.63,623.18,623.0,648.42,-32.8,80958,26493,649.63,-26.46,81742,25254,0.023895,10960,10434,0.00091763,0.00085135],[10070,407.58,413.64,413.39,432.86,-25.28,58246,22329,434.49,-20.84,59111,21204,0.021517,8338,7939,0.00097432,0.00090691],[10071,429.44,437.32,437.16,454.71,-25.27,62341,21428,457.18,-19.86,63532,20212,0.023724,8900,8459,0.00096037,0.00088054],[10072,597.7,605.87,605.65,649.15,-51.45,77362,24986,651.21,-45.34,78127,23887,0.022336,10418,9977,0.00088784,0.00086426],[10073,561.65,567.74,567.5,591.77,-30.13,81294,26568,592.6,-24.86,81980,25489,0.021134,10820,10312,0.00089389,0.00083714],[10074,524.66,533.08,533.45,554.3,-29.64,74305,24628,556.8,-23.72,74947,23396,0.022837,10039,9548,0.00094219,0.00086189],[10075,555.97,562.43,562.17,587.01,-31.04,79775,26077,587.23,-24.8,80849,24749,0.025772,11164,10594,0.00097194,0.0009104],[10076,523.51,530.84,530.4,554.61,-31.1,78724,25849,555.43,-24.59,79545,24537,0.024465,10819,10289,0.00091778,0.00086067],[10077,423.37,430.33,430.29,447.59,-24.23,66651,21921,450.08,-19.75,67502,20811,0.023464,9715,9132,0.00090232,0.00082106],[10078,614.68,622.08,622.1,648.56,-33.89,89609,27234,649.53,-27.45,90460,25916,0.028429,11508,10699,0.00095746,0.00086885],[10079,644.13,650.61,650.85,680.92,-36.78,89228,29238,679.76,-29.15,89868,27639,0.027211,11648,11052,0.00097939,0.00090819],[10080,481.37,488.07,488.11,511.11,-29.75,69456,25000,511.78,-23.71,70171,23523,0.025613,9605,9124,0.0010019,0.00093533],[10081,561.14,567.41,567.33,592.99,-31.84,75949,25761,593.49,-26.08,76711,24566,0.021136,10117,9673,0.00089993,0.00084823],[10082,560.3,566.73,566.6,591.62,-31.32,76267,25389,591.75,-25.02,76934,24103,0.021923,10333,9922,0.00096287,0.00091272],[10083,461.22,467.22,467.01,488.59,-27.37,72842,24239,489.65,-22.43,73593,23243,0.022751,10307,9776,0.00091816,0.00084827],[10084,469.89,476.21,475.6,496.65,-26.76,68751,23206,497.39,-21.18,69541,21897,0.021735,9292,8825,0.00088693,0.00083573],[10085,449.52,455.71,455.68,475.01,-25.48,63260,22548,476.49,-20.78,63972,21521,0.01977,9156,8810,0.00093201,0.00087153],[10086,565.95,573.84,573.77,598.85,-32.9,84203,27013,599.91,-26.07,84819,25517,0.026006,11310,10710,0.00097749,0.00091572],[10087,563.75,571.98,571.84,594.28,-30.53,86952,26381,596.55,-24.57,87792,24983,0.02588,11785,11174,0.00090266,0.00086673],[10088,433.79,442.48,442.35,460.79,-27.0,66328,23377,464.66,-22.19,67514,22278,0.024574,9337,8838,0.00095532,0.00088529],[10089,408.81,414.9,414.3,434.07,-25.26,60485,22036,435.16,-20.26,61438,20855,0.023469,8550,8092,0.00098984,0.00089285],[10090,581.07,587.68,587.08,616.45,-35.38,87684,28553,615.69,-28.01,88385,26948,0.027417,11864,11224,0.00098316,0.00092267],[10091,478.77,486.85,486.69,508.27,-29.5,67477,24038,510.75,-23.89,68349,22957,0.023163,9641,9266,0.00098486,0.00092107],[10092,553.02,557.74,557.78,582.78,-29.76,75081,25197,581.49,-23.74,75797,23933,0.021672,10030,9534,0.00091375,0.00086008],[10093,653.99,663.4,663.54,695.72,-41.73,92844,29076,699.16,-35.76,93753,27634,0.026739,12112,11417,0.00094225,0.00088024],[10094,473.53,480.64,480.56,503.27,-29.74,69017,24951,504.37,-23.73,69562,23973,0.020835,9577,9176,0.00091686,0.00087757],[10095,589.34,597.95,598.0,623.76,-34.43,85304,27870,624.98,-27.04,86227,26286,0.026167,11238,10694,0.00097935,0.00092069],[10096,486.02,492.09,492.25,511.55,-25.53,66805,23180,513.59,-21.5,67390,22190,0.020595,9302,8801,0.00089059,0.00082188],[10097,505.67,512.79,512.31,533.13,-27.47,72749,23199,534.44,-21.66,73630,21850,0.023607,10065,9535,0.0009374,0.00087906],[10098,497.31,503.26,503.36,525.18,-27.87,76389,24571,525.89,-22.62,77059,23409,0.024771,10850,10281,0.00092849,0.00085479],[10099,464.18,470.46,470.02,489.47,-25.3,71688,22900,491.43,-20.97,72539,22151,0.019817,9850,9411,0.00088251,0.00084017],[10100,436.61,444.1,444.11,466.92,-30.31,61219,22546,469.16,-25.06,62530,21211,0.026577,8659,8211,0.00098339,0.0009083],[10101,529.16,536.95,536.65,559.43,-30.28,75975,25138,560.53,-23.58,76584,23933,0.023422,10388,9846,0.00088303,0.00083822],[10102,721.45,737.24,736.91,771.85,-50.4,98311,31197,771.6,-34.37,98778,29533,0.04738,12618,11912,0.00093111,0.0008533],[10103,733.48,741.53,741.04,770.24,-36.76,92967,29364,770.87,-29.34,93943,27808,0.026876,11833,11222,0.00096873,0.00091418],[10104,698.35,703.15,703.22,736.25,-37.91,97222,30865,733.44,-30.29,97834,29156,0.026455,12255,11508,0.0009366,0.00087291],[10105,464.98,472.24,472.13,492.29,-27.32,63126,23429,493.68,-21.44,63972,22505,0.022046,9144,8698,0.00090346,0.00084578],[10106,422.35,429.58,429.42,449.71,-27.36,58726,20902,450.31,-20.73,59651,19834,0.021035,8370,7971,0.00093051,0.0008582],[10107,484.05,491.97,491.52,513.01,-28.95,71872,24872,515.42,-23.45,72704,23672,0.024785,10079,9471,0.00090597,0.00086685],[10108,528.4,535.47,534.98,559.68,-31.28,74997,25491,561.94,-26.46,76030,24763,0.022808,10496,10030,0.0009092,0.00085903],[10109,729.52,738.84,738.68,785.33,-55.81,96373,30073,785.21,-46.37,97076,28432,0.027035,11970,11260,0.0009847,0.00088947],[10110,567.45,572.96,572.44,599.74,-32.29,89423,27085,598.91,-25.94,89949,25753,0.027098,12305,11631,0.00090329,0.00086269],[10111,399.66,406.3,406.08,425.83,-26.17,60943,23070,427.79,-21.49,61771,21911,0.022802,8817,8423,0.00097701,0.00091605],[10112,459.92,464.07,463.72,488.31,-28.39,65161,23644,486.24,-22.17,65701,22300,0.022948,8928,8478,0.00099533,0.00090862],[10113,430.04,436.54,436.38,455.48,-25.44,61929,21708,456.18,-19.64,62790,20343,0.023575,8921,8470,0.00095096,0.00090956],[10114,529.93,535.08,534.89,558.83,-28.9,81340,25877,558.96,-23.87,82135,24579,0.024635,11335,10756,0.00091737,0.00083332],[10115,656.25,663.16,663.42,692.08,-35.83,93308,29986,692.4,-29.24,94159,28540,0.025283,12003,11443,0.00093335,0.00089316],[10116,518.76,526.87,526.29,546.51,-27.75,74553,24344,549.64,-22.77,75365,23337,0.021426,9615,9154,0.00089272,0.0008462],[10117,406.29,413.05,412.61,430.75,-24.47,61255,22078,433.02,-19.97,62164,20894,0.022029,8661,8329,0.0009406,0.00087851],[10118,418.04,424.54,424.69,444.03,-25.99,61340,23040,445.84,-21.31,62261,21920,0.019844,8644,8270,0.00090666,0.00086331],[10119,409.56,416.96,416.78,436.52,-26.97,62644,22642,437.96,-21.0,63499,21587,0.021397,8660,8227,0.00093159,0.00087644],[10120,543.94,553.45,553.38,575.82,-31.89,83842,27218,579.02,-25.57,84473,25697,0.026069,11391,10858,0.00095888,0.00090989],[10121,528.75,536.7,536.34,559.91,-31.16,80399,26242,561.81,-25.11,81217,25202,0.025391,11136,10491,0.0009372,0.00085333],[10122,581.12,587.93,587.69,615.27,-34.15,86699,27768,614.95,-27.03,87701,25884,0.031277,11515,10859,0.00097792,0.0009448],[10123,499.6,506.72,506.81,529.22,-29.61,71622,25406,530.58,-23.86,72652,24285,0.021574,9502,9124,0.00090793,0.00087549],[10124,522.94,533.84,533.69,553.51,-30.57,74152,25973,558.5,-24.66,75112,24612,0.026915,10262,9769,0.00096301,0.00091448],[10125,449.95,455.32,455.3,477.82,-27.87,71315,24362,477.65,-22.33,72284,23038,0.026124,9810,9352,0.00097201,0.00090879],[10126,451.24,460.69,460.22,476.09,-24.85,65062,21240,481.21,-20.51,66048,20327,0.025957,9331,8729,0.00095937,0.00086303],[10127,490.14,495.77,495.68,518.54,-28.4,72818,24761,518.81,-23.04,73638,23522,0.023753,10402,9822,0.00093651,0.00086085],[10128,728.3,732.52,732.23,772.83,-44.53,97874,31300,769.39,-36.86,98183,29572,0.025757,12601,11956,0.00095887,0.00090827],[10129,528.98,535.31,534.98,559.99,-31.01,78132,25957,559.91,-24.6,78743,24589,0.024413,10505,10016,0.0009391,0.00088737],[10130,455.3,461.71,461.55,482.25,-26.95,68188,23342,483.33,-21.62,69080,22131,0.024459,9760,9252,0.00095565,0.00089631],[10131,490.8,499.68,499.3,518.75,-27.95,67240,23399,522.59,-22.91,68306,22362,0.023207,9359,8852,0.00095501,0.00087072],[10132,498.08,503.6,503.38,523.97,-25.89,65344,22883,525.56,-21.96,66056,21957,0.020853,9125,8674,0.00088901,0.00083221],[10133,625.56,631.51,631.47,656.61,-31.05,85626,27318,657.1,-25.59,86475,25991,0.023296,11362,10810,0.00089723,0.00084707],[10134,529.16,536.23,536.08,561.83,-32.67,77180,27098,562.46,-26.23,78212,25530,0.025971,10755,10250,0.00098839,0.00094516],[10135,454.05,459.54,459.1,481.88,-27.83,69749,24240,482.07,-22.53,70066,22997,0.021829,9913,9420,0.00095203,0.00087697],[10136,612.11,620.37,620.19,645.17,-33.06,90437,27311,647.01,-26.64,90948,25917,0.025613,12045,11448,0.00095458,0.00090365],[10137,615.86,622.65,622.32,648.73,-32.87,87061,27579,648.63,-25.98,87943,26091,0.024961,11138,10488,0.00090473,0.00084332],[10138,493.83,501.36,500.93,522.82,-28.99,67694,24339,524.73,-23.37,68392,23183,0.021629,9610,9187,0.00094813,0.00088438],[10139,461.71,467.56,467.44,488.33,-26.62,68194,22691,489.02,-21.45,69186,22078,0.023362,9348,8924,0.00092959,0.00088616],[10140,548.6,552.85,552.68,577.74,-29.14,79656,25653,576.4,-23.55,79960,24332,0.019986,10626,10116,0.00089054,0.00080092],[10141,561.32,580.66,580.5,611.66,-50.34,78715,25630,613.57,-32.9,79718,24308,0.054299,10570,9953,0.00093663,0.00087337],[10142,620.22,628.24,627.66,656.85,-36.63,92803,29638,657.0,-28.75,93781,28066,0.026594,11981,11394,0.00092439,0.00085558],[10143,464.84,471.45,471.28,490.64,-25.8,65090,22303,492.0,-20.55,66036,21128,0.020845,8747,8333,0.00094353,0.00085365],[10144,434.17,440.81,440.48,460.1,-25.94,66552,22819,462.01,-21.2,67260,21702,0.02284,9491,9013,0.00091449,0.00086867],[10145,475.89,481.6,481.29,502.74,-26.84,66971,23209,503.6,-21.99,68117,22496,0.021597,9633,9192,0.00090983,0.00085952],[10146,723.56,765.8,766.39,1021.96,-298.4,85470,29504,1030.4,-264.6,87526,28423,0.21576,11307,10725,0.00098001,0.000918],[10147,463.66,469.59,469.26,491.31,-27.65,68725,23967,491.66,-22.06,69302,22773,0.021985,9633,9124,0.00091537,0.00085287],[10148,685.9,692.34,692.06,722.01,-36.11,89597,28529,720.95,-28.61,90018,27080,0.023072,11064,10521,0.00092611,0.00087428],[10149,515.22,523.63,523.25,550.38,-35.16,76874,27175,552.5,-28.87,77921,25709,0.027104,10653,10144,0.001006,0.00095988],[10150,579.73,589.25,589.0,611.91,-32.18,83584,26993,615.02,-25.77,84704,25602,0.028481,11305,10560,0.00095734,0.00087457],[10151,468.52,474.55,474.41,495.97,-27.45,69258,23332,495.79,-21.24,69776,22187,0.022959,9805,9297,0.00091521,0.00081742],[10152,411.08,418.11,418.15,435.72,-24.65,60547,22325,438.22,-20.11,61648,21430,0.02027,8590,8216,0.00088505,0.0008157],[10153,550.59,555.95,555.81,580.42,-29.84,81209,25825,579.67,-23.73,82126,24365,0.025684,11200,10557,0.00091512,0.00083446],[10154,485.71,490.95,490.83,512.3,-26.59,71927,23116,512.0,-21.05,72439,22046,0.020813,10098,9620,0.00088672,0.00083711],[10155,470.89,478.57,478.41,496.01,-25.12,68709,22218,499.14,-20.57,69514,21128,0.022476,9940,9443,0.00091592,0.00084377],[10156,527.18,534.11,533.88,563.69,-36.5,69142,23962,565.41,-31.31,69940,22959,0.022524,9790,9307,0.00090568,0.0008795],[10157,529.93,537.99,537.97,556.4,-26.48,75523,23821,559.43,-21.44,76480,22668,0.022179,9948,9451,0.00092453,0.0008111],[10158,431.84,437.87,437.45,458.37,-26.53,61922,23244,459.5,-21.63,62659,22145,0.019902,8548,8207,0.00093086,0.00088433],[10159,431.03,439.39,439.1,458.04,-27.01,63692,23480,461.21,-21.82,64757,22390,0.023815,9254,8841,0.0009664,0.00090443],[10160,417.44,422.61,422.32,443.81,-26.37,61930,23188,443.91,-21.3,62740,22033,0.022621,8753,8267,0.00095039,0.00084778],[10161,451.56,458.62,458.53,479.4,-27.84,66226,23999,481.19,-22.57,66905,23046,0.021904,9300,8873,0.00093236,0.00086739],[10162,714.26,721.72,721.18,750.27,-36.01,99306,29715,750.71,-28.99,99413,28286,0.022526,12163,11544,0.00091531,0.0008534],[10163,661.87,669.13,668.75,698.07,-36.2,96084,30071,698.12,-28.98,96493,28435,0.026501,12360,11715,0.00090441,0.00087447],[10164,654.73,684.24,683.89,801.33,-146.6,83927,28723,797.9,-113.65,84637,27141,0.037997,10997,10361,0.00094438,0.00088243],[10165,434.48,441.79,441.81,460.8,-26.32,68420,22928,463.38,-21.59,69229,21618,0.025013,9842,9346,0.0009727,0.00093774],[10166,413.61,419.53,419.38,438.7,-25.09,59174,21742,439.55,-20.01,60231,20326,0.024591,8570,8094,0.001006,0.00091549],[10167,488.23,494.24,494.02,517.83,-29.6,67739,23518,518.32,-24.08,68556,22548,0.021508,9805,9382,0.0009389,0.00087946],[10168,618.46,627.25,627.15,740.78,-122.32,71173,26142,743.48,-116.23,72373,25180,0.025397,9713,9262,0.0010008,0.00092591],[10169,565.62,572.89,572.55,595.25,-29.63,85033,26111,596.63,-23.74,86228,24857,0.024527,11048,10437,0.00088713,0.00081322],[10170,383.37,389.7,389.15,408.08,-24.72,62781,21699,409.69,-19.99,63583,20750,0.022638,9251,8759,0.00093472,0.00086463],[10171,562.47,568.42,567.92,593.26,-30.79,73349,25589,592.95,-24.53,73966,24505,0.021146,9900,9469,0.00088695,0.00084589],[10172,678.5,686.93,686.5,716.73,-38.22,94818,29647,718.27,-31.33,96023,27825,0.028588,11932,11257,0.0010037,0.00094622],[10173,392.37,398.48,398.25,414.89,-22.52,56118,20065,416.84,-18.36,57173,19102,0.020565,8381,8082,0.00095367,0.00089388],[10174,535.24,544.06,543.87,566.26,-31.02,83129,26661,569.17,-25.1,84197,25323,0.025222,11317,10711,0.00091803,0.00086744],[10175,499.75,505.17,504.73,527.27,-27.52,72658,24013,527.58,-22.41,73422,22900,0.020826,9809,9365,0.00089907,0.0008408],[10176,440.13,449.16,448.57,466.54,-26.41,67036,23269,470.67,-21.52,68040,22221,0.021909,9410,8942,0.00089849,0.00083173],[10177,623.25,656.15,655.39,721.57,-98.31,83289,27371,723.55,-67.4,84008,25568,0.033829,11072,10546,0.00099778,0.00091826],[10178,656.17,664.2,664.24,693.11,-36.94,91460,28558,693.63,-29.43,92440,26773,0.028452,11404,10704,0.0010051,0.00095161],[10179,375.85,382.43,382.08,401.01,-25.16,57407,21604,402.56,-20.13,58041,20552,0.023094,8427,8028,0.0009954,0.00094177],[10180,577.17,585.73,585.61,612.13,-34.97,82446,28355,613.74,-28.01,82864,27033,0.026624,10989,10403,0.00099038,0.00090802],[10181,456.65,463.99,463.51,484.51,-27.86,70087,24125,486.58,-22.59,71360,23215,0.026986,10068,9556,0.00096752,0.00092649],[10182,570.09,575.18,574.85,602.44,-32.35,84544,27754,601.24,-26.07,85534,26443,0.023624,10978,10416,0.00094287,0.00087202],[10183,624.42,633.11,632.89,662.09,-37.67,85996,28308,664.2,-31.09,86637,26556,0.027054,11386,10757,0.00099786,0.0009304],[10184,513.95,522.57,521.98,551.86,-37.91,65749,23976,554.69,-32.11,66434,22992,0.022566,9177,8711,0.00093262,0.00084941],[10185,536.63,545.63,545.43,572.9,-36.27,77289,26070,575.64,-30.01,78506,24521,0.027714,10667,10171,0.00099125,0.00095144],[10186,567.49,575.46,575.19,599.28,-31.79,72202,25850,601.64,-26.18,73216,24723,0.02563,10097,9603,0.00098621,0.00094122],[10187,544.48,551.66,551.67,584.75,-40.27,75921,24543,587.26,-35.61,76598,23535,0.020819,10088,9583,0.00091082,0.0008167],[10188,524.9,533.39,533.03,556.99,-32.09,79030,26082,557.75,-24.36,79828,24325,0.024786,10601,10094,0.00096596,0.00090796],[10189,707.55,717.58,717.54,748.5,-40.95,94428,29910,749.16,-31.58,94952,28258,0.029668,12292,11608,0.00095777,0.00090982],[10190,654.54,661.69,661.29,690.23,-35.69,86017,27725,691.01,-29.32,86596,26388,0.023596,11339,10875,0.0009613,0.00093454],[10191,657.36,662.47,662.35,696.34,-38.98,88715,27315,694.8,-32.33,89216,26096,0.025246,11664,11062,0.00088444,0.00085095],[10192,659.05,665.83,665.5,694.6,-35.56,92386,28402,693.7,-27.88,93254,26497,0.028265,11992,11428,0.00097908,0.00095356],[10193,576.05,583.34,582.82,607.55,-31.5,85286,27487,608.68,-25.34,86070,26115,0.024523,11683,11018,0.0008951,0.00082562],[10194,504.62,512.13,511.83,536.27,-31.64,80300,26651,537.52,-25.39,80970,25248,0.025355,10928,10389,0.0010004,0.00092537],[10195,546.93,554.51,554.5,578.47,-31.54,80525,26484,580.03,-25.52,81177,25365,0.024408,11098,10485,0.00091881,0.0008566],[10196,579.06,587.12,586.95,614.16,-35.11,86063,28107,614.75,-27.63,86663,26572,0.028353,11728,11121,0.00098882,0.00094205],[10197,436.09,443.35,442.71,462.02,-25.93,64115,23204,464.4,-21.05,65132,21998,0.024368,8819,8327,0.00096918,0.00086156],[10198,551.06,558.38,558.16,584.38,-33.33,74391,25901,585.82,-27.43,75028,24608,0.022536,10547,10001,0.00092676,0.00086664],[10199,478.38,483.71,483.3,511.36,-32.97,63430,22692,511.41,-27.71,64112,21491,0.022099,8876,8437,0.00095967,0.00087134],[10200,555.32,563.07,562.68,586.13,-30.81,82015,26142,588.21,-25.14,82791,24875,0.024081,11057,10523,0.00093886,0.0008827],[10201,475.53,482.42,482.08,501.94,-26.41,74065,23481,503.46,-21.04,74914,22273,0.022639,10094,9569,0.00090315,0.00084042],[10202,560.71,570.12,569.8,592.71,-32.0,80309,25584,596.3,-26.18,81157,24139,0.026852,10683,10133,0.00099347,0.00089453],[10203,612.4,618.45,618.14,646.12,-33.72,86599,28164,646.18,-27.72,87694,27106,0.025083,11160,10605,0.00092824,0.00086034],[10204,450.19,456.7,456.29,478.59,-28.4,66951,24249,479.65,-22.95,67521,23083,0.022145,9482,8972,0.00092363,0.00083462],[10205,414.1,420.64,420.39,438.18,-24.09,63981,21978,440.52,-19.88,64879,20970,0.022618,9650,9171,0.00091846,0.00084258],[10206,516.05,523.62,523.41,544.74,-28.7,77972,24739,546.24,-22.62,78877,23134,0.026725,10417,9798,0.00096044,0.00087001],[10207,632.56,637.32,637.15,668.73,-36.17,88537,29472,666.88,-29.56,88922,27905,0.024643,11454,10888,0.00099802,0.00090455],[10208,621.1,629.59,629.34,701.31,-80.21,69377,25064,702.62,-73.04,70364,23760,0.02379,9482,9023,0.00094294,0.00085549],[10209,546.99,554.05,553.7,578.72,-31.73,73451,24909,580.35,-26.3,74509,23714,0.024563,9802,9300,0.00099085,0.00092651],[10210,421.68,427.15,426.62,445.91,-24.23,63133,21686,446.54,-19.39,63717,20522,0.019619,8719,8314,0.00092659,0.00082542],[10211,433.52,441.71,441.34,457.88,-24.35,62013,21535,461.14,-19.44,63043,20305,0.023648,9111,8670,0.00092639,0.00086999],[10212,619.58,630.23,630.0,654.25,-34.68,89315,28519,657.75,-27.52,90158,26897,0.026913,11480,10868,0.00099932,0.00094175],[10213,574.88,583.88,583.33,606.39,-31.51,83848,26837,609.32,-25.44,84551,25221,0.028303,11568,10964,0.00097852,0.00091616],[10214,570.94,578.58,578.3,603.81,-32.87,90882,27933,605.26,-26.67,91529,26328,0.02817,11910,11268,0.00097791,0.00090081],[10215,453.37,457.42,457.17,480.94,-27.57,64769,23386,479.55,-22.14,65391,22097,0.02305,9616,9154,0.00095869,0.00091406],[10216,447.16,454.86,454.46,474.22,-27.06,59797,22551,476.58,-21.72,60782,21466,0.021291,8503,8120,0.0010014,0.00089616],[10217,661.41,668.57,668.37,700.53,-39.13,92856,30742,699.62,-31.05,93439,28923,0.031097,11977,11316,0.0010043,0.00096245],[10218,626.37,633.67,633.62,661.37,-35.01,89367,28790,661.31,-27.64,90200,27477,0.024071,12135,11518,0.00090279,0.00083829],[10219,517.33,524.93,524.57,549.56,-32.23,82982,26464,549.81,-24.87,83956,24905,0.027287,11214,10554,0.00094435,0.00088509],[10220,511.3,518.44,517.79,549.64,-38.35,62558,23321,551.0,-32.56,63406,21918,0.023113,8574,8165,0.00099298,0.00093703],[10221,530.38,536.97,536.61,566.3,-35.92,66238,25225,567.11,-30.13,66804,24014,0.022854,9109,8585,0.00097596,0.00090751],[10222,613.64,621.73,621.41,647.35,-33.71,82224,27751,648.8,-27.07,83210,26170,0.025351,10592,10131,0.0010062,0.00095447],[10223,655.51,664.05,663.6,692.99,-37.48,85574,27976,695.75,-31.71,86476,26605,0.027366,11806,11215,0.00093075,0.0008767],[10224,430.3,436.89,436.37,456.64,-26.34,64462,21419,459.02,-22.13,65275,20353,0.023718,9374,8872,0.00096132,0.00086239],[10225,477.18,484.1,483.72,504.34,-27.16,72142,24030,506.79,-22.69,73050,23003,0.022674,10421,9919,0.00092416,0.00085254],[10226,702.61,707.78,707.65,737.97,-35.37,92367,28762,737.49,-29.71,92627,27723,0.022683,11538,10863,0.00088738,0.00081646],[10227,439.46,446.77,446.14,464.0,-24.54,63842,21795,466.57,-19.8,64909,20658,0.022357,9053,8679,0.00092821,0.00086067],[10228,534.36,542.26,542.24,564.88,-30.52,82629,25741,566.21,-23.95,83536,24072,0.028082,11322,10719,0.00095309,0.00088355],[10229,425.66,433.69,433.57,450.38,-24.72,69297,22546,454.29,-20.61,70287,21562,0.023638,9952,9399,0.00091183,0.00084967],[10230,624.14,633.96,633.73,660.33,-36.2,92807,29201,662.56,-28.61,93846,27758,0.029253,11717,11013,0.0010078,0.00093625],[10231,688.32,696.75,696.23,725.16,-36.84,89896,29533,726.7,-29.95,90644,28098,0.025421,11766,11236,0.000974,0.00093221],[10232,496.94,502.62,502.17,525.04,-28.09,71440,23958,525.77,-23.15,72287,22900,0.026357,10094,9504,0.00099578,0.00091702],[10233,442.95,448.73,448.48,469.54,-26.59,67184,23466,470.4,-21.67,67778,22529,0.019446,9277,8857,0.00089905,0.00081349],[10234,532.47,539.9,539.64,563.84,-31.36,73520,25358,566.19,-26.3,74716,24415,0.024474,10171,9670,0.00096177,0.00089149],[10235,657.63,663.13,662.75,694.13,-36.5,84443,27349,693.17,-30.04,85025,25803,0.024525,10579,10040,0.00094876,0.00089531],[10236,439.14,445.66,445.26,464.81,-25.67,69273,22603,466.34,-20.69,70214,21228,0.02683,9940,9376,0.00096664,0.00087895],[10237,638.58,645.7,645.57,673.76,-35.18,86690,29002,673.9,-28.19,87370,27179,0.025666,11534,10934,0.00099894,0.00089748],[10238,447.96,454.82,454.4,479.63,-31.68,58049,23024,481.58,-26.76,58866,21768,0.022667,8531,8176,0.0010056,0.00091485],[10239,594.95,603.9,603.5,628.4,-33.45,82495,27735,631.29,-27.4,83417,26226,0.028955,11248,10656,0.00098641,0.00092022],[10240,594.33,603.95,603.87,636.38,-42.05,82660,26717,639.54,-35.59,83501,25212,0.03097,11215,10521,0.00099288,0.00091675],[10241,401.11,406.79,406.39,425.74,-24.63,59580,20881,427.62,-20.83,60365,19996,0.022435,8787,8324,0.00091715,0.00086254],[10242,419.07,425.49,425.23,443.33,-24.26,59054,20763,444.77,-19.27,59468,19573,0.020482,8750,8343,0.00091057,0.00087227],[10243,614.26,621.37,621.25,686.06,-71.8,72955,26040,687.7,-66.33,73658,24734,0.021233,9893,9490,0.00093584,0.00088165],[10244,434.68,440.85,441.09,460.72,-26.04,63880,22823,462.19,-21.34,64503,21798,0.020891,9396,8992,0.00092863,0.00085904],[10245,592.28,600.11,599.86,625.34,-33.07,83072,26997,626.35,-26.24,84023,25643,0.028534,11053,10401,0.00097946,0.00092348],[10246,556.62,563.34,562.94,589.21,-32.59,82394,27014,588.9,-25.56,83033,25591,0.024322,11289,10750,0.00094013,0.00087201],[10247,495.81,504.92,504.4,526.27,-30.47,76500,25532,528.63,-23.71,77279,23846,0.028093,10510,9882,0.0010047,0.00089405],[10248,490.8,499.5,499.22,520.12,-29.32,78547,25153,522.88,-23.38,79586,23742,0.028248,10548,10011,0.00098479,0.00093842],[10249,529.77,536.98,536.85,559.43,-29.66,76811,25666,561.25,-24.28,77632,24632,0.020962,10583,10122,0.00089194,0.00083185],[10250,400.69,407.05,406.47,424.13,-23.44,60676,20943,426.17,-19.12,61404,19933,0.021041,9061,8645,0.00091779,0.00082867],[10251,380.21,386.21,385.81,404.85,-24.64,59001,21823,406.05,-19.84,59864,20962,0.021387,8881,8484,0.00095276,0.0008721],[10252,393.67,399.77,399.42,418.05,-24.38,59093,21084,419.62,-19.85,60196,20226,0.023489,8550,8182,0.00097186,0.00093323],[10253,574.61,581.53,581.33,605.76,-31.16,88636,27138,606.78,-25.25,89487,25797,0.025348,11963,11350,0.00088565,0.0008386],[10254,493.5,502.47,502.64,523.23,-29.73,65653,24742,527.21,-24.74,66521,23957,0.022129,9014,8625,0.00097372,0.00092227],[10255,596.49,601.81,601.66,628.02,-31.53,86440,27452,627.8,-25.99,87228,26136,0.023874,11348,10849,0.00091609,0.00085698]]},"harness_changes":"Replica unmodified. Arm wrapper ignores init(sigma,lam,size) and passes only (is_buy,ax,ay,t,x,y) to MixFilter; p,s2,arb used only for logging and oracle/diag arms. Fees written back to filter are the table fees (inside [0,0.1] so identical to replica clamp).","tests":{"command":". scratch/env.sh && python scratch/test_mf.py","result":"ALL TESTS PASS","covers":"hidden-input isolation (signatures; filter-mode fees invariant to oracle p), arb pin signs both sides, repeated same-step callbacks do not diffuse, t=0 first callback, gap recomputation from saved per-seed records"},"runtime_s":{"eval_seg_A":296.7,"eval_seg_B":291.2,"ablation":78.8,"cores":16},"port_cost_estimate":"State: 4x(w,m,v) + sigma sums + last pin + tlast/fees ~ 20 slots. Per callback: per silent step 4 truncations (erfc + exp each) plus a pairwise merge over <=5 comps (10 pairs). Silent-step loops unbounded in gap length -> needs a cap (e.g. collapse after 8 steps). Rough guess 60-150k gas with fixed-point erfc/exp approximations; not measured.","dead_ends":["Router likelihood R=30bps, bias 8bps (rival pushed by its own fill): train 0..3 passive RMS 19.9 bps vs 14.4 with router off; closed-loop gap on train 0..31 was 38.1 (se 2.3) vs 8.2 after switching to R=80, bias 0.","retail_first_prob 0.02 / 2.0 / 0.12 / 0.5 (router off): passive RMS 24.5 / 32.3 / 15.6 / 16.3 bps vs 14.4 at 0.25 (seeds 0..3).","vmin 1e-9 vs 1e-12: no change (19.91 vs 19.92 bps)."],"limitations":["Arb/retail classification on first callback only ~90% accurate (oracle-arm confusion seeds 0..3 with router R30: TP 11014, TN 10899, FP 1712, FN 3870); this is the main error source: diag arm (true p, inferred flag) loses only ~0.2-0.3, so almost all of the 7.7 gap is p-estimate error.","Truncation is moment-matched to a single Gaussian per component (no splitting); merge error logged per run but not reported per seed.","Retail likelihood is a crude lognormal in Y of 2x the fill; router split total order is not marginalised exactly; rival state not modelled beyond a Gaussian band.","Replica only; levels differ from engine ~1%; no engine, no Solidity, no gas measured.","Sigma estimate is biased by selection (pins only when classified arb, dt<=50) - acknowledged, not corrected."],"source":{"mixfilt.py":"\"\"\"Small Gaussian-mixture posterior of z=ln(p/spot) for the AMM fee challenge replica.\nStrategy-visible inputs only: init reserves, and per callback (side, amounts, t, post-reserves)\nplus its own stored fees/history. Oracle p / s2 / arb are used only for evaluation.\"\"\"\nimport math, json, sys, os\nsys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))\nimport replica\n\nTAB = json.load(open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'oracle_table.json')))\nKN = [i * 0.003 for i in range(-8, 9)]\nSQ2 = math.sqrt(2.0); SQ2PI = math.sqrt(2 * math.pi)\nPARAMS = dict(ncomp=4, sigma0=0.000945, sigma_prior_n=20.0, R_router_bps=80.0, router_bias_bps=0.0,\n              retail_first_prob=0.25, retail_size_mean=20.0, vmin=1e-12, router=True)\n\n\ndef interp(d, arr):\n    x = d / 0.003\n    if x <= -8: return arr[0]\n    if x >= 8: return arr[-1]\n    i = int(math.floor(x + 8)); i = min(i, 15); f = x + 8 - i\n    return arr[i] * (1 - f) + arr[i + 1] * f\n\n\ndef table_fees(spot, p, flag):\n    d = math.log(spot / p)\n    a = interp(d, TAB['ask']) + (TAB['arb_flag'] if flag else 0.0)\n    b = interp(d, TAB['bid']) + (TAB['arb_flag'] if flag else 0.0)\n    fa = 1 - math.exp(d - a * 0.003); fb = 1 - math.exp(-b * 0.003 - d)\n    return min(max(fb, 0.0), 0.1), min(max(fa, 0.0), 0.1)\n\n\ndef Phi(x): return 0.5 * math.erfc(-x / SQ2)\ndef phi(x): return math.exp(-0.5 * x * x) / SQ2PI\n\n\ndef trunc(m, v, lo, hi):\n    \"\"\"Gaussian N(m,v) truncated to [lo,hi]: returns (mass, mean, var) moment-matched.\"\"\"\n    s = math.sqrt(v)\n    a = (lo - m) / s; b = (hi - m) / s\n    Z = Phi(b) - Phi(a)\n    if Z < 1e-300:\n        # all mass outside: collapse to nearest edge\n        e = lo if m < lo else hi\n        return 0.0, e, v * 1e-4\n    pa, pb = phi(a), phi(b)\n    mu = m + s * (pa - pb) / Z\n    var = v * (1 + (a * pa - b * pb) / Z - ((pa - pb) / Z) ** 2)\n    return Z, mu, max(var, 1e-14)\n\n\nclass MixFilter:\n    def __init__(self, **kw):\n        self.P = dict(PARAMS); self.P.update(kw)\n\n    # --- strategy interface (inputs: own visible data only)\n    def init(self, x, y):\n        self.x, self.y = x, y\n        self.comps = [(1.0, 0.0, 1e-14)]  # z at t=-1: start p=spot exactly is public engine semantics\n        self.tlast = -1          # steps <= tlast fully accounted (including arb phase)\n        self.tcur = None         # step whose arb phase has been resolved by a first callback\n        self.fb = self.fa = 0.003\n        self.flag = False\n        self.ssum = 0.0; self.scnt = 0.0\n        self.last_pin = None     # (t, ln p)\n        self.merge_err = 0.0; self.prune_mass = 0.0\n        self.parb_last = 0.0\n        return self.fb, self.fa\n\n    def sigma2(self):\n        n0 = self.P['sigma_prior_n']; s0 = self.P['sigma0']\n        return (n0 * s0 * s0 + self.ssum) / (n0 + self.scnt)\n\n    def _diffuse(self):\n        s2 = self.sigma2()\n        self.comps = [(w, m - 0.5 * s2, v + s2) for (w, m, v) in self.comps]  # GBM drift -s2/2 on ln p\n\n    def _band(self):\n        return math.log(1 - self.fb), -math.log(1 - self.fa)\n\n    def _truncate(self):\n        lo, hi = self._band()\n        out = []\n        for (w, m, v) in self.comps:\n            Z, mu, var = trunc(m, v, lo, hi)\n            if w * Z > 0: out.append((w * Z, mu, var))\n        tot = sum(c[0] for c in out)\n        if tot <= 0:\n            mm = sum(w * m for w, m, v in self.comps) / sum(w for w, m, v in self.comps)\n            out = [(1.0, min(max(mm, lo), hi), 1e-8)]; tot = 1.0\n        self.comps = [(w / tot, m, v) for (w, m, v) in out]\n        return tot\n\n    def _shift(self, dz):\n        self.comps = [(w, m + dz, v) for (w, m, v) in self.comps]\n\n    def _reduce(self):\n        K = self.P['ncomp']\n        c = [x for x in self.comps if x[0] > 1e-9]\n        self.prune_mass += sum(x[0] for x in self.comps if x[0] <= 1e-9)\n        tot = sum(x[0] for x in c); c = [(w / tot, m, v) for w, m, v in c]\n        while len(c) > K:\n            best = None\n            for i in range(len(c)):\n                for j in range(i + 1, len(c)):\n                    wi, mi, vi = c[i]; wj, mj, vj = c[j]\n                    cost = wi * wj / (wi + wj) * (mi - mj) ** 2\n                    if best is None or cost < best[0]: best = (cost, i, j)\n            cost, i, j = best\n            wi, mi, vi = c[i]; wj, mj, vj = c[j]; w = wi + wj\n            m = (wi * mi + wj * mj) / w\n            v = (wi * (vi + (mi - m) ** 2) + wj * (vj + (mj - m) ** 2)) / w\n            self.merge_err += cost\n            c = [c[k] for k in range(len(c)) if k not in (i, j)] + [(w, m, v)]\n        self.comps = c\n\n    def mean_sd(self):\n        m = sum(w * mm for w, mm, v in self.comps)\n        v = sum(w * (vv + (mm - m) ** 2) for w, mm, vv in self.comps)\n        return m, math.sqrt(max(v, 0.0))\n\n    def _pdf(self, z):\n        return sum(w * math.exp(-0.5 * (z - m) ** 2 / v) / math.sqrt(2 * math.pi * v) for w, m, v in self.comps)\n\n    def _retail_size_pdf(self, Y):\n        mu = math.log(self.P['retail_size_mean']) - 0.72; s = 1.2\n        # our share of a routed order: unknown split, take lognormal of full size scaled by 0.5\n        Yf = 2.0 * Y\n        return 2.0 * math.exp(-0.5 * ((math.log(Yf) - mu) / s) ** 2) / (Yf * s * SQ2PI)\n\n    def _router(self, is_buy):\n        \"\"\"Weak observation: interior split equalises marginal prices; the rival (30 bps) sits\n        near p only right after its arb phase, then drifts with its own fills (bias toward the trade).\"\"\"\n        if not self.P['router']: return\n        R = (self.P['R_router_bps'] * 1e-4) ** 2; bias = self.P['router_bias_bps'] * 1e-4\n        g = 0.997\n        if is_buy:   # trader sold X to us: our bid s*(1-fb) == rival bid s2*g; s2 above p? no: rival also took X -> s2 below p\n            zobs = math.log((1 - self.fb_old) / g) + bias\n        else:        # trader bought X: our ask s/(1-fa) == rival ask s2/g -> s2 = s*g/(1-fa), rival pushed up\n            zobs = math.log(g / (1 - self.fa_old)) - bias\n        out = []\n        for w, m, v in self.comps:\n            S = v + R\n            lw = -0.5 * (zobs - m) ** 2 / S - 0.5 * math.log(S)\n            k = v / S\n            out.append((w, lw, m + k * (zobs - m), v * (1 - k)))\n        mx = max(o[1] for o in out)\n        ws = [o[0] * math.exp(o[1] - mx) for o in out]; t = sum(ws)\n        self.comps = [(ws[i] / t, out[i][2], out[i][3]) for i in range(len(out))]\n\n    def on_trade(self, is_buy, ax, ay, t, x, y):\n        \"\"\"is_buy: AMM buys X (trader sold X). ax, ay: X and Y amounts. x, y post-reserves.\"\"\"\n        sb = self.y / self.x; sa = y / x\n        self.fb_old, self.fa_old = self.fb, self.fa\n        arb_flag = False\n        if t != self.tcur:\n            # fully silent steps tlast+1 .. t-1\n            for _ in range(self.tlast + 1, t):\n                self._diffuse(); self._truncate()\n            self._diffuse()\n            # first callback at t: latent arb vs retail (arb phase silent)\n            if is_buy:  # AMM bought X: arb would sell -> pin p = sa*(1-fb)\n                zpin = math.log(sa * (1 - self.fb) / sb)\n                dzdY = 2.0 / y        # |d ln s_after / d yout|\n            else:\n                zpin = math.log(sa / (1 - self.fa) / sb)\n                dzdY = 2.0 * (1 - self.fa) / y\n            lo, hi = self._band()\n            outside = zpin < lo - 1e-12 or zpin > hi + 1e-12\n            dens_arb = self._pdf(zpin) * dzdY if outside else 0.0\n            prior = list(self.comps)\n            pin_mass = self._truncate()\n            dens_ret = pin_mass * self.P['retail_first_prob'] * self._retail_size_pdf(ay)\n            pa = dens_arb / (dens_arb + dens_ret) if dens_arb + dens_ret > 0 else 0.0\n            self.parb_last = pa\n            if pa > 0.5: arb_flag = True\n            # mixture: arb branch (pinned, in post-trade frame) + retail branch\n            ret = [(w * (1 - pa), m, v) for w, m, v in self.comps]\n            self.comps = ret\n            self._shift(-math.log(sa / sb))\n            if pa < 1.0 and self.P['router'] and (1 - pa) > 1e-6:\n                wsum = sum(w for w, m, v in self.comps)\n                self.comps = [(w / wsum, m, v) for w, m, v in self.comps]\n                self._router(is_buy)\n                self.comps = [(w * (1 - pa), m, v) for w, m, v in self.comps]\n            zp_post = zpin - math.log(sa / sb)\n            if pa > 0: self.comps.append((pa, zp_post, self.P['vmin']))\n            # sigma from arb-to-arb moves (only confident pins)\n            if pa > 0.9:\n                lp = math.log(sa) + zp_post\n                if self.last_pin is not None:\n                    dt = t - self.last_pin[0]\n                    if 0 < dt <= 50:\n                        self.ssum += (lp - self.last_pin[1]) ** 2 / dt * 1.0; self.scnt += 1.0\n                self.last_pin = (t, lp)\n            self.tcur = t; self.tlast = t\n        else:\n            # later callback same step: retail\n            self._shift(-math.log(sa / sb))\n            self._router(is_buy)\n            self.parb_last = 0.0\n        self._reduce()\n        self.x, self.y = x, y\n        self.flag = arb_flag\n        return arb_flag\n\n\nclass Arm:\n    \"\"\"mode: 'filter' (p_hat, inferred flag), 'oracle' (true p, true flag), 'diag' (true p, inferred flag).\"\"\"\n    def __init__(self, mode, **kw):\n        self.mode = mode; self.kw = kw\n\n    def init(self, sigma, lam, size):  # hidden values deliberately ignored\n        self.F = MixFilter(**self.kw)\n        self.F.init(100.0, 10000.0)\n        self.se = 0.0; self.n = 0; self.cov = 0; self.flag_ok = 0\n        return 0.003, 0.003\n\n    def on_trade(self, is_buy, ax, ay, t, x, y, arb, p, s2):\n        F = self.F\n        flag = F.on_trade(is_buy, ax, ay, t, x, y)\n        spot = y / x\n        m, sd = F.mean_sd()\n        zt = math.log(p / spot)\n        e = m - zt\n        self.se += e * e; self.n += 1\n        if abs(e) <= 1.96 * sd + 1e-9: self.cov += 1\n        if flag == arb: self.flag_ok += 1\n        if self.mode == 'filter': ph, fl = spot * math.exp(m), flag\n        elif self.mode == 'oracle': ph, fl = p, arb\n        else: ph, fl = p, flag\n        fb, fa = table_fees(spot, ph, fl)\n        F.fb, F.fa = fb, fa  # stored fees (after replica clamp, identical since clamp in [0,.1])\n        return fb, fa\n\n\ndef run_seed(args):\n    seed, mode, kw = args\n    a = Arm(mode, **kw)\n    r = replica.run(seed, a)\n    return dict(seed=seed, mode=mode, edge=r['edge'], retail=r['retail'], arb=r['arb'], rv=r['rv'], av=r['av'],\n                se=a.se, n=a.n, cov=a.cov, flag_ok=a.flag_ok, merge_err=a.F.merge_err,\n                sig_hat=math.sqrt(a.F.sigma2()), sig=r['sigma'])\n","runeval.py":"import sys,json,os,time\nsys.path.insert(0,os.path.dirname(os.path.abspath(__file__)))\nfrom multiprocessing import Pool\nimport mixfilt\na,b=int(sys.argv[1]),int(sys.argv[2]); modes=sys.argv[3].split(','); kw=json.loads(sys.argv[4]) if len(sys.argv)>4 else {}\nout=sys.argv[5] if len(sys.argv)>5 else None\nt=time.time()\nwith Pool(16) as P: R=P.map(mixfilt.run_seed,[(s,m,kw) for s in range(a,b) for m in modes])\nimport statistics as st,math\nfor m in modes:\n  r=[x for x in R if x['mode']==m]\n  print(m,len(r),'edge %.2f'%st.mean(x['edge'] for x in r),'rms %.1f'%(1e4*math.sqrt(sum(x['se'] for x in r)/sum(x['n'] for x in r))),'cov %.3f'%(sum(x['cov'] for x in r)/sum(x['n'] for x in r)),'flag %.4f'%(sum(x['flag_ok'] for x in r)/sum(x['n'] for x in r)))\nif 'oracle' in modes and 'filter' in modes:\n  o={x['seed']:x['edge'] for x in R if x['mode']=='oracle'}; d=[o[x['seed']]-x['edge'] for x in R if x['mode']=='filter']\n  print('gap %.3f se %.3f'%(st.mean(d),st.stdev(d)/math.sqrt(len(d))))\nprint('time',time.time()-t)\nif out: json.dump(R,open(out,'w'))\n","test_mf.py":"import sys,math,inspect,json;sys.path.insert(0,'scratch');import mixfilt as M\n# 1 isolation: filter API has no p/s2/arb/sigma/lam/size inputs\na=inspect.signature(M.MixFilter.on_trade).parameters; assert not set(a)&{'p','s2','arb','sigma','lam','size'},a\nassert set(inspect.signature(M.MixFilter.init).parameters)=={'self','x','y'}\n# filter-mode fees invariant to oracle p (only logging uses it)\ndef fees(pmul):\n  A=M.Arm('filter');A.init(0,0,0);out=[]\n  for t,(ib,ax,ay,x,y) in enumerate([(False,0.1,10.0,99.9,10010.0),(True,0.1,10.0,100.0,10000.0)]):\n    out.append(A.on_trade(ib,ax,ay,t*3,x,y,False,100*pmul,100))\n  return out\nassert fees(1.0)==fees(1.3)\n# 2 signs: AMM sells X (spot up) arb pin p = s_after/(1-fa) > s_after ; AMM buys X pin below\nF=M.MixFilter();F.init(100,10000);F.fa=F.fb=0.003\ny=math.sqrt(1e6*100.3);F.on_trade(False,100-1e6/y,y-1e4,50,1e6/y,y)\npin=[c for c in F.comps if c[2]<1e-10]; assert pin and abs(pin[0][1]+math.log(1-0.003))<1e-9, F.comps\nF=M.MixFilter();F.init(100,10000);F.fa=F.fb=0.003\ny=math.sqrt(1e6*99.7);F.on_trade(True,1e6/y-100,1e4-y,50,1e6/y,y); pin=[c for c in F.comps if c[2]<1e-10]; assert pin and abs(pin[0][1]-math.log(1-0.003))<1e-9, F.comps\n# 3 repeated callbacks at same t: no extra diffusion\nF=M.MixFilter();F.init(100,10000);F.on_trade(False,0.01,1.0,3,99.99,10001.0)\nv1=sum(w*v for w,m,v in F.comps); tl=F.tlast\nF.on_trade(False,0.01,1.0,3,99.98,10002.0); assert F.tlast==tl and sum(w*v for w,m,v in F.comps)<=v1*1.0001+1e-12\n# t=0 handled: first callback at t=0 diffuses once from exact z=0\nF=M.MixFilter();F.init(100,10000);F.on_trade(False,0.01,1.0,0,99.99,10001.0);assert F.tlast==0\n# 4 gap propagation: gap = oracle - filter per seed recomputed from saved files\nR=json.load(open('scratch/evA.json'))+json.load(open('scratch/evB.json'))\no={r['seed']:r['edge'] for r in R if r['mode']=='oracle'};f={r['seed']:r['edge'] for r in R if r['mode']=='filter'}\nassert len(o)==len(f)==256 and all(abs((o[s]-f[s])-(o[s]-f[s]))<1e-12 for s in o)\nprint('ALL TESTS PASS')\n"}}