Class LinkPredictor

Inheritance Relationships

Derived Types

Class Documentation

class LinkPredictor

Abstract base class for link predictors.

Subclassed by NetworKit::AdamicAdarIndex, NetworKit::AdjustedRandIndex, NetworKit::AlgebraicDistanceIndex, NetworKit::CommonNeighborsIndex, NetworKit::JaccardIndex, NetworKit::KatzIndex, NetworKit::NeighborhoodDistanceIndex, NetworKit::NeighborsMeasureIndex, NetworKit::PreferentialAttachmentIndex, NetworKit::ResourceAllocationIndex, NetworKit::SameCommunityIndex, NetworKit::TotalNeighborsIndex, NetworKit::UDegreeIndex, NetworKit::VDegreeIndex

Public Types

using prediction = std::pair<std::pair<node, node>, double>

Type of predictions.

Public Functions

LinkPredictor()
explicit LinkPredictor(const Graph &G)
Parameters:

G – The graph to work on

virtual ~LinkPredictor() = default

Default destructor.

virtual void setGraph(const Graph &newGraph)

Sets the graph to work on.

Parameters:

newGraph – The graph to work on

virtual double run(node u, node v)

Returns a score indicating the likelihood of a future link between the given nodes. Prior to calling this method a graph should be provided through the constructor or by calling setGraph. Note that only undirected graphs are accepted. There is also no lower or upper bound for scores and the actual range of values depends on the specific link predictor implementation. In case u == v a 0 is returned. If suitable this method might make use of parallelization to enhance performance.

Parameters:
  • u – First node in graph

  • v – Second node in graph

Returns:

a prediction-score indicating the likelihood of a future link between the given nodes

virtual std::vector<prediction> runOn(std::vector<std::pair<node, node>> nodePairs)

Executes the run-method on al given nodePairs and returns a vector of predictions. The result is a vector of pairs where the first element is the node-pair and it’s second element the corresponding score generated by the run-method. The method makes use of parallelization.

Parameters:

nodePairs – Node-pairs to run the predictor on

Returns:

a vector of pairs containing the given node-pair as the first element and it’s corresponding score as the second element. The vector is sorted ascendingly by node-pair

virtual std::vector<prediction> runAll()

Runs the link predictor on all currently unconnected node-pairs. Possible self-loops are also excluded. The method makes use of parallelization.

Returns:

a vector of pairs containing all currently unconnected node-pairs as the first elements and the corresponding scores as the second elements. The vector is sorted ascendingly by node-pair

Protected Attributes

const Graph *G

Graph to operate on.

bool validCache

Indicates whether a possibly used cache is valid.