app.metrics module

class app.metrics.CitationNetwork(G, weighting_methods=('forward_cites', 'h_index'), quality=True, h_index=True, custom_centrality=False, knowledge=True, k_depth=10, discount=0.5)[source]

Bases: object

Tracks the graph and meta-attributes for any citation network

Initializes the CitationNetwork

Parameters:
  • G – the citation graph
  • weighting_methods – the primary importance weighting methods for the knowledge impact metric
  • quality – whether to use the quality metric
  • h_index – whether to use the h_index
  • custom_centrality – whether to use custom_centrality
  • knowledge – whether to calculate knowledge impact
  • k_depth – maximum depth for knowledge evaluation
draw()[source]

Draws the network

eval_all(weighting_keys=None, verbose=True, file_early=None, knowledge=True)[source]

Calculates all custom metrics, if requested during instantiation

Parameters:
  • weighting_keys – the preferred weighting key to use for knowledge impact
  • verbose – whether or not to log progress
eval_centrality()[source]

calculates the centrality and set it as a node attribute

eval_h()[source]

calculates the h_index and set it as a node attribute

eval_k(weighting_keys, verbose=False)[source]

Evaluates the knowledge impact metric for every node and saves as node attribute :param weighting_keys: the quality metric to use as a weight :param verbose: whether or not to print out progress, as opposed to using the ticker

eval_quality()[source]

determines patent quality with established metrics; saves metrics as node attributes

file_custom_metrics(filename)[source]

Files the calculated metrics in a CSV :param filename: the filename

get_successors_recursively(patent, max_depth, depth)[source]
static h_index(m)[source]

Calculates the h index for a list of values :param m: list of values :return: the h-index

k(root, node, weighting_keys, depth, verbose=False)[source]

Recursively calculates the knowledge impact for a single node

\(K_i = W_i + \sum_{j=1}^{n_i} \lambda P_jK_{j}\)

Parameters:
  • root – the root node
  • node – the current node
  • weighting_keys – the quality weighting key to use for knowledge impact
  • depth – the current search depth
  • verbose – whether or not to print progress to stdout
Returns:

a dictionary containing the total knowledge impact score keyed by the weighting metric used

make_df(features, data)[source]
static make_knowledge_name(weighting_key)[source]
p(root, node)[source]
print_custom_metrics()[source]

Summarize the calculated metrics

root_analysis(depth, filename, allow_external=False, limit=None, bin_size=20)[source]

Instead of evaluating knowledge impact within the network (breadth-first), conducts a depth-first calculation for every node in the network up to some limit. Then, calculate knowledge impact in bins of a given size by time. Write time-series results to a file.

Parameters:
  • depth – the depth of the search (how many generations of children to examine)
  • filename – the filename to save results
  • limit – the maximum number of nodes to evaluate
  • bin_size – the size of the time bins in weeks
  • allow_external – whether or not to allow external patents in the analysis
  • query – a query to help speed up feature querying, if no external patents allowed
static str_to_datetime(date)[source]
summary()[source]

Prints summary statistics for the graph metrics

write_graphml(filepath)[source]

Writes the graph to a graphml file

Parameters:filepath (str) – the filename to store, as generated by a QueryMunger instance
class app.metrics.GraphSearchTracker[source]

Bases: object

is_visited(val)[source]
reset(already_visited=[])[source]
class app.metrics.TreeCitationNetwork(G, root, weighting_methods=('h_index', 'forward_cites'), k_depth=10, quality=True, h_index=True, custom_centrality=False, knowledge=True)[source]

Bases: app.metrics.CitationNetwork

A special variation on the CitationNetwork built specifically to track the descendants of a single patent.

draw()

Draws the network

eval_all(weighting_keys=None, verbose=True, file_early=None, knowledge=True)

Calculates all custom metrics, if requested during instantiation

Parameters:
  • weighting_keys – the preferred weighting key to use for knowledge impact
  • verbose – whether or not to log progress
eval_binned(bin_size_weeks, plot=False, weighting_keys=['h_index', 'forward_cites'])[source]

Evaluates knowledge impact in time-based bins.

Parameters:
  • bin_size_weeks – the bin size in weeks
  • plot – whether or not to display a plot of knowledge over time
  • weighting_keys – the weighting key for knowledge impact calculation
Returns:

a list of knowledge impact metrics, one for each bin

eval_centrality()

calculates the centrality and set it as a node attribute

eval_h()

calculates the h_index and set it as a node attribute

eval_k(weighting_keys, verbose=False)

Evaluates the knowledge impact metric for every node and saves as node attribute :param weighting_keys: the quality metric to use as a weight :param verbose: whether or not to print out progress, as opposed to using the ticker

eval_quality()

determines patent quality with established metrics; saves metrics as node attributes

file_custom_metrics(filename)

Files the calculated metrics in a CSV :param filename: the filename

get_successors_recursively(patent, max_depth, depth)
static h_index(m)

Calculates the h index for a list of values :param m: list of values :return: the h-index

is_empty()[source]
k(root, node, weighting_keys, depth, verbose=False)

Recursively calculates the knowledge impact for a single node

\(K_i = W_i + \sum_{j=1}^{n_i} \lambda P_jK_{j}\)

Parameters:
  • root – the root node
  • node – the current node
  • weighting_keys – the quality weighting key to use for knowledge impact
  • depth – the current search depth
  • verbose – whether or not to print progress to stdout
Returns:

a dictionary containing the total knowledge impact score keyed by the weighting metric used

make_df(features, data)
static make_knowledge_name(weighting_key)
p(root, node)
print_custom_metrics()

Summarize the calculated metrics

root_analysis(depth, filename, allow_external=False, limit=None, bin_size=20)

Instead of evaluating knowledge impact within the network (breadth-first), conducts a depth-first calculation for every node in the network up to some limit. Then, calculate knowledge impact in bins of a given size by time. Write time-series results to a file.

Parameters:
  • depth – the depth of the search (how many generations of children to examine)
  • filename – the filename to save results
  • limit – the maximum number of nodes to evaluate
  • bin_size – the size of the time bins in weeks
  • allow_external – whether or not to allow external patents in the analysis
  • query – a query to help speed up feature querying, if no external patents allowed
static str_to_datetime(date)
summary()[source]

Prints summary statistics for the graph metrics

write_graphml(filepath)

Writes the graph to a graphml file

Parameters:filepath (str) – the filename to store, as generated by a QueryMunger instance