ó
    ­³Àj«&  ã                  óŽ   • S r SSKJr  SSKrSSKrSSKJr  Sr	 " S S\
5      rSSS jjrSS	 jr   SSS
 jjrSS jrSSS jjrg)aš  Supported chronological origins, faculty balancing, and earlier-only priors.

Origins are single semesters in the target term of the three-semester academic
calendar. A cell is eligible only when both outcomes have support. Faculty
coverage is an explicit fraction of the full selected faculty schema; the
production default requires every faculty. No target outcome enters selection
or evidence construction.
é    )ÚannotationsN)ÚTable)ÚsemesterÚfacultyÚrowsÚ	positivesÚ	negativesÚorigin_rowsÚ
train_rowsÚtrain_faculty_rowsÚ	same_termÚeligibleÚreasonÚorigin_eligibleÚselectedc                  ó0   ^ • \ rS rSrSrSU 4S jjrSrU =r$ )ÚUnsupportedOriginsErroré   zÜNo supported origin exists; ``audit`` retains every inspected cell.

Callers must print and, outside preflight, save the full audit rather than
falling back to an unsupported semester or a different validation protocol.
c                óN   >• UR                  5       U l        [        TU ]  S5        g )NzGNo supported earlier same-term origins; inspect the full support audit.)ÚcopyÚauditÚsuperÚ__init__)Úselfr   Ú	__class__s     €ÚT/root/disk_3tb/earlywarning/30072026/suite27_memory_conditioned_boosting/protocol.pyr   Ú UnsupportedOriginsError.__init__   s   ø€ Ø—Z‘Z“\ˆŒ
Ü‰ÑÐbÕcó    )r   )r   úpd.DataFrame)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ú__static_attributes__Ú__classcell__)r   s   @r   r   r      s   ø† ñ÷
dõ dr   r   c                óÄ   •  [        U 5      nX0:w  d  Ub  X2:  a  Ub  SU 3OSn[        U SU 35      eU$ ! [        [        [        4 a  n[        U S35      UeS nAff = f)Nz must be a finite integerz >= Ú )ÚintÚ	TypeErrorÚ
ValueErrorÚOverflowError)ÚvalueÚnameÚminimumÚresultÚexcÚbounds         r   Ú_integerr3   "   s�   € ðFÜ�U“ˆð ƒ˜7Ñ.°6Ó3CØ$+Ñ$7�$�w�iÑ ¸RˆÜ˜D˜6Ð!:¸5¸'ÐBÓCÐCØ€Møô ”z¤=Ð1ó FÜ˜D˜6Ð!:Ð;Ó<À#ÐEûðFús   ‚6 ¶AÁAÁAc                ó~  • [        U 5      (       d#  [        R                  " S[        R                  S9$ [        R                  " U R
                  [        U R                  5      S9n[        [        R                  " U5      5      n[        U 5      X!U R
                     -  -  R                  [        R                  5      $ )zÅMean-one inverse faculty-frequency weights, with no class balancing.

An absent schema faculty has no rows to weight. Each observed faculty has
equal total mass, and the average row weight is one.
r   ©Údtype)Ú	minlength)
ÚlenÚnpÚemptyÚfloat32Úbincountr   Úfaculty_namesr)   Úcount_nonzeroÚastype)ÚtableÚcountsÚpresents      r   Úfaculty_weightsrC   -   s€   € ô ˆu�:‰:Ü�xŠx˜¤§¡Ñ,Ð,Ü�[Š[˜Ÿ™´#°e×6IÑ6IÓ2JÑK€FÜ”"×"Ò" 6Ó*Ó+€GÜ�‹J˜'¨5¯=©=Ñ$9Ñ9Ñ:×BÑBÄ2Ç:Á:ÓNÐNr   c	                ó¸
  ^/• [        US5      n	[        USS5      n
[        USS5      n[        USS5      m/[        S[        USS5      5      n[        S[        USS5      5      n[        US	S5      n [        U5      n[        R                  " U5      (       a  SUs=:  a  S::  d  O  [	        S
5      e[        R                  " U R                  U R                  U R                  R                  [        R                  5      S.5      nUR                  SS/SS9S   R!                  SS/5      n[        R"                  " [%        U R&                  5      [        R                  S9n/ / nn[        R(                  " U R                  5       GHC  n[+        U5      nUS-  U	S-  :H  n[+        UR-                  5       5      n/ n[/        U R&                  5       GH  u  nnUU4nUUR0                  ;   a,  UR2                  U   n[+        US   5      [+        US   5      nnOSu  nnUU-
  n / n!UT/:  a  U!R5                  ST/ 35        UU:  a  U!R5                  SU 35        U U:  a  U!R5                  SU 35        U!(       + n"UU   T/:  a  U!R5                  ST/ 35        UR5                  [7        UUUUU U[+        UU   5      [9        U5      [9        U"5      U!S9
5        GM     U V#s/ s H  n#U#S   (       d  M  U#PM     n$n#[-        S U 5       5      n%U%U:¬  n&[%        U$5      [%        U R&                  5      -  U:¬  n'UU:¬  n([;        U/4S jU$ 5       5      n)[9        UU	:  =(       a/    U=(       a&    U&=(       a    U'=(       a    U(=(       a    U)=(       a    U$5      n*U*(       a  UR5                  U5        / n+UU	:¼  a  U+R5                  S5        U(       d  U+R5                  S 5        U&(       d  U+R5                  S!U 35        U'(       d  U+R5                  S"US# 35        U((       d  U+R5                  S$U 35        U)(       d  U+R5                  S%5        U HF  n,U%U,S&'   S'R=                  U,S(   U+-   5      =(       d    S)U,S('   U*U,S*'   S+U,S,'   UR5                  U,5        MH     U[        R>                  " U V#s/ s H  n#U#S-   PM
     sn#[        R                  S9-  nGMF     [        R                  RA                  U[B        S.9n-UU
* S n.U.(       d  [E        U-5      eU-S   RG                  U.5      U-S   -  U-S,'   U.U-4$ ! [        [        [
        4 a  n[	        S
5      UeSnAff = fs  sn#f s  sn#f )/a–  Return the latest supported same-term origins and an exhaustive audit.

``eligible`` describes a faculty's validation outcome support independently
of term and global training support. ``min_faculty_rows`` applies to both
each validation cell and that faculty's earlier training rows. An
``origin_eligible`` semester also needs ``min_rows`` across its entire cohort,
must precede target, match its term, cover the requested faculty fraction,
have enough earlier training rows, and have enough earlier rows for *every*
eligible validation faculty. Less than n_origins may be returned; zero is
always an explicit UnsupportedOriginsError carrying a headered audit.
Útarget_semesterÚ	n_originsé   Úmin_rowsr   Úmin_faculty_rowsÚmin_positiveÚmin_negativeÚmin_train_rowsz%coverage must be finite and in (0, 1]N)r   r   Úpositiver   r   T)ÚsortrM   ÚsizeÚsumr5   é   )r   r   zfaculty_rows<z
positives<z
negatives<ztrain_faculty_rows<)
r   r   r   r   r	   r   r   r   r   r   r   c              3  ó*   #   • U  H	  oS    v •  M     g7f)r   N© )Ú.0Úrs     r   Ú	<genexpr>Ú!choose_origins.<locals>.<genexpr>z   s   é € Ð:ª\¨˜Fž)ª\ùs   ‚c              3  ó2   >#   • U  H  oS    T:¬  v •  M     g7f)r   NrS   )rT   rU   Úfaculty_mins     €r   rV   rW   ~   s   øé € Ð!aÒR`ÈQÐ$8Ñ"9¸[Ö"HÒR`ùs   ƒÚnot_earlier_than_targetÚnot_same_termzorigin_rows<zfaculty_coverage<Úgztrain_rows<Ú%eligible_faculty_training_unsupportedr
   Ú;r   Ú	supportedr   Fr   r   )Úcolumns)$r3   ÚmaxÚfloatr*   r+   r,   r9   ÚisfiniteÚpdÚ	DataFramer   r   Úyr?   Úint64ÚgroupbyÚaggÚzerosr8   r=   Úuniquer)   rP   Ú	enumerateÚindexÚlocÚappendÚdictÚboolÚallÚjoinÚasarrayÚfrom_recordsÚSUPPORT_COLUMNSr   Úisin)0r@   rE   rF   rH   rI   rJ   rK   rL   ÚcoverageÚtargetÚnumberÚrow_minÚpositive_minÚnegative_minÚ	train_minÚrequired_coverager1   ÚobservedrA   Ú	precedingÚrecordsÚeligible_originsr   r   r   Úterm_recordsÚfir   ÚkeyÚrowr   r   r	   ÚreasonsÚcell_eligiblerU   Úeligible_cellsr
   Ú	cohort_okÚcoverage_okÚtraining_okÚfaculty_training_okr   Úshared_reasonsÚrecordr   ÚoriginsrY   s0                                                  @r   Úchoose_originsr’   :   s'  ø€ ô �oÐ'8Ó9€FÜ�i ¨aÓ0€FÜ�x ¨QÓ/€GÜÐ+Ð-?ÀÓC€KÜ�qœ( <°ÀÓCÓD€LÜ�qœ( <°ÀÓCÓD€LÜ˜Ð)9¸1Ó=€IðKÜ! (›OÐô �;Š;Ð(×)Ñ)°Ð5FÕ1KÈ!Õ1KÜÐ@ÓAÐAô �|Š|¨¯©ÀEÇMÁMØ).¯©¯©¼¿¹Ó)AñCó D€Hà×Ñ˜z¨9Ð5¸DÐÐAÀ*ÑM×QÑQÐSYÐ[`ÐRaÓb€FÜ—’œ˜U×0Ñ0Ó1¼¿¹ÑB€IØ " BÐ€GÜ—I’I˜eŸn™n×-ˆÜ�x“=ˆØ˜q‘L F¨Q¡JÑ.ˆ	Ü˜Ÿ™›Ó)ˆ
ØˆÜ$ U×%8Ñ%8×9‰KˆB�Ø˜R�.ˆCØ�f—l‘lÓ"Ø—j‘j ‘o�Ü"% c¨&¡kÓ"2´C¸¸E¹
³O�i��ià"&‘��iØ˜yÑ(ˆIØˆGØ�kÓ!Ø—‘ ¨{¨mÐ<Ô=Ø˜<Ó'Ø—‘ ¨L¨>Ð:Ô;Ø˜<Ó'Ø—‘ ¨L¨>Ð:Ô;Ø 'œKˆMØ˜‰}˜{Ó*Ø—‘Ð!4°[°MÐBÔCØ×Ñ¤Ø!¨7¸ÈØ#°
Ü#& y°¡}Ó#5ÄÀiÃÜ˜mÓ,°Wñ	!÷ ñ% :ñ0 &2ÓC¢\ °Q°zµ]Ÿ!¡\ˆÐCÜÑ:©\Ó:Ó:ˆØ 7Ñ*ˆ	Ü˜.Ó)¬C°×0CÑ0CÓ,DÑDÐHYÑYˆØ  IÑ-ˆÜ!Ô!aÑR`Ó!aÓaÐÜ˜x¨&Ñ0÷  J°Y÷  JÀ9÷  JÐQ\÷  JÐal÷  JØ#6÷ JØ;IóKˆæØ×#Ñ# HÔ-ØˆØ�vÓØ×!Ñ!Ð";Ô<ÞØ×!Ñ! /Ô2ÞØ×!Ñ! L°°	Ð":Ô;ÞØ×!Ñ!Ð$5Ð6GÈÐ5JÐ"KÔLÞØ×!Ñ! K°	¨{Ð";Ô<Þ"Ø×!Ñ!Ð"IÔJÛ"ˆFØ$/ˆF�=Ñ!Ø"Ÿx™x¨¨xÑ(8¸>Ñ(IÓJ×YÈkˆF�8ÑØ(7ˆFÐ$Ñ%Ø!&ˆF�:ÑØ�N‰N˜6Ö"ñ #ð 	”R—Z’Z±LÓ A²L¨q  6¤±LÑ AÌÏÉÑRÑR‹	ñu .ôv �L‰L×%Ñ% g´Ð%ÐG€EØ ˜w˜xÐ(€GÞÜ% eÓ,Ð,Ø˜jÑ)×.Ñ.¨wÓ7¸%À
Ñ:KÑK€Eˆ*ÑØ�Eˆ>ÐøôW ”z¤=Ð1ó KÜÐ@ÓAÀsÐJûðKüòP Dùò: !Bs*   Á1T) ËUË/UÒ$UÔ)UÔ>U
Õ
Uc                óŒ   • [        US5      nU R                  U S   U:H  U S   -  S4   R                  5       R                  5       $ )zIEligible faculty names at an origin, preserving the audit's schema order.Úoriginr   r   r   )r3   rn   Údrop_duplicatesÚtolist)r   r”   r   s      r   Úorigin_cellsr—   Ÿ   sH   € ä˜ Ó)€HØ�9‰9�e˜JÑ'¨8Ñ3°u¸ZÑ7HÑHÈ)ÐSÑT×dÑdÓf×mÑmÓoÐor   c           	     óx  • [        USS5      nU R                  UR                  :w  d  U R                  UR                  :w  a  [        S5      e[        R
                  " [        R                  " SS/[        R                  S9[        U5      S45      n[        [        U R                  5      5       GH   n[        R                  " U R                  U:H  5      n[        R                  " UR                  U:H  5      n[        U5      (       a  [        U5      (       d  Ml  U[        R                  " U R                  U   SS	9   nU R                  U   n	U R                  U   R                  [        R                   5      n
U R"                  U   n[        R$                  " [        R&                  " U5      US
-  SU
-
  5      n[        R(                  " S/[        R*                  " U
[        R                   S9/5      n[        R(                  " S/[        R*                  " U[        R                   S9/5      n[        R                  " UR                  U    Vs/ s H  n[-        U5      U-
  PM     sn5      n[        R.                  " U	USS9nUS:„  nUU   UU   nnUU   U-  UUS4'   UU   U-  UUS4'   GM     U$ s  snf )ah  Cumulative earlier-only faculty failure and performance means [N, 2].

For each query, bank.semester must be strictly below query.semester-embargo.
Performance is the observed grade divided by ten, or 1-y if grade is absent.
Faculty defaults without earlier observations are failure=.1, performance=.65.
Row order and query outcomes cannot alter these priors.
Úembargor   z7Prior bank/query feature and faculty schemas must matchgš™™™™™¹?gÍÌÌÌÌÌä?r5   rG   Ústable)Úkindg      $@ç      ð?g        Úleft)Úside)r3   r=   Úfeature_namesr+   r9   Útilert   r;   r8   ÚrangeÚflatnonzeror   Úargsortr   rf   r?   Úfloat64ÚgradeÚwhererc   ÚconcatenateÚcumsumr)   Úsearchsorted)Ú
bank_tableÚquery_tabler™   Úexcludedr0   r…   Ú	bank_rowsÚ
query_rowsÚorderr   Úfailurer¥   ÚperformanceÚfailure_sumÚperformance_sumr-   ÚcutoffÚcountÚknownÚsupported_rowsÚdenominators                        r   Úprior_evidencer¹   ¥   s<  € ô ˜ ¨AÓ.€HØ× Ñ  K×$=Ñ$=Ó=Ø×'Ñ'¨;×+DÑ+DÓDÜÐRÓSÐSÜ�WŠW”R—Z’Z  S 	´·±Ñ<¼sÀ;Ó?OÐQRÐ>SÓT€FÜ”C˜
×0Ñ0Ó1×2ˆÜ—N’N :×#5Ñ#5¸Ñ#;Ó<ˆ	Ü—^’^ K×$7Ñ$7¸2Ñ$=Ó>ˆ
Ü�9�~‰~¤S¨§_¡_ÙØœ"Ÿ*š* Z×%8Ñ%8¸Ñ%CÈ(ÑSÑTˆØ×&Ñ& uÑ-ˆØ—,‘,˜uÑ%×,Ñ,¬R¯Z©ZÓ8ˆØ× Ñ  Ñ'ˆÜ—h’hœrŸ{š{¨5Ó1°5¸3±;ÀÀWÁÓMˆÜ—n’n r d¬B¯IªI°gÄRÇZÁZÑ,PÐ%QÓRˆÜŸ.š.¨2¨$´·	²	¸+ÌRÏZÉZÑ0XÐ)YÓZˆä—’À×@TÑ@TÐU_Ò@`ÓaÒ@`°uœS ›Z¨(Ô2Ñ@`ÑaÓbˆÜ—’ ¨&°vÑ>ˆØ˜‘	ˆØ&0°Ñ&7¸¸u¹˜ˆØ$/°Ñ$<¸{Ñ$Jˆˆ~˜qÐ Ñ!Ø$3°KÑ$@À;Ñ$Nˆˆ~˜qÐ Ô!ñ% 3ð& €Mùò bs   ÉJ7
)N)r.   ÚstrÚreturnr)   )r@   r   r»   ú
np.ndarray)é   iÐ  é   é   é   iˆ  rœ   )r@   r   )r   r   r»   z	list[str])r   )rª   r   r«   r   r»   r¼   )r$   Ú
__future__r   Únumpyr9   Úpandasrd   Údatar   rv   r+   r   r3   rC   r’   r—   r¹   rS   r   r   Ú<module>rÅ      sW   ðñõ #ã Û å ð€ôd˜jô döô
Oð IMØEGØ14öbôJp÷ r   