forked from cipriancorneanu/dnn-topology
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualise.py
45 lines (37 loc) · 1.45 KB
/
visualise.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
import matplotlib.pyplot as plt
import scipy.ndimage
from bettis import *
import argparse
import os
from config import SAVE_PATH, MAX_EPSILON
parser = argparse.ArgumentParser()
parser.add_argument('--net')
parser.add_argument('--dataset')
parser.add_argument('--trial', default=0)
parser.add_argument('--epochs', nargs='+', type=int)
parser.add_argument('--dim', default=1, type=int)
args = parser.parse_args()
directory = os.path.join(SAVE_PATH, args.net+'_'+args.dataset+'/')
trial = 0
for epc in args.epochs:
# read persistent diagram from persistent homology output
birth, death = read_results(directory, epc, trl=args.trial, max_epsilon=MAX_EPSILON, dim=args.dim, persistence=0.02)
if len(birth) > 0:
# compute betti curve from persistent diagram
x, betti = pd2betti(birth, death)
# filter curve for improved visualization
filter_size = int(len(betti) / 10)
betti = scipy.ndimage.filters.uniform_filter1d(betti, size=filter_size, mode='constant')
# plor curve
plt.xlabel('$\epsilon$')
plt.ylabel('#cavities')
plt.plot(x, betti, label='epc_' + str(epc))
plt.legend()
plt.title('betti_{}'.format(args.dim))
# compute life and midlife
life = pd2life(birth, death)
midlife = pd2midlife(birth, death)
print('EPC = {}, LIFE = {}, MIDLIFE = {}'.format(epc, life, midlife))
else:
print('The persistence diagram is empty!')
plt.show()