+
    1j"                    "   R t ^ RIHt ^ RIHt ^ RIt^ RIHt ^ RIt	]! RR7       ! R R4      4       t
]
! R	]! 0 Rm4      4      t]
! R
]! 0 Rm4      4      t]
! R]! 0 Rm4      4      t]
! R]! 0 R m4      4      t]
! R]! 0 R!m4      4      t]
! R]! 0 R"m4      4      t]
! R]! R04      4      t]]]]]]]]]]]]]]]]3t]]]]]]]]3t^t]! ]4      ],           t]! ]! ]! ]4      ]4      4      tR R ltR R ltR R ltR R ltR R ltR R lt R# )#a'  Interpretable input routing for the grouped MLP experiment.

Each first-layer unit receives one coherent family of features.  Later layers
remain dense, so the model can learn interactions *between* those family-level
representations without mixing unrelated raw signals in the first transform.
)annotations)	dataclassN)SequenceT)frozenc                  0    ] tR t^t$ RtR]R&   R]R&   RtR# )FeatureFamilyzDA named set of raw features routed to one or more first-layer units.strnamezfrozenset[str]features N)__name__
__module____qualname____firstlineno____doc____annotations____static_attributes__r       H/Users/jameslopez/projects/TradingBot25/strategies/mlp_feature_groups.pyr   r      s    N
Ir   r   local_technicalon_chaincandlesticksmacrorsid_structuremarket_flowcross_assetbtc_gold_normc               $    V ^8  d   QhRRRRRR/#    feature_colsSequence[str]hidden_sizeintreturn
np.ndarrayr   )formats   "r   __annotate__r'   S   s!      = s z r   c                   V\        \        4      8w  d    \        R\        \        4       RV R24      h\        4       P                  ! R \         4       !  p\        V 4      V,
          pV'       d   \        R\        V4       24      h\        P                  ! \         UUu. uF!  pV  Uu. uF  qUVP                  9   NK  	  upNK#  	  upp\        R7      pVP                  ^ R7      P                  4       '       gG   \        WP                  ^ R7      4       UUu. uF  w  rWV'       d   K  VNK  	  ppp\        RV 24      hV# u upi u uppi u uppi )	u   Return the allowed ``(hidden_size, n_features)`` first-layer edges.

The experiment deliberately targets the established 55→16→8→1 shape.
Failing on a different width prevents a silently arbitrary allocation.
z!Grouped input structure requires  first-layer units; received .c              3  8   "   T F  qP                   x  K  	  R # 5iNr
   .0familys   & r   	<genexpr>+grouped_first_layer_mask.<locals>.<genexpr>^   s     V>UF>U   z.Grouped input structure has unknown features: dtypeaxisz0Grouped input structure left features unrouted: )lenGROUPED_UNIT_ALLOCATION
ValueError	frozensetunionsetsortednparrayr
   boolanyallzip)	r    r"   knownunknownr0   featuremaskpresentmissings	   &&       r   grouped_first_layer_maskrK   S   s<    c122/4K0L/M N#}A'
 	
 KV>UVWE,%'GI&QX/IZ[\\88.	0.V 5A	ALV__
$L	A.	0D
 888!!36|XXSTXEU3Vf3V/w^e773VfKG9UVVK 
B 	0
 gs$   !	E	
*EE	
E+EE	
c               $    V ^8  d   QhRRRRRR/# r   r    r!   r"   r#   r$   dict[str, object]r   )r&   s   "r   r'   r'   m   s"      ]  Qb r   c                  a \        W4       \        \        P                  \        4      4      pRRR\         Uu. uF  q3P
                  NK  	  upRV Uau/ uF#  oSP
                  \        V3R lV  4       4      bK%  	  up/# u upi u upi )z>Serializable provenance saved beside an experimental artifact.r	   grouped_first_layer_v1unit_familiesfamily_feature_countsc              3  @   <"   T F  qSP                   9   x  K  	  R # 5ir,   r-   )r/   rG   r0   s   & r   r1   -grouped_structure_metadata.<locals>.<genexpr>u   s     T|G7|s   )rK   tupledictfromkeysr9   r	   sum)r    r"   familiesr0   s   && `r   grouped_structure_metadatarZ   m   s    \7T]]#:;<H(4KL4K&++4KL""
" KKT|TTT""
 L"
s   B
)Bc               $    V ^8  d   QhRRRRRR/# r   r   )r&   s   "r   r'   r'   {   s"     4 4- 4c 4V` 4r   c                4   V\         8w  d   \        R\          RV R24      h\        4       P                  ! R \         4       !  p\        V 4      V,
          pV'       d   \        R\        V4       24      h\        P                  ! \         UUu. uF!  pV  Uu. uF  qUVP                  9   NK  	  upNK#  	  upp\        R7      p\        P                  ! \        \        4      \        V 4      3\        R7      p\        P                  ! Wg34      # u upi u uppi )aJ  Return the v1 specialist-plus-dense first-layer connectivity mask.

Rows 0--7 are hard-routed specialists, in the documented family order.
Rows 8--15 remain fully trainable across every input feature.  Keeping the
architecture check strict makes the allocation auditable rather than an
accidental choice for another hidden width.
z(Hybrid grouped input structure requires r)   r*   c              3  8   "   T F  qP                   x  K  	  R # 5ir,   r-   r.   s   & r   r1   2hybrid_grouped_first_layer_mask.<locals>.<genexpr>   s     c>bF>br3   z5Hybrid grouped input structure has unknown features: r4   )HYBRID_GROUPED_HIDDEN_SIZEr:   r;   r<   $HYBRID_GROUPED_SPECIALIST_ALLOCATIONr=   r>   r?   r@   r
   rA   onesr8    HYBRID_GROUPED_DENSE_ROW_INDICESvstack)r    r"   rE   rF   r0   rG   specialist_rows
dense_rowss   &&      r   hybrid_grouped_first_layer_maskrf   {   s     0067Q6R S++6-q:
 	
 Kc>bcdE,%'GPQWX_Q`Pabcchh;	=;V 5A	ALV__
$L	A;	=O
 #>?\ARS[_`J99o233 
B 	=s   	D
D/D
D
c               $    V ^8  d   QhRRRRRR/# rM   r   )r&   s   "r   r'   r'      s#      M PS Xi r   c                   \        W4      pRP                  V 4      p\        \        4      pRRR^R\	        \        4       UUu/ uF  w  rV\        V4      VP                  bK  	  uppR\        \        4      R\        P                  ! VP                  4       4      P                  4       R\        VP                  4       4      R	\        VP                  VP                  4       ,
          4      R
VP                  ^R7       Uu. uF  p\        V4      NK  	  upRV Uu. uF'  p\         P"                  ! V4      P%                  4       NK)  	  upRVR\        \        4      /# u uppi u upi u upi )z@Return complete, reproducible provenance for the hybrid v1 mask.r	   hybrid_grouped_first_layer_v1versionspecialist_row_familiesdense_row_indicesfeature_cols_sha256active_edgesblocked_edgesrow_active_edgesr6   row_feature_indicesspecialist_row_countdense_row_count)rf   joinr8   r`   	enumerater   r	   listrb   hashlibsha256encode	hexdigestr#   rX   sizer?   flatnonzerotolist)r    r"   rH   feature_textspecialist_countrowr0   counts   &&      r   !hybrid_grouped_structure_metadatar      s-   *<ED;;|,L?@/1!()MN$
N Hfkk!N$
 	T"BCw~~l.A.A.CDNNPDHHJTYY34TXX1X5EF5EESZ5EFMs 3 : : <M 03?@ $
 GMs   !E E#"-E(&c               (    V ^8  d   QhRRRRRRRR/# )r   r    r!   r"   r#   	mask_seedr$   r%   r   )r&   s   "r   r'   r'      s,      .1>Ar   c                2   \        W4      p\        P                  P                  V4      p\        P                  ! V\
        R7      p\        VP                  ^R7      4       F1  w  rgVP                  \        V 4      \        V4      RR7      pRWVV3&   K3  	  V# )ac  Return a seeded random control mask with the grouped row capacities.

This deliberately samples features independently per hidden unit.  It is a
capacity-matched control, not a second semantic feature routing scheme.
Calling the grouped builder first preserves its architecture and feature
validation while providing the exact per-row active-edge counts.
r4   r6   F)r|   replaceT)rK   r?   randomdefault_rng
zeros_likerA   rv   rX   choicer8   r#   )	r    r"   r   grouped_maskrngrH   	row_indexro   selecteds	   &&&      r   random_sparse_first_layer_maskr      s     ,LFL
))

	
*C==T2D#,\-=-=1-=-E#F	::c,/c,6GQV:W$( ! $G Kr   c               (    V ^8  d   QhRRRRRRRR/# )r   r    r!   r"   r#   r   r$   rN   r   )r&   s   "r   r'   r'      s,      .1>Ar   c                   \        WV4      pRP                  V 4      pRRRTRRR\        P                  ! VP	                  4       4      P                  4       R\        VP                  4       4      R	\        VP                  VP                  4       ,
          4      R
VP                  ^R7       Uu. uF  p\        V4      NK  	  upRV Uu. uF'  p\        P                  ! V4      P                  4       NK)  	  up/# u upi u upi )zBReturn complete, serializable provenance for a random sparse mask.ri   r	   random_sparse_first_layer_v1r   	generatorzDnumpy.default_rng(seed).choice(n_features, row_count, replace=False)rn   ro   rp   rq   r6   rr   )r   ru   rx   ry   rz   r{   r#   rX   r|   r?   r}   r~   )r    r"   r   rH   r   r   r   s   &&&    r    random_sparse_structure_metadatar      s     *,YOD;;|,L.Y[w~~l.A.A.CDNNPDHHJTYY34TXX1X5EF5EESZ5EFMs 3 : : <M	 	 GMs   .C:	-C?">   osc_norm
stoch_normm2_div_normm3_div_normm2_tiny_normbb_pct_b_normm2_nooff_normvwap_div_normmacd_pred_normrsi_subtf_normstoch_div_normstoch_peak_normm3_momentum_norm>	   hr_norm	nupl_norm	sopr_normnewaddr_normactive1y_normsendaddr_normtotalvol_normmvrv_zscore_contmvrv_zscore_value>   shooting_star_scorebullish_hammer_scorebearish_engulfing_scorebullish_engulfing_score>   gc_positiondxy_roc_normbtc_spx_corr_30vix_pctrank_invbtc_dom_roc_signfed_net_liq_signgold_roc_pctrankspy_above_200emayield_curve_signus2y_roc_inv_signus10y_roc_inv_sign>
   rsid_rt_bear_normrsid_rt_bull_normrsid_hid_bear_normrsid_hid_bull_normrsid_reg_bear_normrsid_reg_bull_normrsid_slow_bear_normrsid_slow_bull_normrsid_delayed_dip_normrsid_delayed_peak_norm>   cvd_norm	rvol_norm
basis_normoi_roc_normusdt_d_norm)!r   
__future__r   dataclassesr   rx   typingr   numpyr?   r   r;   LOCAL_TECHNICALON_CHAINCANDLESTICKSMACRORSIDMARKET_FLOWCROSS_ASSETr9   r`   HYBRID_GROUPED_DENSE_UNIT_COUNTr8   r_   rU   rangerb   rK   rZ   rf   r   r   r   r   r   r   <module>r      s   # !    $     19 > 4  Y 0 &  ^Y 8 .  	gy *   	
 %y 2 (  M9 6 ,  M9o5F+GH _oh	5%$  _	( $ #$  !EFIhh #(	#2
35OP$  
444.&r   