+
    s(j  c                   l    R t ^ RIt^ RIHu Ht ^ RIt^ RI	t	^ RI
HtHt  ! R R4      t ! R R4      tR# )au  
TDD RED tests for the MLP forward pass in strategies/strategy_mlp_scores.py.

Contract under test:
  - _tanh(x): clamped closed-form tanh, identical formula to the Pine implementation:
        tanh(x) = x >= 20 ?  1.0
                : x <= -20 ? -1.0
                : (exp(2x) - 1) / (exp(2x) + 1)
  - mlp_forward(X, layers): X is a (T, F) float64 matrix; layers is a list of
    (W, b) tuples with W shape (n_out, n_in) and b shape (n_out,).
    Every layer (including the output layer) applies _tanh; the final scalar
    is scaled by 1000 so scores live in [-1000, +1000] like the existing
    activation-score convention.
N)_tanhmlp_forwardc                   2   a  ] tR t^t o R tR tR tRtV tR# )TestTanhc                   \         P                  ! RR R4      p\         P                  p\         P                  p\	        V4      p\         P
                  qU! V4      qdV,
          qs! V4      q! V4      p	RqV
8  q'       Eg   \        P                  ! RV3RW34      RR\        P                  ! 4       9   g!   \        P                  ! \         4      '       d   \        P                  ! \         4      MRR\        P                  ! V4      RR\        P                  ! 4       9   g!   \        P                  ! \         4      '       d   \        P                  ! \         4      MRR\        P                  ! V4      RR	\        P                  ! 4       9   g!   \        P                  ! \        4      '       d   \        P                  ! \        4      MR	R
R\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V4      RR\        P                  ! 4       9   g!   \        P                  ! \         4      '       d   \        P                  ! \         4      MRR\        P                  ! V4      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V4      R\        P                  ! V4      R\        P                  ! V	4      R\        P                  ! V
4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;p;p;p;p;p;p;p	;rR# )g      3@i  -q=py0nppy2py3py5py6r   py7xpy9py10py12py13py15py18py20py23zassert %(py25)spy25Ng      3<)z%(py20)s
{%(py20)s = %(py2)s
{%(py2)s = %(py0)s.max
}(%(py18)s
{%(py18)s = %(py5)s
{%(py5)s = %(py3)s.abs
}((%(py9)s
{%(py9)s = %(py6)s(%(py7)s)
} - %(py15)s
{%(py15)s = %(py12)s
{%(py12)s = %(py10)s.tanh
}(%(py13)s)
}))
})
} < %(py23)s)r   linspacemaxabsr   tanh
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanation)selfr   @py_assert1@py_assert4@py_assert8@py_assert11@py_assert14@py_assert16@py_assert17@py_assert19@py_assert22@py_assert21@py_format24@py_format26s   &             A/Users/jameslopez/projects/TradingBot25/tests/test_mlp_forward.pytest_matches_numpy_inside_clamp(TestTanh.test_matches_numpy_inside_clamp   s   KKtT*vv<bff<U1X<<
<
2<f23<v34<u<u<<<<<4<<<<<<r<<<<r<<<v<<<<<<b<<<<b<<<f<<<<<<U<<<<U<<<<<<<1<<<<1<<<X<<<<<<<<<<<<<<<<<<<<<<<<<<
<<<3<<<4<<<u<<<<<<<<<<    c                
   \        \        P                  ! . RO4      4      ^ ,          pRq!V8H  q3'       gy   \        P                  ! RV3RW34      R\        P
                  ! V4      R\        P
                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;r2\        P                  p\        P                  p. ROq! V4      p	\        V	4      p
RqV8H  q! V4      q'       Eg   \        P                  ! RV3RW34      RR\        P                  ! 4       9   g!   \        P                  ! \         4      '       d   \        P
                  ! \         4      MRRR	\        P                  ! 4       9   g!   \        P                  ! \        4      '       d   \        P
                  ! \        4      MR	R\        P
                  ! V4      R
\        P
                  ! V4      R\        P
                  ! V	4      R\        P
                  ! V
4      R\        P
                  ! V4      /,          pRRR	\        P                  ! 4       9   g!   \        P                  ! \        4      '       d   \        P
                  ! \        4      MR	R\        P
                  ! V4      RVR\        P
                  ! V4      /,          p\        \        P                  ! V4      4      hR;p;p;p;p	;p
;p;r\        P                  p\        P                  p. ROq! V4      p	\        V	4      p
Rq) pV
V8H  q! V4      pV'       Eg   \        P                  ! RV3RV
V34      RR\        P                  ! 4       9   g!   \        P                  ! \         4      '       d   \        P
                  ! \         4      MRRR	\        P                  ! 4       9   g!   \        P                  ! \        4      '       d   \        P
                  ! \        4      MR	R\        P
                  ! V4      R
\        P
                  ! V4      R\        P
                  ! V	4      R\        P
                  ! V
4      R\        P
                  ! V4      /,          pRRR	\        P                  ! 4       9   g!   \        P                  ! \        4      '       d   \        P
                  ! \        4      MR	R\        P
                  ! V4      RVR\        P
                  ! V4      /,          p\        \        P                  ! V4      4      hR;p;p;p;p	;p
;p;p;ppR# )      4@      ?py1py4zassert %(py6)sr   Nr
   r   r   py8r   r   r   zHassert %(py19)s
{%(py19)s = %(py2)s
{%(py2)s = %(py0)s.all
}(%(py17)s)
}r   r	   py17py19zHassert %(py20)s
{%(py20)s = %(py2)s
{%(py2)s = %(py0)s.all
}(%(py18)s)
}r   r   )r8   g      9@g    .A==)z%(py1)s == %(py4)s)zn%(py12)s
{%(py12)s = %(py3)s(%(py10)s
{%(py10)s = %(py6)s
{%(py6)s = %(py4)s.array
}(%(py8)s)
})
} == %(py15)s)g      4g      9g    .)zo%(py12)s
{%(py12)s = %(py3)s(%(py10)s
{%(py10)s = %(py6)s
{%(py6)s = %(py4)s.array
}(%(py8)s)
})
} == -%(py15)s)r   r   arrayr   r   r#   r$   r%   allr    r!   r"   )r&   @py_assert0@py_assert3@py_assert2@py_format5@py_format7r'   @py_assert5@py_assert7@py_assert9r*   r+   @py_assert13@py_assert18@py_format16@py_format20r,   r.   @py_format17@py_format21s   &                   r3    test_clamps_to_exact_one_outside)TestTanh.test_clamps_to_exact_one_outside   s   RXX/01!4;;;;;;;4;;;4;;;;;;;;;;;vv@BHH@%6@H%67@e78@C@C?@v@@@@@@@8@@@@@@e@@@@e@@@@@@@B@@@@B@@@H@@@%6@@@7@@@8@@@C@@@@@@@r@@@@r@@@v@@@@@@@@@@@@vvDBHHD%9DH%9:De:;DDtD;tCDvDDDDDDDD;tDDDDDDeDDDDeDDDDDDDBDDDDBDDDHDDD%9DDD:DDD;DDDDDDDDDDrDDDDrDDDvDDDDDDDDDDDDr6   c                ~   R p\        V4      p\        V4      p\        P                  pR qT! V4      qcV,
          p\	        V4      pRqV	8  q'       EgU   \
        P                  ! RV
3RW34      RR\        P                  ! 4       9   g!   \
        P                  ! \        4      '       d   \
        P                  ! \        4      MRRR\        P                  ! 4       9   g!   \
        P                  ! \        4      '       d   \
        P                  ! \        4      MRRR\        P                  ! 4       9   g!   \
        P                  ! \         4      '       d   \
        P                  ! \         4      MRR\
        P                  ! V4      R	\
        P                  ! V4      R
\
        P                  ! V4      RR\        P                  ! 4       9   g!   \
        P                  ! \        4      '       d   \
        P                  ! \        4      MRR\
        P                  ! V4      R\
        P                  ! V4      R\
        P                  ! V4      R\
        P                  ! V4      R\
        P                  ! V	4      /,          pRRV/,          p\        \
        P                  ! V4      4      hR;p;p;p;p;p;p;p;p;rRp\        V4      p\        V4      pRpVV8H  pV'       EgR   \
        P                  ! RV3RVV34      RR\        P                  ! 4       9   g!   \
        P                  ! \        4      '       d   \
        P                  ! \        4      MRRR\        P                  ! 4       9   g!   \
        P                  ! \         4      '       d   \
        P                  ! \         4      MRR\
        P                  ! V4      R\
        P                  ! V4      R\
        P                  ! V4      R\
        P                  ! V4      /,          pRRV/,          p\        \
        P                  ! V4      4      hR;p;p;p;ppR# )       ?r   r   r   r:   floatr	   r   r;   r   r<   r   r   py11r   r   r   py21zassert %(py23)sr   N        r
   r   r   r   zassert %(py12)sr   r   )z%(py18)s
{%(py18)s = %(py0)s((%(py8)s
{%(py8)s = %(py1)s(%(py6)s
{%(py6)s = %(py2)s(%(py4)s)
})
} - %(py15)s
{%(py15)s = %(py11)s
{%(py11)s = %(py9)s.tanh
}(%(py13)s)
}))
} < %(py21)sr?   )zO%(py7)s
{%(py7)s = %(py0)s(%(py5)s
{%(py5)s = %(py1)s(%(py3)s)
})
} == %(py10)s)r   rU   r   r   r   r   r   r    r!   r"   r#   r$   r%   )r&   rD   rH   rI   @py_assert10@py_assert12r+   r,   r-   @py_assert20r.   @py_format22r1   rE   r(   @py_assert6rJ   r)   @py_format11@py_format13s   &                   r3   test_scalar_inputTestTanh.test_scalar_input    s*   "<s<5$<rww<s<ws|<|3<s34<u<u<<<<<4<<<<<<s<<<<s<<<<<<<5<<<<5<<<<<<<<<<<<<<s<<<<<<$<<<<<<r<<<<r<<<w<<<s<<<|<<<4<<<u<<<<<<<<<<'U3Z'uZ 'C' C''''' C''''''u''''u'''''''U''''U'''3'''Z''' '''C'''''''''r6    N)	__name__
__module____qualname____firstlineno__r4   rQ   r`   __static_attributes____classdictcell____classdict__s   @r3   r   r      s     =E( (r6   r   c                   8   a  ] tR t^%t o R tR tR tR tRtV t	R# )TestForwardc                   \         P                  ! . RO. RO.\         P                  R7      p\         P                  ! RR.\         P                  R7      p\         P                  ! RR..\         P                  R7      p\         P                  ! R.\         P                  R7      p\         P                  ! . RO.\         P                  R7      p\         P                  ! W^ ,          ,          V,           4      pR\         P                  ! W6,          V,           4      ^ ,          ,          p\	        WQV3W43.4      pVP
                  p	RqV
8H  q'       g   \        P                  ! RV3RW34      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V	4      R	\        P                  ! V
4      /,          pR
RV/,          p\        \        P                  ! V4      4      hR;p	;rV^ ,          qV,
          p
\        V
4      pRqV8  pV'       Eg3   \        P                  ! RV3RW34      RR\        P                  ! 4       9   g!   \        P                  ! \        4      '       d   \        P                  ! \        4      MRR\        P                  ! V	4      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p	;p
;p;ppR# )rT   皙?dtypegffffff?g?     @@r   outr	   r   assert %(py7)sr   N&.>r   r
   expectedr   r   zassert %(py11)srV   )rT   g      пrn   )g?g333333?gٿgɿg333333)r9   g      g      ?)   r?   z-%(py2)s
{%(py2)s = %(py0)s.shape
} == %(py5)sr   )z;%(py6)s
{%(py6)s = %(py0)s((%(py2)s - %(py3)s))
} < %(py9)s)r   rA   float64r   r   shaper   r   r    r!   r"   r#   r$   r%   r   )r&   W1b1W2b2r   hru   rr   r'   r(   rD   @py_format6@py_format8rH   r)   rI   @py_format10@py_format12s   &                  r3   test_hand_computed_two_layer(TestForward.test_hand_computed_two_layer&   s    XX((*13=XXsDk4XXT{m2::6XXtfBJJ/HH'(

;GGB1IN#BGGBFRK033!2h12yy D D     y      s    s   y   D        q6,H$,s$%,,,,,,,%,,,,,,s,,,,s,,,6,,,,,,H,,,,H,,,%,,,,,,,,,,,,r6   c                	   \         P                  P                  ^*4      p^. ROr2VP                  R^W#^ ,          3R7      p\	        \        V4      ^,
          4       Uu. uFK  pVP                  RW5^,           ,          W5,          3R7      VP                  RW5^,           ,          R7      3NKM  	  pp\        WF4      pVP                  q3qV	8H  q'       g   \        P                  ! RV
3RW34      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V4      R\        P                  ! V	4      /,          pR	R
V/,          p\        \        P                   ! V4      4      hR;p;rVP"                  p\         P$                  qV8H  q'       Eg   \        P                  ! RV
3RW34      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V4      RR\        P                  ! 4       9   g!   \        P                  ! \         4      '       d   \        P                  ! \         4      MRR\        P                  ! V4      /,          pRRV/,          p\        \        P                   ! V4      4      hR;p;r\         P&                  p\         P(                  q! V4      pRpVV8*  pV! V4      pV'       Eg   \        P                  ! RV3RVV34      RR\        P                  ! 4       9   g!   \        P                  ! \         4      '       d   \        P                  ! \         4      MRR\        P                  ! V	4      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V4      R\        P                  ! V4      /,          pRRR\        P                  ! 4       9   g!   \        P                  ! \         4      '       d   \        P                  ! \         4      MRR\        P                  ! V4      RVR\        P                  ! V4      /,          p\        \        P                   ! V4      4      hR;p;p	;p;p;ppR# u upi )*   sizerT   scaler   rn   r   rr   r	   r   rs   r   Nr;   r   r   zassert %(py8)sr<   rq   r
   rV   zHassert %(py15)s
{%(py15)s = %(py2)s
{%(py2)s = %(py0)s.all
}(%(py13)s)
}r   r   1         rv   r?   rw   )zJ%(py2)s
{%(py2)s = %(py0)s.dtype
} == %(py6)s
{%(py6)s = %(py4)s.float64
})<=)zJ%(py8)s
{%(py8)s = %(py5)s
{%(py5)s = %(py3)s.abs
}(%(py6)s)
} <= %(py11)s)r   randomdefault_rnguniformrangelennormalr   ry   r   r   r    r!   r"   r#   r$   r%   rp   rx   rB   r   )r&   rngTarchXilayersrr   r'   r(   rD   r   r   rH   rG   @py_format9rI   rY   rJ   r+   r   rM   s   &                     r3   test_output_shape_and_range'TestForward.test_output_shape_and_range8   s   ii##B'^4KKAQQLK1 3t9q=)
 * ZZc!edg(>Z?ZZcUZ46) 	 

 !$yy D D     y      s    s   y   D        yy&BJJ&J&&&&&y&&&&&&s&&&&s&&&y&&&&&&B&&&&B&&&J&&&&&&&&vv,bff,fSk,V,kV+,v,,,,,,,,kV,,,,,,b,,,,b,,,f,,,,,,S,,,,S,,,k,,,V,,,,,,,r,,,,r,,,v,,,,,,,,,,,,
s   AS+c                L   \         P                  ! R\         P                  R7      p\         P                  ! R4      \         P                  ! ^4      3\         P                  ! R4      \         P                  ! ^4      3.p\         P                  p\        W4      pRqTV8H  qc! V4      qw'       Eg   \        P                  ! RV3RWE34      RR\        P                  ! 4       9   g!   \        P                  ! \
        4      '       d   \        P                  ! \
        4      MRRR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRRR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR	\        P                  ! V4      R
\        P                  ! V4      /,          pRRR\        P                  ! 4       9   g!   \        P                  ! \         4      '       d   \        P                  ! \         4      MRR\        P                  ! V4      RVR\        P                  ! V4      /,          p	\        \        P                  ! V	4      4      hR;p;p;p;rWR# )   ro   rX   r
   r   r;   r   r   r   r   r   zHassert %(py14)s
{%(py14)s = %(py2)s
{%(py2)s = %(py0)s.all
}(%(py12)s)
}r   r   r	   r   py14N)r      )   r   )rv   r   r?   )z:%(py7)s
{%(py7)s = %(py3)s(%(py4)s, %(py5)s)
} == %(py10)s)r   onesrx   zerosrB   r   r   r   r    r!   r"   r#   r$   r%   )
r&   r   r   r'   r]   rJ   r)   rK   r^   @py_format15s
   &         r3   !test_zero_weights_give_zero_score-TestForward.test_zero_weights_give_zero_scoreF   s[   GGF"**-88F#RXXa[1BHHV4Dbhhqk3RSvv4k!,4434v4444444,444444k4444k4444444!4444!4444444V4444V444,4444444444r4444r444v44444444444r6   c                h	   \         P                  ! R 4      p\        P                  P	                  ^4      p. ROpVP                  R^^@V^ ,          3R7      p\        \        V4      ^,
          4       Uu. uFK  pVP                  RW5^,           ,          W5,          3R7      VP                  RW5^,           ,          R7      3NKM  	  ppVP                  4       ;_uu_ 4        VP                  WAP                  R7      pV FK  w  rVP                  WqP                  VP                  4      ,          VP                  V	4      ,           4      pKM  	  VP                  R4      R,          P                  4       p
RRR4       \        P                   p\        P"                  p\%        WF4      qX
,
          q! V4      q! V4      pRpVV8  pV'       Eg   \&        P(                  ! RV3RVV34      R	R
\*        P,                  ! 4       9   g!   \&        P.                  ! \        4      '       d   \&        P0                  ! \        4      MR
R\&        P0                  ! V4      RR
\*        P,                  ! 4       9   g!   \&        P.                  ! \        4      '       d   \&        P0                  ! \        4      MR
R\&        P0                  ! V4      RR\*        P,                  ! 4       9   g!   \&        P.                  ! \$        4      '       d   \&        P0                  ! \$        4      MRRR\*        P,                  ! 4       9   g   \&        P.                  ! V4      '       d   \&        P0                  ! V4      MRRR\*        P,                  ! 4       9   g   \&        P.                  ! V4      '       d   \&        P0                  ! V4      MRR\&        P0                  ! V4      RR\*        P,                  ! 4       9   g   \&        P.                  ! V
4      '       d   \&        P0                  ! V
4      MRR\&        P0                  ! V4      R\&        P0                  ! V4      R\&        P0                  ! V4      /,          pRRV/,          p\3        \&        P4                  ! V4      4      hR;p;p;p;p;p;p;ppR# u upi   + '       g   i     EL6; i) torchr   rT   r   rn   ro   rq   Nrt   r   r   r	   r
   r   r   r   r   r   r<   r   r   rV   refr   py16r>   zassert %(py21)srW   r   r   r   )z%(py16)s
{%(py16)s = %(py2)s
{%(py2)s = %(py0)s.max
}(%(py14)s
{%(py14)s = %(py5)s
{%(py5)s = %(py3)s.abs
}((%(py10)s
{%(py10)s = %(py6)s(%(py7)s, %(py8)s)
} - %(py11)s))
})
} < %(py19)s)pytestimportorskipr   r   r   r   r   r   r   no_gradtensorrx   r   r   squeezenumpyr   r   r   r   r   r    r!   r"   r#   r$   r%   )r&   r   r   r   r   r   r   aWbr   r'   r(   rJ   rZ   rK   @py_assert15rL   r-   rN   r\   s   &                    r3   test_matches_torch_reference(TestForward.test_matches_torch_referenceK   s   ##G,ii##A&KKARaMK2 3t9q=)
 * ZZc!edg(>Z?ZZcUZ46) 	 

 ]]__Qmm4AJJq<<#44u||AFG 99R=6)002C	 
 vvBbffB[3Bc9Bf9:Bv:;BdB;dBBBBB;dBBBBBBrBBBBrBBBvBBBBBBbBBBBbBBBfBBBBBB[BBBB[BBBBBBBBBBBBBBBBBBFBBBBFBBB3BBBBBBcBBBBcBBB:BBB;BBBdBBBBBBBBB

 __s   4ARBR  R1	rb   N)
rc   rd   re   rf   r   r   r   r   rg   rh   ri   s   @r3   rl   rl   %   s      -$-5
C Cr6   rl   )__doc__builtinsr    _pytest.assertion.rewrite	assertionrewriter   r   r   r   strategies.strategy_mlp_scoresr   r   r   rl   rb   r6   r3   <module>r      s0        =( ( 5C 5Cr6   