FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
intervals/plot_gap_distribution.py at master · geometryprocessing/intervals · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
geometryprocessing
/
intervals
Public
Notifications
You must be signed in to change notification settings
Fork
2
Star
4
Code
Issues
1
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
intervals
/
plot_gap_distribution.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
177 lines (147 loc) · 5.85 KB
Breadcrumbs
intervals
/
plot_gap_distribution.py
Copy path
File metadata and controls
177 lines (147 loc) · 5.85 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import
matplotlib
as
mpl
mpl
.
use
(
'Agg'
)
from
fractions
import
Fraction
import
numpy
as
np
import
matplotlib
.
pyplot
as
plt
from
matplotlib
.
ticker
import
FixedLocator
import
platform
import
sys
import
math
import
statistics
try
:
import
cPickle
as
pickle
except
ImportError
:
# Python 3.x
import
pickle
test_names
=
[]
method_names
=
[]
colors
=
[
"#F78154"
,
"#1C3144"
,
"#2274A5"
,
"#32936F"
,
"#D00000"
,
"#FFBF00"
,
"#8D2AB7"
,
"#27182E"
,
"#232534"
]
# the ones that we actually care about, in this case we care about distribution between 0 to 3
bin_size_comp
=
30
actual_bin_size_comp
=
50
# position 40 and 50 are for outliers and negative intervals
bins_comp
=
[
x
/
10.0
for
x
in
list
(
range
(
0
,
actual_bin_size_comp
+
1
,
1
))]
# < -16, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, >=3, placeholder, empty
bin_size_raw
=
22
# the ones that we actually care about, in this case we care about distribution between 10^-17 to 10^3
actual_bin_size_raw
=
23
# position 50 for outliers, position 60 for negatives
bins_raw
=
list
(
range
(
-
17
,
6
,
1
))
def
plot_raw
(
datas
,
test_name
,
system
=
"mac"
):
plt
.
rc
(
'xtick'
,
labelsize
=
7
)
# fontsize of the tick labels
plt
.
rc
(
'ytick'
,
labelsize
=
10
)
# fontsize of the tick labels
plt
.
rc
(
'legend'
,
fontsize
=
10
)
# fontsize of the tick labels
bar_width
=
0.5
/
(
len
(
datas
))
all_items
=
[]
for
item
in
datas
:
all_items
+=
datas
[
item
]
average
=
statistics
.
median
(
all_items
)
if
average
<=
0
:
average
=
sum
(
all_items
)
*
1.0
/
len
(
all_items
)
if
average
<=
0
:
average
=
math
.
pow
(
10
,
-
16
)
average_log
=
int
(
math
.
floor
(
math
.
log10
(
average
)))
limit_down
=
average_log
-
4
limit_up
=
average_log
+
4
count
=
0
bins
=
list
(
range
(
21
))
bins
=
[
x
*
0.5
+
limit_down
-
1
for
x
in
bins
]
# print(bins)
# print(len(bins))
negative_count
=
0
ax
=
plt
.
axes
()
ax
.
spines
[
'top'
].
set_visible
(
False
)
ax
.
spines
[
'right'
].
set_visible
(
False
)
plt
.
xlim
([
limit_down
-
1
,
limit_up
+
2.5
])
plt
.
ylim
([
0
,
100
])
plt
.
xticks
([
limit_down
-
1
]
+
list
(
range
(
limit_down
,
limit_up
+
2
)), [
r'$\leq10^{'
+
str
(
limit_down
)
+
r'}$'
]
+
[
r'$10^{'
+
str
(
x
)
+
r'}$'
for
x
in
list
(
range
(
limit_down
,
limit_up
))]
+
[
r'$\geq10^{'
+
str
(
limit_up
)
+
r'}$'
,
"EMPTY"
])
for
item
in
datas
:
belows
=
0
ranges
=
[
0
]
*
16
aboves
=
0
negatives
=
0
for
gap
in
datas
[
item
]:
if
gap
<
0
:
negatives
+=
1
elif
gap
==
0
:
belows
+=
1
else
:
## compute the log value
log_value
=
math
.
log10
(
gap
)
if
log_value
<=
limit_down
:
belows
+=
1
elif
log_value
>=
limit_up
:
aboves
+=
1
else
:
position
=
int
((
log_value
-
limit_down
)
*
2
)
ranges
[
position
]
+=
1
belows
=
belows
*
100.0
/
len
(
datas
[
item
])
ranges
=
[
x
*
100.0
/
len
(
datas
[
item
])
for
x
in
ranges
]
aboves
=
aboves
*
100.0
/
len
(
datas
[
item
])
negatives
=
negatives
*
100.0
/
len
(
datas
[
item
])
# print(belows)
# print(ranges)
# print(aboves)
# print(negatives)
bar
=
plt
.
bar
([
x
+
bar_width
/
2
+
bar_width
*
count
for
x
in
bins
], [
0
]
*
2
+
ranges
+
[
0
]
*
3
,
label
=
item
,
color
=
colors
[
count
],
alpha
=
1.0
,
width
=
bar_width
)
bar
=
plt
.
bar
([
x
+
bar_width
*
1
+
bar_width
*
2
*
count
for
x
in
bins
], [
belows
,
0
]
+
[
0
]
*
16
+
[
aboves
,
0
]
+
[
negatives
] ,
color
=
colors
[
count
],
alpha
=
1.0
,
width
=
bar_width
*
2
)
if
(
negatives
>
0
):
rect
=
bar
[
-
1
]
plt
.
text
(
limit_up
+
1.5
,
rect
.
get_height
(), (
'%s:
\n
%f'
%
(
item
,
negatives
)).
rstrip
(
'0'
).
rstrip
(
'.'
)
+
"%"
+
"
\n
\n
"
*
negative_count
,
ha
=
'center'
,
va
=
'bottom'
)
negative_count
+=
1
count
+=
1
plt
.
legend
(
prop
=
{
'size'
:
6
})
plt
.
title
(
test_name
)
# plt.show()
save_plot_name
=
"graphs/raw/"
+
test_name
+
"_gap_raw_"
+
system
+
".pdf"
plt
.
savefig
(
save_plot_name
,
bbox_inches
=
'tight'
,
pad_inches
=
0
,
dpi
=
200
)
plt
.
close
()
print
(
test_name
+
" raw interval size graph generated"
)
def
plot_comp
(
datas
,
test_name
,
system
=
"mac"
):
pass
def
compute_comparison
(
base
,
num
):
frac
=
1.0
if
(
base
==
0
and
num
==
0
):
frac
=
1
elif
(
base
==
0
and
num
!=
0
):
frac
=
999
elif
(
base
!=
0
and
num
==
0
):
frac
=
0
else
:
frac
=
float
(
num
/
base
)
return
frac
def
plot_data
(
file_name
,
system
=
"mac"
):
f
=
open
(
file_name
,
'r'
)
last_test_name
=
None
datas
=
{}
numerator
=
1
denominator
=
1
for
line
in
f
:
splitted
=
line
.
strip
().
split
(
", "
)
test_name
=
", "
.
join
(
splitted
[
1
:
-
2
])
method_name
=
splitted
[
-
2
]
if
last_test_name
!=
test_name
:
if
last_test_name
!=
None
:
plot_raw
(
datas
,
last_test_name
,
system
)
plot_comp
(
datas
,
last_test_name
,
system
)
## clear data
datas
=
{}
## set the new test name
last_test_name
=
test_name
method_names
.
clear
()
## put method name in dictionary
if
not
method_name
in
method_names
:
method_names
.
append
(
method_name
)
datas
[
method_name
]
=
[]
## get the gap size in numerator and denominator
if
(
len
(
splitted
[
-
1
].
split
(
"/"
))
==
2
):
numerator
=
int
(
splitted
[
-
1
].
split
(
"/"
)[
0
])
denominator
=
int
(
splitted
[
-
1
].
split
(
"/"
)[
1
])
else
:
numerator
=
int
(
splitted
[
-
1
].
split
(
"/"
)[
0
])
denominator
=
1
datas
[
method_name
].
append
(
float
(
Fraction
(
numerator
,
denominator
)))
plot_raw
(
datas
,
last_test_name
,
system
)
plot_comp
(
datas
,
last_test_name
,
system
)
def
main
():
plot_data
(
"build/gaps.txt"
,
str
(
platform
.
platform
()))
if
__name__
==
"__main__"
:
main
()
Back
|
FazBrowse Home
|
New Git URL