-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStartUp.py
141 lines (119 loc) · 3.34 KB
/
StartUp.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# -*- coding: utf-8 -*-
# load typical modules
import numpy as np
import pandas as pd
#from dionysus import *
#from dionysus import *
#from dionysus.viewer import *
import matplotlib.pyplot as plt
from subprocess import call
import webbrowser
import os
import heapq
#%matplotlib inline
# load created modules
from generateData import sineData
from slideWindowsNoInterp import getSlidingWindow
from plottingPersistence import plotPersistence
from timeDelayEmbedding import embed
#from generateHomology import *
# generate some data
wavelength=3
V = sineData(0, 10, 200, wavelength, std_dev=0.1)
#V=incomSineData(0,20,200,5)
plt.plot(V[:,0],V[:,1])
# slide ya window 1 0.1713 inf -- 1 0.169524 inf
#dim = 20
#Tau = 1
#dT = 1
#X = getSlidingWindow(V[:,1], dim, Tau, dT)
#resolution = V.shape[0]
#tauWidth = int(resolution*0.5)
taumax = 50#np.argmin(V[:,1])+ tauWidth
elen = 100
dt = 40 #np.argmin(V[:wavelength*resolution/10,1])
X = embed(V[:,1], taumax, elen, dt)
#plt.plot(np.linspace(0,taumax-dt+2,X.shape[1]),X[2,:])
#plt.plot(np.linspace(0,elen,X.shape[0]),X[:,2])
# write the data to a txt
#float_formatter = lambda x: "%.19f" % x
#X = float_formatter(X)
X.astype('float64', order='C')
np.savetxt('data.txt', X, fmt='%0.19f')
#%matplotlib inline
# generate some data
#V = cosineData(0, 10, 100, std_dev=0.001)
# slide ya window 1 0.1713 inf -- 1 0.169524 inf
#dim = 8
#Tau = 1
#dT = 1
#X = getSlidingWindow(V[:,1], dim, Tau, dT)
#extent = Tau*dim
# write the data to a txt
#X.astype('float64', order='C')
#np.savetxt('data.txt', X)
# remove old files
try:
os.remove('points-1.val')
except OSError:
pass
try:
os.remove('points-1.ccl')
except OSError:
pass
try:
os.remove('points-0.val')
except OSError:
pass
try:
os.remove('points-0.pdf')
except OSError:
pass
try:
os.remove('points-0.ccl')
except OSError:
pass
try:
os.remove('points.vrt')
except OSError:
pass
try:
os.remove('points.dgm')
except OSError:
pass
try:
os.remove('points.bdry')
except OSError:
pass
print("Removed files")
# run cohomolgy on data
max_distance = 4
max_distance = 1.5
skeleton = 2
data_file = 'data.txt' #'sample2noComma.txt'
max_distance = str(max_distance)
skeleton = str(skeleton)
path = './rips-pairwise-cohomology ' + data_file + ' -m '+ max_distance +' -s ' + skeleton + ' -b points.bdry -c points -v points.vrt -d points.dgm'
call([path], shell=True)
print("Built Rips")
# plot persistence
dgm = pd.read_table('points.dgm', delim_whitespace=True)
dgmMax = np.ceil(float(max(dgm.iloc[:,[2]])))
dgm = dgm.replace('inf', dgmMax*10)
dgm = dgm.as_matrix()
print("Top 10 max lifetimes: \n{0}".format("\n".join(str(x) for x in heapq.nlargest(10,dgm[:,2]-dgm[:,1]))))
#plotPersistence(dgm)
# assign each vertex of input to a circle valued function
a = call(['python2.7 cocycle.py points.bdry points-0.ccl points.vrt'], shell=True)
call(['python2.7 cocycle.py points.bdry points-1.ccl points.vrt'], shell=True)
if a==0:
print("Assigned vertex")
else:
print("Vertices not assigned to circle valued function. Exit")
# generate pdf to visulaize values assigned to points
vis_path = 'python2.7 plot.py points-0.val ' + data_file + ' scatter.py points-0.val points-1.val'
a = call([vis_path], shell=True)
if a==0:
print("Generated graphic")
# open pdf
webbrowser.open_new(r'file:/home/wilson/Documents/17_Spring/TDA/DelayEmbedding/points-0.pdf')