-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsite_md.py
318 lines (251 loc) · 15.2 KB
/
website_md.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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
import os
import glob
def get_properties(property_file = 'Properties.csv'):
properties_dict = dict()
index_to_property_map = list()
# Min/Max matrix dimension
n_min = 10000
n_max = 0
with open(property_file, 'r') as f:
# Process header
header_line = next(f)
header_line = header_line.rstrip('\n')
header_line = header_line.split(',')
for i in range(len(header_line)):
properties_dict[header_line[i]] = dict()
index_to_property_map.append(header_line[i])
# Process OEIS
oeis_line = next(f)
oeis_line = oeis_line.rstrip('\n')
oeis_line = oeis_line.split(',')
for i in range(len(oeis_line)):
k = index_to_property_map[i]
properties_dict[k]['oeis'] = oeis_line[i]
# Process data
for line in f:
line = line.rstrip('\n')
line = line.split(',')
n_min = min(int(line[0]), n_min)
n_max = max(int(line[0]), n_max)
for i in range(len(line)):
k = index_to_property_map[i]
key_name = line[0]
properties_dict[k][key_name] = line[i]
return (properties_dict, n_min, n_max)
def get_properties_subsection(properties_dict, header_name, subproperties, n_min, n_max):
s = ''
# Header
s += '### {}\n\n'.format(header_name)
# Table header
s += '| Matrix Size |'
for ss in subproperties:
s += ' {} |'.format(ss)
s += '\n'
# Table separator
s += '| --- |'
for _ in subproperties:
s += ' --- |'
s += '\n'
# OEIS line
s += '| [__OEIS__](https://oeis.org/) |'
for ss in subproperties:
if properties_dict[ss]['oeis'] != '':
s += ' [__{0}__](https://oeis.org/{0})'.format(properties_dict[ss]['oeis'])
s += ' |'
s += '\n'
# Property values
for i in range(n_min, n_max+1):
s += '| {0}x{0} |'.format(i)
for ss in subproperties:
if properties_dict[ss][str(i)] == '':
s += ' |'
else:
s += ' {:,} |'.format(int(properties_dict[ss][str(i)]))
s += '\n'
s += '\n'
return s
def get_properties_section(data_dir,
property_file = 'Properties.csv'):
# Load properties from file
(properties_dict, n_min, n_max) = get_properties(property_file = property_file)
s = ''
# Properties header
s += '## Properties\n\n'
s += 'Download all properties: <a href=\"http://cpdb.bohemianmatrices.com/{}/Properties.csv\">Properties.csv</a>\n\n'.format(data_dir[:-5])
# ------------------------------------------------------------------------ #
# Characteristic Polynomials #
# ------------------------------------------------------------------------ #
header_name = 'Characteristic Polynomials'
subproperties = ['Number of Matrices',
'Number of Characteristic Polynomials',
'Number of Minimal Polynomials',
'Number of Non-Derogatory Matrices',
'Maximum Characteristic Height']
s += get_properties_subsection(properties_dict, header_name, subproperties, n_min, n_max)
# ------------------------------------------------------------------------ #
# Eigenvalues #
# ------------------------------------------------------------------------ #
header_name = 'Eigenvalues'
subproperties = ['Number of Distinct Eigenvalues',
'Number of Distinct Real Eigenvalues',
'Number of Distinct Purely Complex Eigenvalues',
'Number of Distinct Jordan Canonical Forms']
s += get_properties_subsection(properties_dict, header_name, subproperties, n_min, n_max)
# ------------------------------------------------------------------------ #
# Rank #
# ------------------------------------------------------------------------ #
header_name = 'Rank'
subproperties = ['Number of Singular Matrices',
'Number of Non-Singular Matrices']
for i in range(1, n_max+1):
subproperties.append('Number of Rank {} Matrices'.format(i))
s += get_properties_subsection(properties_dict, header_name, subproperties, n_min, n_max)
# ------------------------------------------------------------------------ #
# Determinant #
# ------------------------------------------------------------------------ #
header_name = 'Determinant'
subproperties = ['Number of Distinct Determinants',
'Maximum Determinant',
'Number of Unimodular Matrices']
s += get_properties_subsection(properties_dict, header_name, subproperties, n_min, n_max)
# ------------------------------------------------------------------------ #
# Miscellaneous #
# ------------------------------------------------------------------------ #
header_name = 'Miscellaneous'
subproperties = ['Number of Normal Matrices',
'Number of Rhapsodic Matrices',
'Number of Nilpotent Matrices',
'Number of Totally Unimodular Matrices',
'Number of Type I Stable Matrices',
'Number of Type II Stable Matrices']
s += get_properties_subsection(properties_dict, header_name, subproperties, n_min, n_max)
return s
def sizeof_fmt(num, suffix='B'):
for unit in ['','K','M','G','T','P','E','Z']:
if abs(num) < 1024.0:
return "%.0f%s%s" % (num, unit, suffix)
num /= 1024.0
return "%.0f%s%s" % (num, 'Y', suffix)
def get_data_section(data_dir, title):
s = ''
# Characteristic polynomials
s += '## Characteristic Polynomials\n\n'
s += 'Download all characteristic polynomials:\n'
# CharPolys.zip
fsize = sizeof_fmt(os.path.getsize('{}/CharPolys.zip'.format(data_dir)))
s += '- <a href=\"http://cpdb.bohemianmatrices.com/{}/CharPolys.zip\">CharPolys.zip</a> ({})\n'.format(data_dir, fsize)
# CharPolys.tar.gz
fsize = sizeof_fmt(os.path.getsize('{}/CharPolys.tar.gz'.format(data_dir)))
s += '- <a href=\"http://cpdb.bohemianmatrices.com/{}/CharPolys.tar.gz\">CharPolys.tar.gz</a> ({})\n\n'.format(data_dir, fsize)
# Char poly table
s += '| Matrix Size | .csv | .zip | .tar.gz |\n'
s += '| --- | --- | --- | --- |\n'
csv_fnames = list(glob.iglob('{}/CharPolys_*.csv'.format(data_dir), recursive=True))
n_min = min([int(c[-5]) for c in csv_fnames])
n_max = max([int(c[-5]) for c in csv_fnames])
for i in range(n_min, n_max+1):
s += '| {}x{} '.format(i, i)
fsize = sizeof_fmt(os.path.getsize('{}/CharPolys_{}x{}.csv'.format(data_dir, i, i)))
s += '| <a href="http://cpdb.bohemianmatrices.com/{}/CharPolys_{}x{}.csv">CharPolys_{}x{}.csv</a> ({})'.format(data_dir, i, i, i, i, fsize)
fsize = sizeof_fmt(os.path.getsize('{}/CharPolys_{}x{}.zip'.format(data_dir, i, i)))
s += '| <a href="http://cpdb.bohemianmatrices.com/{}/CharPolys_{}x{}.zip">CharPolys_{}x{}.zip</a> ({})'.format(data_dir, i, i, i, i, fsize)
fsize = sizeof_fmt(os.path.getsize('{}/CharPolys_{}x{}.tar.gz'.format(data_dir, i, i)))
s += '| <a href="http://cpdb.bohemianmatrices.com/{}/CharPolys_{}x{}.tar.gz">CharPolys_{}x{}.tar.gz</a> ({}) |\n'.format(data_dir, i, i, i, i, fsize)
s += '\n'
# Minimal polynomials
s += '## Minimal Polynomials\n\n'
s += 'Download all minimal polynomials:\n'
# MinPolys.zip
fsize = sizeof_fmt(os.path.getsize('{}/MinPolys.zip'.format(data_dir)))
s += '- <a href=\"http://cpdb.bohemianmatrices.com/{}/MinPolys.zip\">MinPolys.zip</a> ({})\n'.format(data_dir, fsize)
# MinPolys.tar.gz
fsize = sizeof_fmt(os.path.getsize('{}/MinPolys.tar.gz'.format(data_dir)))
s += '- <a href=\"http://cpdb.bohemianmatrices.com/{}/MinPolys.tar.gz\">MinPolys.tar.gz</a> ({})\n\n'.format(data_dir, fsize)
# Min poly table
s += '| Matrix Size | .csv | .zip | .tar.gz |\n'
s += '| --- | --- | --- | --- |\n'
csv_fnames = list(glob.iglob('{}/MinPolys_*.csv'.format(data_dir), recursive=True))
n_min = min([int(c[-5]) for c in csv_fnames])
n_max = max([int(c[-5]) for c in csv_fnames])
for i in range(n_min, n_max+1):
s += '| {}x{} '.format(i, i)
fsize = sizeof_fmt(os.path.getsize('{}/MinPolys_{}x{}.csv'.format(data_dir, i, i)))
s += '| <a href="http://cpdb.bohemianmatrices.com/{}/MinPolys_{}x{}.csv">MinPolys_{}x{}.csv</a> ({})'.format(data_dir, i, i, i, i, fsize)
fsize = sizeof_fmt(os.path.getsize('{}/MinPolys_{}x{}.zip'.format(data_dir, i, i)))
s += '| <a href="http://cpdb.bohemianmatrices.com/{}/MinPolys_{}x{}.zip">MinPolys_{}x{}.zip</a> ({})'.format(data_dir, i, i, i, i, fsize)
fsize = sizeof_fmt(os.path.getsize('{}/MinPolys_{}x{}.tar.gz'.format(data_dir, i, i)))
s += '| <a href="http://cpdb.bohemianmatrices.com/{}/MinPolys_{}x{}.tar.gz">MinPolys_{}x{}.tar.gz</a> ({}) |\n'.format(data_dir, i, i, i, i, fsize)
s += '\n'
return s
def write_readme(data_dir,
population_title):
class_name = data_dir.split('/')[1]
subclass_name = data_dir.split('/')[0]
permalink = '/cpdb/{}'.format(data_dir[:-5].lower())
property_file = '{}/Properties.csv'.format(data_dir[:-5])
output_file = '../BohemianMatrices/cpdb/{}.md'.format(data_dir[:-5].lower())
# yaml header
s = '---\n'
s += 'layout: page\n'
s += 'title: {}\n'.format(class_name)
s += 'permalink: {}\n'.format(permalink)
s += '---\n\n'
s += '{% include nav-breadcrumbs.html %}\n\n'
s += '{}\n\n'.format(population_title)
# Data section
s += get_data_section(data_dir, class_name)
s += '\n\n'
# Get the properties section
s += get_properties_section(data_dir,
property_file = property_file)
with open(output_file, 'w') as f:
f.write(s)
if __name__ == '__main__':
import glob
import os
property_files_list = []
# Unstructured
property_files_list.append({'data_dir': 'Unstructured/Unstructured_0_1/Data',
'population_title': 'Matrices with entries from the set {0, +1}.'})
property_files_list.append({'data_dir': 'Unstructured/Unstructured_0_1_2/Data',
'population_title': 'Matrices with entries from the set {0, +1, +2}.'})
property_files_list.append({'data_dir': 'Unstructured/Unstructured_0_Diag_0_1/Data',
'population_title': 'Matrices with entries from the set {0, +1} and diagonal entries fixed at 0.'})
property_files_list.append({'data_dir': 'Unstructured/Unstructured_0_Diag_0_1_2/Data',
'population_title': 'Matrices with entries from the set {0, +1, +2} and diagonal entries fixed at 0.'})
property_files_list.append({'data_dir': 'Unstructured/Unstructured_0_Diag_n1_0/Data',
'population_title': 'Matrices with entries from the set {-1, 0} and diagonal entries fixed at 0.'})
property_files_list.append({'data_dir': 'Unstructured/Unstructured_0_Diag_n1_0_1/Data',
'population_title': 'Matrices with entries from the set {-1, 0, +1} and diagonal entries fixed at 0.'})
property_files_list.append({'data_dir': 'Unstructured/Unstructured_0_Diag_n1_1/Data',
'population_title': 'Matrices with entries from the set {-1, +1} and diagonal entries fixed at 0.'})
property_files_list.append({'data_dir': 'Unstructured/Unstructured_n1_0/Data',
'population_title': 'Matrices with entries from the set {-1, 0}.'})
property_files_list.append({'data_dir': 'Unstructured/Unstructured_n1_0_1/Data',
'population_title': 'Matrices with entries from the set {-1, 0, +1}.'})
property_files_list.append({'data_dir': 'Unstructured/Unstructured_n1_1/Data',
'population_title': 'Matrices with entries from the set {-1, +1}.'})
property_files_list.append({'data_dir': 'UpperHessenberg/UH_1_Subdiag_0_1/Data',
'population_title': 'Upper Hessenberg matrices with subdiagonal entries fixed at 1 and all other entries from the set {0, +1}.'})
property_files_list.append({'data_dir': 'UpperHessenberg/UH_1_Subdiag_0_1_2/Data',
'population_title': 'Upper Hessenberg matrices with subdiagonal entries fixed at 1 and all other entries from the set {0, +1, +2}.'})
property_files_list.append({'data_dir': 'UpperHessenberg/UH_1_Subdiag_0_Diag_0_1/Data',
'population_title': 'Upper Hessenberg matrices with subdiagonal entries fixed at 1, diagonal entries fixed at 0, and all other entries from the set {0, +1}.'})
property_files_list.append({'data_dir': 'UpperHessenberg/UH_1_Subdiag_0_Diag_0_1_2/Data',
'population_title': 'Upper Hessenberg matrices with subdiagonal entries fixed at 1, diagonal entries fixed at 0, and all other entries from the set {0, +1, +2}.'})
property_files_list.append({'data_dir': 'UpperHessenberg/UH_1_Subdiag_0_Diag_n1_0/Data',
'population_title': 'Upper Hessenberg matrices with subdiagonal entries fixed at 1, diagonal entries fixed at 0, and all other entries from the set {-1, 0}.'})
property_files_list.append({'data_dir': 'UpperHessenberg/UH_1_Subdiag_0_Diag_n1_0_1/Data',
'population_title': 'Upper Hessenberg matrices with subdiagonal entries fixed at 1, diagonal entries fixed at 0, and all other entries from the set {-1, 0, +1}.'})
property_files_list.append({'data_dir': 'UpperHessenberg/UH_1_Subdiag_0_Diag_n1_1/Data',
'population_title': 'Upper Hessenberg matrices with subdiagonal entries fixed at 1, diagonal entries fixed at 0, and all other entries from the set {-1, +1}.'})
property_files_list.append({'data_dir': 'UpperHessenberg/UH_1_Subdiag_n1_0/Data',
'population_title': 'Upper Hessenberg matrices with subdiagonal entries fixed at 1 and all other entries from the set {-1, 0}.'})
property_files_list.append({'data_dir': 'UpperHessenberg/UH_1_Subdiag_n1_0_1/Data',
'population_title': 'Upper Hessenberg matrices with subdiagonal entries fixed at 1 and all other entries from the set {-1, 0, +1}.'})
property_files_list.append({'data_dir': 'UpperHessenberg/UH_1_Subdiag_n1_1/Data',
'population_title': 'Upper Hessenberg matrices with subdiagonal entries fixed at 1 and all other entries from the set {-1, +1}.'})
for p_dict in property_files_list:
print(p_dict['data_dir'])
write_readme(p_dict['data_dir'],
p_dict['population_title'])