Skip to content

Instantly share code, notes, and snippets.

@macleginn
Last active February 11, 2022 12:01
Show Gist options
  • Save macleginn/47ae09bdaf9d445ed394c23be39c1baa to your computer and use it in GitHub Desktop.
Save macleginn/47ae09bdaf9d445ed394c23be39c1baa to your computer and use it in GitHub Desktop.
A step in the simulation of random feature spread on a network guided by NPM
import numpy as np
# We're given an n by n distance matrix *D* with transfer
# probabilities for a given pair of nodes (for any feature),
# a feature matrix *M*, and a dropout probability p_d.
# We convert the transfer probabilities to no-transfer probabilities
# and take their logs
L = np.log(1 - D)
# No-transfer probabilities after considering all node pairs
LogNoTransfer = np.matmul(L, M)
NoTransfer = np.exp(LogNoTransfer)
Transfer = 1 - NoTransfer
# Update M
for i in range(M.shape[0]):
for j in range(M.shape[1]):
M[i,j] = max(M[i,j], np.random.binomial(1, Transfer[i,j]))
# Apply dropout
for i in range(M.shape[0]):
for j in range(M.shape[1]):
M[i,j] = min(M[i,j], M[i,j] * np.random.binomial(1, 1 - p_d))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment