This repository was archived by the owner on Jul 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredictor.py
More file actions
54 lines (43 loc) · 1.27 KB
/
predictor.py
File metadata and controls
54 lines (43 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2017-05-05
# @Author : Andrey Demidenko (worm2fed@mail.ru)
# @Version : 1.0
""" Module for Link Prediction
"""
__version__ = '1.0'
__author__ = 'Andrey Demidenko'
__docformat__ = 'reStructuredText'
class PredictorException(Exception):
""" Base class for errors in predictor module.
"""
def __init__(self, message):
self.message = message
def __str__(self):
return self.message
class Predictor():
""" Class for prediction
"""
def __init__(self):
""" Initialisation
"""
pass
def topology_predictor(self, coef, threshold, check_edges=None):
""" Predictor
:param coef: coefficient like common neighbours, Adamic/Adar,
Jaccaard, etc.
:param threshold: predictor threshold
:param check_edges: dict with edges to check prediction
:return: if `check_edges` is empty returns dict with edges,
otherwise dict with hits
"""
if check_edges is not None:
if isinstance(check_edges, dict):
return dict(enumerate(e for e in check_edges.values() \
if e in predicted_edges.values()))
else:
raise PredictorException('Error message: %s' % \
'check_edges should be <class \'dict\'>')
else:
return dict(enumerate(map(lambda x: set(x[0]), \
coef.most_common(threshold))))