
    ph+              	       r   S r SSKrSSKJrJr  SSKJrJrJr  / SQr/ SQr	S	 r
 " S
 S\R                  5      rS r " S S\R                  5      r " S S\R                  " SSS/5      5      r " S S\R                  \R"                  5      r " S S\5      r/ SQr " S S\R                  5      rSS jrg)z=
Objects that represent structures used in actual causation.
    N   )cmpfmt   )	Directionconfigutils)alphastate	direction	mechanismpurview	partitionprobabilitypartitioned_probability)r
   r   r   r   r   r   c                 R    U S:  =(       a    [         R                  " U S5      (       + $ )zPReturn ``True`` if alpha is greater than zero, accounting for
numerical errors.
r   )r	   eqr
   s    W/home/james-whalen/.local/lib/python3.13/site-packages/pyphi/models/actual_causation.pygreater_than_zeror      s!     19/UXXeQ///    c                   h    \ rS rSrSr SS jrSrS/rS rS r	S	 r
\S
 5       rS rS rS rS rSrg)"AcRepertoireIrreducibilityAnalysis   a  A minimum information partition for ac_coef calculation.


These can be compared with the built-in Python comparison operators (``<``,
``>``, etc.). First, |alpha| values are compared. Then, if these are equal
up to |PRECISION|, the size of the mechanism is compared.

Attributes:
    alpha (float):
        This is the difference between the mechanism's unpartitioned and
        partitioned actual probability.
    state (tuple[int]):
        state of system in specified direction (cause, effect)
    direction (str):
        The temporal direction specifiying whether this analysis should be
        calculated with cause or effect repertoires.
    mechanism (tuple[int]):
        The mechanism to analyze.
    purview (tuple[int]):
        The purview over which the unpartitioned actual probability differs
        the least from the actual probability of the partition.
    partition (tuple[Part, Part]):
        The partition that makes the least difference to the mechanism's
        repertoire.
    probability (float):
        The probability of the state in the previous/next timestep.
    partitioned_probability (float):
        The probability of the state in the partitioned repertoire.
Nc
                 p    Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        Xl        g N)	r
   r   r   r   r   r   r   r   node_labels)
selfr
   r   r   r   r   r   r   r   r   s
             r   __init__+AcRepertoireIrreducibilityAnalysis.__init__;   s4     

"""&'>$&r    r   c                    [         R                  (       a6  U R                  [        U R                  5      [        U R
                  5      * /$ U R                  [        U R                  5      [        U R
                  5      /$ r   )r   PICK_SMALLEST_PURVIEWr
   lenr   r   r   s    r   order_by+AcRepertoireIrreducibilityAnalysis.order_byL   sT    ''JJDNN 3c$,,6G5GHH

C/T\\1BCCr   c                 8    [         R                  " X[        5      $ r   )r   
general_eq_acria_attributes_for_eqr   others     r   __eq__)AcRepertoireIrreducibilityAnalysis.__eq__R   s    ~~d+CDDr   c                 ,    [        U R                  5      $ )zKAn |AcRepertoireIrreducibilityAnalysis| is ``True`` if it has
|alpha > 0|.
r   r
   r%   s    r   __bool__+AcRepertoireIrreducibilityAnalysis.__bool__V        !,,r   c                     U R                   $ z.Alias for |alpha| for PyPhi utility functions.r   r%   s    r   phi&AcRepertoireIrreducibilityAnalysis.phi\        zzr   c                 L   ^  [        U 4S j[         5       5      n[        U5      $ )Nc              3   <   >#    U  H  n[        TU5      v   M     g 7fr   )getattr).0attrr   s     r   	<genexpr>>AcRepertoireIrreducibilityAnalysis.__hash__.<locals>.<genexpr>b   s     O6NdgdD))6Ns   )tupler*   hash)r   attrss   ` r   __hash__+AcRepertoireIrreducibilityAnalysis.__hash__a   s    O6NOOE{r   c                 L    [          Vs0 s H  o[        X5      _M     sn$ s  snf )*Return a JSON-serializable representation.)_acria_attributesr;   r   r=   s     r   to_json*AcRepertoireIrreducibilityAnalysis.to_jsone   s$    6GH6Gdgd))6GHHH   !c                 8    [         R                  " U [        5      $ r   )r   	make_reprrG   r%   s    r   __repr__+AcRepertoireIrreducibilityAnalysis.__repr__i   s    }}T#455r   c                 \    S[         R                  " [         R                  " U 5      5      -   $ )Nz!RepertoireIrreducibilityAnalysis
)r   indent
fmt_ac_siar%   s    r   __str__*AcRepertoireIrreducibilityAnalysis.__str__l   s$    4

3>>$/01 	2r   )	r
   r   r   r   r   r   r   r   r   r   )__name__
__module____qualname____firstlineno____doc__r   	__slots__unorderable_unless_eqr&   r-   r1   propertyr6   rC   rI   rN   rS   __static_attributes__r!   r   r   r   r      s[    @ "' I(MDE-  I62r   r   c                 "    [        U UUUS S S SS9$ )N        )r   r   r   r   r   r   r   r
   )r   )r   r   r   r   s       r   _null_ac_riar`   q   s'    - $	 	r   c                       \ rS rSrSrS r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       r\S
 5       rS rS r\R"                  rS rS rS rS rS rSrg)
CausalLink~   a  A maximally irreducible actual cause or effect.

These can be compared with the built-in Python comparison operators (``<``,
``>``, etc.). First, |alpha| values are compared. Then, if these are equal
up to |PRECISION|, the size of the mechanism is compared.
c                     Xl         g r   _ria)r   rias     r   r   CausalLink.__init__   s    	r   c                 .    U R                   R                  $ )zbfloat: The difference between the mechanism's unpartitioned and
partitioned actual probabilities.
)rf   r
   r%   s    r   r
   CausalLink.alpha   s    
 yyr   c                     U R                   $ r5   r   r%   s    r   r6   CausalLink.phi   r8   r   c                 .    U R                   R                  $ )z&Direction: Either |CAUSE| or |EFFECT|.)rf   r   r%   s    r   r   CausalLink.direction        yy"""r   c                 .    U R                   R                  $ )z;list[int]: The mechanism for which the action is evaluated.)rf   r   r%   s    r   r   CausalLink.mechanism   ro   r   c                 .    U R                   R                  $ )zGlist[int]: The purview over which this mechanism's |alpha| is
maximal.
)rf   r   r%   s    r   r   CausalLink.purview   s    
 yy   r   c                     U R                   $ )zTAcRepertoireIrreducibilityAnalysis: The irreducibility analysis for
this mechanism.
re   r%   s    r   rg   CausalLink.ria   s    
 yyr   c                 .    U R                   R                  $ r   )rf   r   r%   s    r   r   CausalLink.node_labels   s    yy$$$r   c                 2    [         R                  " U S/5      $ )Nrg   r   rM   r%   s    r   rN   CausalLink.__repr__   s    }}TE7++r   c                 p    S[         R                  " [         R                  " U R                  5      5      -   $ )NzCausalLink
)r   rQ   
fmt_ac_riarg   r%   s    r   rS   CausalLink.__str__   s#    

3>>$((+C DDDr   c                 6    U R                   R                  5       $ r   )rg   r&   r%   s    r   r&   CausalLink.order_by   s    xx  ""r   c                 4    U R                   UR                   :H  $ r   rg   r+   s     r   r-   CausalLink.__eq__   s    xx599$$r   c                 ,    [        U R                  5      $ r   )rA   rf   r%   s    r   rC   CausalLink.__hash__   s    DIIr   c                 ,    [        U R                  5      $ )z+An |CausalLink| is ``True`` if |alpha > 0|.r0   r%   s    r   r1   CausalLink.__bool__   s     ,,r   c                     SU R                   0$ )rF   rg   r   r%   s    r   rI   CausalLink.to_json   s    txx  r   re   N)rU   rV   rW   rX   rY   r   r\   r
   r6   r   r   r   rg   r   rN   rS   r   r[   r&   r-   rC   r1   rI   r]   r!   r   r   rb   rb   ~   s         # # # # ! !   % %,E 	+@@ #%-!r   rb   c                   (    \ rS rSrSr\S 5       rSrg)Event   zA mechanism which has both an actual cause and an actual effect.

Attributes:
    actual_cause (CausalLink): The actual cause of the mechanism.
    actual_effect (CausalLink): The actual effect of the mechanism.
c                     U R                   R                  U R                  R                  :X  d   eU R                   R                  $ )zThe mechanism of the event.)actual_causer   actual_effectr%   s    r   r   Event.mechanism   s<       **d.@.@.J.JJJJ  ***r   r!   N)rU   rV   rW   rX   rY   r\   r   r]   r!   r   r   r   r      s     + +r   r   r   r   c                       \ rS rSrSrS rS rS rS r\	R                  S 5       rS r\	R                  S	 5       r\S
 5       r\S 5       rS rS rS r\S 5       rSrg)Account   z`The set of |CausalLinks| with |alpha > 0|. This includes both actual
causes and actual effects.
c                 $    [        U5      U l        g r   )r@   causal_links)r   r   s     r   r   Account.__init__   s    !,/r   c                 ,    [        U R                  5      $ r   )r$   r   r%   s    r   __len__Account.__len__   s    4$$%%r   c                 ,    [        U R                  5      $ r   )iterr   r%   s    r   __iter__Account.__iter__       D%%&&r   c                      U R                   U   $ r   r   )r   is     r   __getitem__Account.__getitem__   s      ##r   c                 4    U R                   UR                   :H  $ r   r   r+   s     r   r-   Account.__eq__   s      E$6$666r   c                 ,    [        U R                  5      $ r   )rA   r   r%   s    r   rC   Account.__hash__   r   r   c                 R    U R                  U R                  UR                  -   5      $ r   )	__class__r   r+   s     r   __add__Account.__add__   s"    ~~d//%2D2DDEEr   c                 &    [        S U  5       5      $ )z0The set of irreducible causes in this |Account|.c              3   d   #    U  H&  nUR                   [        R                  L d  M"  Uv   M(     g 7fr   )r   r   CAUSEr<   links     r   r>   -Account.irreducible_causes.<locals>.<genexpr>   s'      ;dd)//9 Td   !0	0r@   r%   s    r   irreducible_causesAccount.irreducible_causes   s      ;d ; ; 	;r   c                 &    [        S U  5       5      $ )z1The set of irreducible effects in this |Account|.c              3   d   #    U  H&  nUR                   [        R                  L d  M"  Uv   M(     g 7fr   )r   r   EFFECTr   s     r   r>   .Account.irreducible_effects.<locals>.<genexpr>   s)      <dd)*:*:: Tdr   r   r%   s    r   irreducible_effectsAccount.irreducible_effects   s      <d < < 	<r   c                 2    [         R                  " U S/5      $ Nr   ry   r%   s    r   rN   Account.__repr__  s    }}TN#344r   c                 .    [         R                  " U 5      $ r   )r   fmt_accountr%   s    r   rS   Account.__str__  s    t$$r   c                     S[        U 5      0$ r   r   r%   s    r   rI   Account.to_json	  s    d,,r   c                     U " US   5      $ r   r!   )clsdcts     r   	from_jsonAccount.from_json  s    3~&''r   r   N)rU   rV   rW   rX   rY   r   r   r   r   r   sametyper-   rC   r   r\   r   r   rN   rS   rI   classmethodr   r]   r!   r   r   r   r      s    0&'$ 	\\7 7' 	\\F F ; ;
 < <
5%- ( (r   r   c                       \ rS rSrSrSrg)DirectedAccounti  zMThe set of |CausalLinks| with |alpha > 0| for one direction of a
transition.
r!   N)rU   rV   rW   rX   rY   r]   r!   r   r   r   r     s     	r   r   r
   r   accountpartitioned_account
transitioncutc                   v    \ rS rSrSr  SS jrS rS r\S 5       r	\S 5       r
S	/rS
 rS rS rS rS rSrg)AcSystemIrreducibilityAnalysisi  a  An analysis of transition-level irreducibility (|big_alpha|).

Contains the |big_alpha| value of the |Transition|, the causal account, and
all the intermediate results obtained in the course of computing them.

Attributes:
    alpha (float): The |big_alpha| value for the transition when taken
        against this analysis, *i.e.* the difference between the
        unpartitioned account and this analysis's partitioned account.
    account (Account): The account of the whole transition.
    partitioned_account (Account): The account of the partitioned
        transition.
    transition (Transition): The transition this analysis was calculated
        for.
    cut (ActualCut): The minimal partition.
Nc                 L    Xl         X l        X0l        X@l        XPl        X`l        g r   r   )r   r
   r   r   r   r   r   s          r   r   'AcSystemIrreducibilityAnalysis.__init__1  s!    
"#6 $r   c                 8    [         R                  " U [        5      $ r   )r   rM   _ac_sia_attributesr%   s    r   rN   'AcSystemIrreducibilityAnalysis.__repr__:  s    }}T#566r   c                 .    [         R                  " U 5      $ r   )r   rR   r%   s    r   rS   &AcSystemIrreducibilityAnalysis.__str__=  s    ~~d##r   c                 .    U R                   R                  $ )z5Return the actual previous state of the |Transition|.)r   before_stater%   s    r   r   +AcSystemIrreducibilityAnalysis.before_state@  s     +++r   c                 .    U R                   R                  $ )z4Return the actual current state of the |Transition|.)r   after_stater%   s    r   r   *AcSystemIrreducibilityAnalysis.after_stateE  s     ***r   r   c                 D    U R                   [        U R                  5      /$ r   )r
   r$   r   r%   s    r   r&   'AcSystemIrreducibilityAnalysis.order_byM  s    

C011r   c                 8    [         R                  " X[        5      $ r   )r   r)   r   r+   s     r   r-   %AcSystemIrreducibilityAnalysis.__eq__P  s    ~~d+=>>r   c                 ,    [        U R                  5      $ )zKAn |AcSystemIrreducibilityAnalysis| is ``True`` if it has
|big_alpha > 0|.
r0   r%   s    r   r1   'AcSystemIrreducibilityAnalysis.__bool__S  r3   r   c                     [        U R                  U R                  U R                  U R                  U R
                  45      $ r   )rA   r
   r   r   r   r   r%   s    r   rC   'AcSystemIrreducibilityAnalysis.__hash__Y  s6    TZZ--tXX   	 r   c                 L    [          Vs0 s H  o[        X5      _M     sn$ s  snf r   )r   r;   rH   s     r   rI   &AcSystemIrreducibilityAnalysis.to_json^  s$    6HI6Hdgd))6HIIIrK   )r   r
   r   r   r   r   )NNNNNN)rU   rV   rW   rX   rY   r   rN   rS   r\   r   r   r[   r&   r-   r1   rC   rI   r]   r!   r   r   r   r     sk    " <@@D7$ , , + + )M2?- 
Jr   r   c                     [        U UUSSS9$ )zUReturn an |AcSystemIrreducibilityAnalysis| with zero |big_alpha| and
empty accounts.
r!   )r   r   r
   r   r   )r   )r   r   r
   s      r   _null_ac_siar   b  s      * r   )r_   )rY   collections r   r   r   r   r	   rG   r*   r   	Orderabler   r`   rb   
namedtupler   Sequencer   r   r   r   r   r!   r   r   <module>r      s   
   ' 'L 6 0R2 R2j
K! K!\+K""7^_,MN +3(cmm[11 3(l	g 	+ @JS]] @JF
r   