+
    �°³j‚  ã                   ó–   € R t ^ RIt^ RIHt R.t]! R4      ]! R4      ]P                  ! RRR^/R7      RRRR/R	 l4       4       4       tR# )
zTime dependent algorithms.N)Únot_implemented_forÚcd_indexÚ
undirectedÚ
multigraphÚtimeÚweight)Ú
node_attrsc          	     ó:  a aaa€ \         ;QJ d     V V3R lS  4       F  '       d   K   RM	  RM! V V3R lS  4       4      '       g   \        P                  ! R4      h S P                  S,          S,          V,           pS P                  S,           Uu0 uF&  pS P                  V,          S,          V8:  g   K$  VkK(  	  ppT Uau. uFW  o\
        ;QJ d'    T T3R lS S,           4       F  '       g   K   RM	  RM! T T3R lS S,           4       4      '       d   RM^NKY  	  pp\        TP                  ! T T3R lS S,           4       !  4      p	T	^ 8X  d   \        P                  ! R4      hTf$   \        \        R	 T 4       4      T	,          ^4      # T Uu. uF&  pS P                  T,          P                  T^4      NK(  	  p
p\        \        R
 \        YŠ4       4       4      T	,          ^4      # u upi    \        P                  ! R4      h; iu upi u upi )a¿  Compute the CD index for `node` within the graph `G`.

Calculates the CD index for the given node of the graph,
considering only its predecessors who have the `time` attribute
smaller than or equal to the `time` attribute of the `node`
plus `time_delta`.

Parameters
----------
G : graph
   A directed networkx graph whose nodes have `time` attributes and optionally
   `weight` attributes (if a weight is not given, it is considered 1).
node : node
   The node for which the CD index is calculated.
time_delta : numeric or timedelta
   Amount of time after the `time` attribute of the `node`. The value of
   `time_delta` must support comparison with the `time` node attribute. For
   example, if the `time` attribute of the nodes are `datetime.datetime`
   objects, then `time_delta` should be a `datetime.timedelta` object.
time : string (Optional, default is "time")
    The name of the node attribute that will be used for the calculations.
weight : string (Optional, default is None)
    The name of the node attribute used as weight.

Returns
-------
float
   The CD index calculated for the node `node` within the graph `G`.

Raises
------
NetworkXError
   If not all nodes have a `time` attribute or
   `time_delta` and `time` attribute types are not compatible or
   `n` equals 0.

NetworkXNotImplemented
    If `G` is a non-directed graph or a multigraph.

Examples
--------
>>> from datetime import datetime, timedelta
>>> G = nx.DiGraph()
>>> nodes = {
...     1: {"time": datetime(2015, 1, 1)},
...     2: {"time": datetime(2012, 1, 1), "weight": 4},
...     3: {"time": datetime(2010, 1, 1)},
...     4: {"time": datetime(2008, 1, 1)},
...     5: {"time": datetime(2014, 1, 1)},
... }
>>> G.add_nodes_from([(n, nodes[n]) for n in nodes])
>>> edges = [(1, 3), (1, 4), (2, 3), (3, 4), (3, 5)]
>>> G.add_edges_from(edges)
>>> delta = timedelta(days=5 * 365)
>>> nx.cd_index(G, 3, time_delta=delta, time="time")
0.5
>>> nx.cd_index(G, 3, time_delta=delta, time="time", weight="weight")
0.12

Integers can also be used for the time values:
>>> node_times = {1: 2015, 2: 2012, 3: 2010, 4: 2008, 5: 2014}
>>> nx.set_node_attributes(G, node_times, "new_time")
>>> nx.cd_index(G, 3, time_delta=4, time="new_time")
0.5
>>> nx.cd_index(G, 3, time_delta=4, time="new_time", weight="weight")
0.12

Notes
-----
This method implements the algorithm for calculating the CD index,
as described in the paper by Funk and Owen-Smith [1]_. The CD index
is used in order to check how consolidating or destabilizing a patent
is, hence the nodes of the graph represent patents and the edges show
the citations between these patents. The mathematical model is given
below:

.. math::
    CD_{t}=\frac{1}{n_{t}}\sum_{i=1}^{n}\frac{-2f_{it}b_{it}+f_{it}}{w_{it}},

where `f_{it}` equals 1 if `i` cites the focal patent else 0, `b_{it}` equals
1 if `i` cites any of the focal patents successors else 0, `n_{t}` is the number
of forward citations in `i` and `w_{it}` is a matrix of weight for patent `i`
at time `t`.

The `datetime.timedelta` package can lead to off-by-one issues when converting
from years to days. In the example above `timedelta(days=5 * 365)` looks like
5 years, but it isn't because of leap year days. So it gives the same result
as `timedelta(days=4 * 365)`. But using `timedelta(days=5 * 365 + 1)` gives
a 5 year delta **for this choice of years** but may not if the 5 year gap has
more than 1 leap year. To avoid these issues, use integers to represent years,
or be very careful when you convert units of time.

References
----------
.. [1] Funk, Russell J., and Jason Owen-Smith.
       "A dynamic network measure of technological change."
       Management science 63, no. 3 (2017): 791-817.
       http://russellfunk.org/cdindex/static/papers/funk_ms_2017.pdf

c              3   óP   <"  € T F  pSSP                   V,          9   x € K  	  R # 5i©N)Únodes)Ú.0ÚnÚGr   s   & €€Úc/home/luca/screen-checking/.venv/lib/python3.14/site-packages/networkx/algorithms/time_dependent.pyÚ	<genexpr>Úcd_index.<locals>.<genexpr>q   s   øé € Ð-©1 aˆt�q—w‘w˜q•zÖ!«1ùs   ƒ#&FTz&Not all nodes have a 'time' attribute.zPAddition and comparison are not supported between 'time_delta' and 'time' types.c              3   ó:   <"  € T F  qSS,          9   x € K  	  R # 5ir   © )r   Újr   Úis   & €€r   r   r   €   s   øé € Ð.¡g ˜˜!�–9£gùs   ƒc              3   óv   <"  € T F.  pSP                   V,          P                  4       S0,
          x € K0  	  R # 5ir   )ÚpredÚkeys)r   Úsr   Únodes   & €€r   r   r   ƒ   s*   øé € ÐD¹G°q˜Ÿ™ �Ÿ™Ó)¨T¨F×2Ò2»Gùs   ƒ69zThe cd index cannot be defined.c              3   ó$   "  € T F  qx € K  	  R # 5ir   r   )r   Úbis   & r   r   r   ‰   s   é € Ð(¡a œ£aùs   ‚c              3   ó6   "  € T F  w  rW,          x € K  	  R # 5ir   r   )r   r   Úwts   &  r   r   r   Ž   s   é € Ð?©¡V R˜Ÿš«ùs   ‚éÿÿÿÿ)ÚallÚnxÚNetworkXErrorr   r   ÚanyÚlenÚunionÚroundÚsumÚgetÚzip)r   r   Ú
time_deltar   r   Útarget_dater   r   Úbr   Úweightss   ff&d$ `    r   r   r   	   s¡  û€ ÷P ‹3Õ-©1Ó-�3�3Š3Õ-©1Ó-×-Ò-Ü×ÒÐGÓHÐHð	
à—g‘g˜d•m DÕ)¨JÕ6ˆàŸ6™6 $ž<ÓK™<�a¨1¯7©7°1­:°dÕ+;¸{Ñ+J—�™<ˆÐKñ @DÔD¹t¸!�s‹sÕ. a¨¦gÓ.�s�sŠsÕ. a¨¦gÓ.×.Ò.‰°AÒ	5¹t€AÐDô 	ˆD�JŠJÕD¸A¸d¾GÓDÑEÓF€AØˆA„vÜ×ÒÐ@ÓAÐAð ‚~Ü”SÑ(¡aÓ(Ó(¨1Õ,¨aÓ0Ð0ñ 7;Ó;±d°�1—7‘7˜1•:—>‘> &¨!Ö,±dˆÐ;Ü”SÑ?¬s°1¬Ó?Ó?À!ÕCÀQÓGÐGùò- Løð
Ü×Òð ó
ð 	
üò 	Eùò <sB   Á6G8 Â!G3Â:G3Ã G8 ÃHÃHÃ6%HÄHÆ,HÇ3G8 Ç8H)Ú__doc__Únetworkxr"   Únetworkx.utilsr   Ú__all__Ú_dispatchabler   r   ó    r   Ú<module>r5      sm   ðÙ  ã Ý .àˆ,€ñ �\Ó"Ù�\Ó"Ø×Ò˜f d¨H°aÐ8Ô9ðBH¨&ð BH¸ó BHó :ó #ó #òBHr4   