Class AbstractLinkPredictor<U>

java.lang.Object
es.uam.eps.ir.relison.links.linkprediction.AbstractLinkPredictor<U>
Type Parameters:
U - type of the users.
All Implemented Interfaces:
LinkPredictor<U>
Direct Known Subclasses:
InstancePostfixExLinkPredictor, RecommendationLinkPredictor, SupervisedLinkPredictor

public abstract class AbstractLinkPredictor<U>
extends java.lang.Object
implements LinkPredictor<U>
Abstract definition of a link prediction algorithm.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    private java.util.Comparator<org.ranksys.core.util.tuples.Tuple2od<Pair<U>>> comparator
    The comparator of pairs to return a sorted list.
    private Graph<U> graph
    The social network.
  • Constructor Summary

    Constructors 
    Constructor Description
    AbstractLinkPredictor​(Graph<U> graph)
    Constructor.
    AbstractLinkPredictor​(Graph<U> graph, java.util.Comparator<org.ranksys.core.util.tuples.Tuple2od<Pair<U>>> comparator)
    Constructor.
  • Method Summary

    Modifier and Type Method Description
    protected java.util.Comparator<org.ranksys.core.util.tuples.Tuple2od<Pair<U>>> getComparator()
    Obtains the comparator for ordering the nodes.
    protected Graph<U> getGraph()
    Obtains the graph over which we execute the link prediction algorithm
    Prediction<U> getPrediction()
    Given a social network, ranks the possible user-user pairs, according to the scores given by the algorithm.
    Prediction<U> getPrediction​(int maxLength)
    Given a social network, ranks the possible user-user pairs, according to the scores given by the algorithm and returns the a limited set of them.
    abstract Prediction<U> getPrediction​(int maxLength, java.util.function.Predicate<Pair<U>> filter)
    Given a social network, ranks the possible user-user pairs, according to the scores given by the algorithm.
    Prediction<U> getPrediction​(java.util.function.Predicate<Pair<U>> filter)
    Given a social network, ranks the possible user-user pairs, according to the scores given by the algorithm.
    Prediction<U> getPrediction​(java.util.stream.Stream<Pair<U>> candidates)
    Given a social network, ranks the possible user-user pairs, according to the scores given by the algorithm.
    double getPredictionScore​(U u, U v)
    Obtains the prediction score for a pair of candidates.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • graph

      private final Graph<U> graph
      The social network.
    • comparator

      private final java.util.Comparator<org.ranksys.core.util.tuples.Tuple2od<Pair<U>>> comparator
      The comparator of pairs to return a sorted list.
  • Constructor Details

    • AbstractLinkPredictor

      public AbstractLinkPredictor​(Graph<U> graph, java.util.Comparator<org.ranksys.core.util.tuples.Tuple2od<Pair<U>>> comparator)
      Constructor.
      Parameters:
      graph - the social network.
      comparator - a comparator for reordering the pairs.
    • AbstractLinkPredictor

      public AbstractLinkPredictor​(Graph<U> graph)
      Constructor. By default, sorts the pairs in descending score order.
      Parameters:
      graph - the social network.
  • Method Details

    • getPrediction

      public Prediction<U> getPrediction()
      Description copied from interface: LinkPredictor
      Given a social network, ranks the possible user-user pairs, according to the scores given by the algorithm.
      Specified by:
      getPrediction in interface LinkPredictor<U>
      Returns:
      a sorted list containing the user-user pairs and the link prediction score (in descending score order).
    • getPrediction

      public Prediction<U> getPrediction​(int maxLength)
      Description copied from interface: LinkPredictor
      Given a social network, ranks the possible user-user pairs, according to the scores given by the algorithm and returns the a limited set of them.
      Specified by:
      getPrediction in interface LinkPredictor<U>
      Parameters:
      maxLength - the maximum size of the link prediction list.
      Returns:
      a sorted list containing the user-user pairs and the link prediction score (in descending score order).
    • getPrediction

      public Prediction<U> getPrediction​(java.util.function.Predicate<Pair<U>> filter)
      Description copied from interface: LinkPredictor
      Given a social network, ranks the possible user-user pairs, according to the scores given by the algorithm. It only ranks those user pairs which pass a given filter.
      Specified by:
      getPrediction in interface LinkPredictor<U>
      Parameters:
      filter - a filter to indicate which user pairs shall be ranked.
      Returns:
      a sorted list containing the user-user pairs and the link prediction score (in descending score order).
    • getPrediction

      public abstract Prediction<U> getPrediction​(int maxLength, java.util.function.Predicate<Pair<U>> filter)
      Description copied from interface: LinkPredictor
      Given a social network, ranks the possible user-user pairs, according to the scores given by the algorithm. It only ranks those user pairs which pass a given filter. It returns a limited number of such pairs.
      Specified by:
      getPrediction in interface LinkPredictor<U>
      Parameters:
      maxLength - the maximum size of the link prediction list.
      filter - a filter to indicate which user pairs shall be ranked.
      Returns:
      a sorted list containing the user-user pairs and the link prediction score (in descending score order).
    • getPrediction

      public Prediction<U> getPrediction​(java.util.stream.Stream<Pair<U>> candidates)
      Description copied from interface: LinkPredictor
      Given a social network, ranks the possible user-user pairs, according to the scores given by the algorithm. It only ranks the received user pairs.
      Specified by:
      getPrediction in interface LinkPredictor<U>
      Parameters:
      candidates - a stream containing the user pairs to rank.
      Returns:
      a sorted list containing the user-user pairs and the link prediction score (in descending score order).
    • getPredictionScore

      public double getPredictionScore​(U u, U v)
      Description copied from interface: LinkPredictor
      Obtains the prediction score for a pair of candidates.
      Specified by:
      getPredictionScore in interface LinkPredictor<U>
      Parameters:
      u - first user in the pair.
      v - second user in the pair.
      Returns:
      the prediction score.
    • getGraph

      protected Graph<U> getGraph()
      Obtains the graph over which we execute the link prediction algorithm
      Returns:
      the graph.
    • getComparator

      protected java.util.Comparator<org.ranksys.core.util.tuples.Tuple2od<Pair<U>>> getComparator()
      Obtains the comparator for ordering the nodes.
      Returns:
      the comparator.