/
visibility.py
117 lines (98 loc) · 2.73 KB
/
visibility.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
"""Visibility Graph Script
This script allows the user to run a vsibility graph on data
This script requires requirements.txt.
This file can also be imported as a module and contains the following
functions:
* main - the main function of the script
"""
import math
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
from visibility_graph import visibility_graph
N = 100
start = 0
end = 2*math.pi
spacing = (end-start)/N
samples = np.arange(start, end, spacing)
def sin_f(x):
return math.sin(np.float(x))
def cos_f(x):
return math.cos(np.float(x))
def tan_f(x):
return math.tan(np.float(x))
def main():
# sine
#sin = np.vectorize(sin_f)
#series = sin(samples)
# cos
#cos = np.vectorize(cos_f)
#series = cos(samples)
# tan
#tan = np.vectorize(tan_f)
#series = tan(samples)
# normal
#series = np.random.normal(loc=6, scale=0.1, size=(N,1))
# binomial
#series = np.random.binomial(n=10, p=0.7, size=(N,1))
# Poisson
#series = np.random.poisson(lam=2, size=(N,1))
# Uniform
#series = np.random.uniform(size=(N, 1))
# Logistic
#series = np.random.logistic(loc=1, scale=2, size=(N, 1))
# Multi
series = np.random.multinomial(n=6, pvals=[1/6, 1/6, 1/6, 1/6, 1/6, 1/6])
# Exponential
#series = np.random.exponential(scale=2, size=(N, 1))
# Chi
#series = np.random.chisquare(df=2, size=(N, 1))
# Rayleigh
#series = np.random.rayleigh(scale=2, size=(N, 1))
# Pareto
#series = np.random.pareto(a=2, size=(N, 1))
# Zipf
#series = np.random.zipf(a=2, size=(N, 1))
g = visibility_graph(series)
# Circular
#pos = nx.circular_layout(g)
# Bipartite
#top = nx.bipartite.sets(g)[0]
#pos = nx.bipartite_layout(g, top)
# Kamada Kawai
#pos = nx.kamada_kawai_layout(g)
# Planar
#pos = nx.planar_layout(g)
# Random
#pos = nx.random_layout(g)
# Shell
shells = [[0], list(np.arange(1, len(g), 1))]
pos = nx.shell_layout(g, shells)
# Spring
#pos = nx.spring_layout(g)
# Spectral
#pos = nx.spectral_layout(g)
# Spiral
#pos = nx.spiral_layout(g)
# Multipartite
#pos = nx.multipartite_layout(g)
print(g.nodes())
print(g.edges())
x = list(g.nodes())
y = series
e = list(g.edges())
plt.stem(x,y)
plt.figure(1)
for edg in e:
plt.plot(edg, [y[(edg[0])], y[(edg[1])]])
plt.show()
plt.figure(2)
nx.draw(g,pos)
#nx.draw_networkx_labels(g,pos,font_size=7,font_family='sans-serif')
#nx.draw_networkx_edge_labels(g,pos,q_list,label_pos=0.3)
plt.show()
plt.figure(3)
plt.hist(y)
plt.show()
if __name__ == "__main__":
main()