This repository has been archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsamplematrix.py
62 lines (46 loc) · 1.5 KB
/
samplematrix.py
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
import Erdos_Renyi as er
import json
import pandas as pd
import numpy as np
import pdb
import networkx as nx
import matplotlib.pyplot as plt
from Erdos_Renyi import get_W
# Parameters
p = 0.3
subset = 15
K = subset
#const = 60*60*24*7 # 1 week
# Load settings file
settings = json.load(open("settings.json","r"))
# Path to file
events_embd = settings["out_path"]+"concepts_date_embd.csv"
# Load events
print("Reading in data")
events = pd.read_csv(events_embd,header=None)
L = events.head(subset)
print("Calculating W from data")
W_real = er.get_W(L)
# Set to minimum of limit and shape of data (due to starting period with less events)
S_real = np.eye(K,dtype=np.int)
def resample_graph(N,data,K):
ld_network = er.LatentDistanceAdjacencyModel(K=K, L = None, dim=2, v=None, alpha=1.0, beta=1.0,kappa=1.0,p = p)
A,W = np.ones((K, K)), np.zeros((K, K))
for i in range(N):
if i%10 == 0: print(i)
ld_network.resample(data=data)
# Define weight model
weight_model = er.SpikeAndSlabGammaWeights(model = ld_network, parallel_resampling=False)
weight_model.A = A
weight_model.W = W
weight_model.resample_new(data=data)
A,W = [weight_model.A,weight_model.W]
return weight_model
weight_model = resample_graph(N=20,data=[S_real,W_real],K=K)
# Print adjecancy matrix and it's properties
print(weight_model.A)
print(sum(weight_model.A))
print(max(sum(weight_model.A)))
def W_sample(A,W):
return A*W
print(W_sample(W_real,weight_model.A))