Program Listing for File JaccardIndex.hpp

Return to documentation for file (include/networkit/linkprediction/JaccardIndex.hpp)

/*
 * JaccardIndex.hpp
 *
 *  Created on: 23.03.2015
 *      Author: Kolja Esders
 */

#ifndef NETWORKIT_LINKPREDICTION_JACCARD_INDEX_HPP_
#define NETWORKIT_LINKPREDICTION_JACCARD_INDEX_HPP_

#include <networkit/linkprediction/LinkPredictor.hpp>
#include <networkit/linkprediction/NeighborhoodUtility.hpp>

namespace NetworKit {

class JaccardIndex final : public LinkPredictor {
    double runImpl(node u, node v) override {
        const auto unionSize = NeighborhoodUtility::getNeighborsUnion(*G, u, v).size();
        if (unionSize == 0) {
            return 0;
        }
        return 1.0 * NeighborhoodUtility::getCommonNeighbors(*G, u, v).size() / unionSize;
    }

public:
    using LinkPredictor::LinkPredictor;
};

} // namespace NetworKit

#endif // NETWORKIT_LINKPREDICTION_JACCARD_INDEX_HPP_