{ "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 }