- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
Latest commit
54 lines (34 loc) · 1.39 KB
/
Copy pathexample.py
File metadata and controls
54 lines (34 loc) · 1.39 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
fromgpmod.predictimportdiffusion_SSL
fromgpmod.utilsimportload_labels
fromgpmod.utilsimportextract_seed_sets
importnumpyasnp
# create seeds by randomly sampling some of the true labels
y_true=load_labels('graphs/blogcat_label.lst')
num_seeds=1000
N=y_true.shape[0]
seed_indices=np.random.choice(range(N), size=num_seeds, replace=False )
seedset=extract_seed_sets(y_true, seed_indices)
# configure diffusion_SSL() predictor and
ssl=diffusion_SSL()
ssl.SetGraphDir('graphs') # NOTE_: this is already the default value
ssl.LoadGraph('blogcat')
ssl.SetNumClasses(y_true.shape[1])
# run default Personalized PageRank
ssl.SetBalancing_ON()
#ssl.SetBalancing_OFF()
predictions=ssl.SeedAndPredict(seedset)
# Get reference to soft label predictions attribute
# Run: predictions = np.array(ssl.SeedAndPredict(seedset)) to obtain local copy..
print( "\nPersonalized PageRank predictions", predictions,"\n")
# switch to Heat Kernel
ssl.SetPredictorType('hk')
ssl.SeedAndPredict(seedset)
print( "\nHeat Kernel predictions", predictions,"\n")
# customized diffusion
coefficients=np.array([ 1.0 , 2.0 , 3.0, 1.5, 0.0, 0.0, 0.0, 1.0, 1.0 ,1.0 ])
coefficients=coefficients/np.sum(coefficients)
ssl.SetPredictorType('custom')
ssl.SetNumSteps(len(coefficients))
ssl.InputCoefs(list(coefficients))
ssl.SeedAndPredict(seedset)
print( "\ncustom diffusion predictions", predictions,"\n")