cd_index#
- cd_index(G, node, time_delta, *, time='time', weight=None)[source]#
Compute the CD index for
node
within the graphG
.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 thetime
attribute of thenode
plustime_delta
.- Parameters:
- Ggraph
A directed networkx graph whose nodes have
time
attributes and optionallyweight
attributes (if a weight is not given, it is considered 1).- nodenode
The node for which the CD index is calculated.
- time_deltanumeric or timedelta
Amount of time after the
time
attribute of thenode
. The value oftime_delta
must support comparison with thetime
node attribute. For example, if thetime
attribute of the nodes aredatetime.datetime
objects, thentime_delta
should be adatetime.timedelta
object.- timestring (Optional, default is “time”)
The name of the node attribute that will be used for the calculations.
- weightstring (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 graphG
.
- Raises:
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:
\[CD_{t}=\frac{1}{n_{t}}\sum_{i=1}^{n}\frac{-2f_{it}b_{it}+f_{it}}{w_{it}},\]where
f_{it}
equals 1 ifi
cites the focal patent else 0,b_{it}
equals 1 ifi
cites any of the focal patents successors else 0,n_{t}
is the number of forward citations ini
andw_{it}
is a matrix of weight for patenti
at timet
.The
datetime.timedelta
package can lead to off-by-one issues when converting from years to days. In the example abovetimedelta(days=5 * 365)
looks like 5 years, but it isn’t because of leap year days. So it gives the same result astimedelta(days=4 * 365)
. But usingtimedelta(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
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