RepTB_NBI_Algorithm_Snippet.ipynb
1.95 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"import csv\n",
"import numpy.matlib\n",
"from operator import itemgetter, attrgetter\n",
"from sklearn.model_selection import KFold\n",
"from sklearn.metrics import roc_curve, auc\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#NBI calculation for A (adjacent matrix)\n",
"\n",
"K = np.diag((1/sum(A))) # Create a diagonal matrix \n",
"n = A.shape[0] # Number of rows of adjacent martix A\n",
"m = A.shape[1] # Number of columns in adjacent matrix A\n",
"#print n, m, Ky.shape\n",
"K[np.isinf(K) | np.isnan(K)] = 0\n",
"kk = np.transpose(np.sum(A,1))\n",
"#print kx.shape\n",
"N = np.matlib.repmat(1/kk,n,1)\n",
"N[np.isinf(N) | np.isnan(N)] = 0\n",
"#kx[np.isinf(kx) | np.isnan(kx)] = 0\n",
"W = np.transpose(np.dot(A, K)) # Create the weight matrix \n",
"W1 = np.dot(A, W)\n",
"W2 = np.multiply(N, W1) # Create the scaled up weight matrix\n",
"print W2.shape\n",
"NBIscore = np.dot(W2, A) # Create the Final Resource matrix in accordance with (R = W.A)\n",
"print NBIscore.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}