Created
March 17, 2015 19:00
-
-
Save mazieres/9d11ca85f5e0227d5fca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
def wannabe_projection(df): | |
''' | |
https://stats.stackexchange.com/questions/142132/is-this-a-valid-method-for-unipartite-projection-of-a-bipartite-graph | |
''' | |
n_samples = df.shape[0] | |
res = np.zeros((n_samples, n_samples)) | |
index = df.index | |
df = df.T | |
i = 0 | |
while i < n_samples: | |
j = 0 | |
while j < n_samples: | |
if i == j: | |
res[i][j] = 0 | |
else: | |
res[i][j] = df[[index[i], index[j]]].min(axis=1).sum() | |
j += 1 | |
i += 1 | |
return pd.DataFrame(res, index=df.index, columns=df.index) | |
if __name__ == '__main__': | |
# X = np.array([[1, 8, 3], [5, 2, 0], [0, 4, 2]]) | |
# df = pd.DataFrame(X, index=['A','B','C'], columns=['x','y','z']) | |
X = np.array([[0,1,3],[2,4,6]]) | |
df = pd.DataFrame(X, index=['A','B'], columns=['x','y','z']) | |
print wannabe_projection(df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment