def long_table(num=2, title=("符号", "说明")): data_table = LongTable("l " * num) data_table.add_hline() data_table.add_hline() data_table.add_row(title) data_table.add_hline() data_table.end_table_header() data_table.add_hline() data_table.end_table_footer() data_table.add_hline() data_table.add_hline() data_table.end_table_last_footer() return data_table
def test_table(): # Tabular t = Tabular(table_spec='|c|c|', data=None, pos=None, width=2) t.add_hline(start=None, end=None) t.add_row((1, 2), escape=False, strict=True, mapper=[bold]) t.add_row(1, 2, escape=False, strict=True, mapper=[bold]) # MultiColumn/MultiRow. t.add_row((MultiColumn(size=2, align='|c|', data='MultiColumn'), ), strict=True) # One multiRow-cell in that table would not be proper LaTeX, # so strict is set to False t.add_row((MultiRow(size=2, width='*', data='MultiRow'), ), strict=False) repr(t) # TabularX tabularx = Tabularx(table_spec='X X X', width_argument=NoEscape(r"\textwidth")) tabularx.add_row(["test1", "test2", "test3"]) # Long Table longtable = LongTable(table_spec='c c c') longtable.add_row(["test", "test2", "test3"]) longtable.end_table_header() # Colored Tabu coloredtable = Tabu(table_spec='X[c] X[c]') coloredtable.add_row(["test", "test2"], color="gray", mapper=bold) # Colored Tabu with 'spread' coloredtable = Tabu(table_spec='X[c] X[c]', spread="1in") coloredtable.add_row(["test", "test2"], color="gray", mapper=bold) # Colored Tabu with 'to' coloredtable = Tabu(table_spec='X[c] X[c]', to="5in") coloredtable.add_row(["test", "test2"], color="gray", mapper=bold) # Colored Tabularx coloredtable = Tabularx(table_spec='X[c] X[c]') coloredtable.add_row(["test", "test2"], color="gray", mapper=bold) # Column column = ColumnType("R", "X", r"\raggedleft", parameters=2) repr(column)
def test_table(): # Tabular t = Tabular(table_spec='|c|c|', data=None, pos=None, width=2) t.add_hline(start=None, end=None) t.add_row((1, 2), escape=False, strict=True, mapper=[bold]) t.add_row(1, 2, escape=False, strict=True, mapper=[bold]) # MultiColumn/MultiRow. t.add_row((MultiColumn(size=2, align='|c|', data='MultiColumn'),), strict=True) # One multiRow-cell in that table would not be proper LaTeX, # so strict is set to False t.add_row((MultiRow(size=2, width='*', data='MultiRow'),), strict=False) repr(t) # TabularX tabularx = Tabularx(table_spec='X X X', width_argument=NoEscape(r"\textwidth")) tabularx.add_row(["test1", "test2", "test3"]) # Long Table longtable = LongTable(table_spec='c c c') longtable.add_row(["test", "test2", "test3"]) longtable.end_table_header() # Colored Tabu coloredtable = Tabu(table_spec='X[c] X[c]') coloredtable.add_row(["test", "test2"], color="gray", mapper=bold) # Colored Tabu with 'spread' coloredtable = Tabu(table_spec='X[c] X[c]', spread="1in") coloredtable.add_row(["test", "test2"], color="gray", mapper=bold) # Colored Tabu with 'to' coloredtable = Tabu(table_spec='X[c] X[c]', to="5in") coloredtable.add_row(["test", "test2"], color="gray", mapper=bold) # Colored Tabularx coloredtable = Tabularx(table_spec='X[c] X[c]') coloredtable.add_row(["test", "test2"], color="gray", mapper=bold) # Column column = ColumnType("R", "X", r"\raggedleft", parameters=2) repr(column)
def make_table_of_symbols(symbols: List[str], units: List[str], descriptions: List[str]): table_symbols_content = LongTable("l l l") table_symbols_content.add_hline() table_symbols_content.add_row(["Symbol", "Unit", "Description"]) table_symbols_content.add_hline() table_symbols_content.end_table_header() table_symbols_content.add_hline() table_symbols_content.add_row( (MultiColumn(3, align='r', data='Continued on Next Page'), )) table_symbols_content.add_hline() table_symbols_content.end_table_footer() table_symbols_content.add_hline() table_symbols_content.add_row((MultiColumn(3, align='r', data='***End'), )) table_symbols_content.add_hline() table_symbols_content.end_table_last_footer() for i in range(len(symbols)): try: symbol = py2tex(symbols[i], print_latex=False, print_formula=False).replace('$', '') except: symbol = symbols[i] try: unit = py2tex(units[i], print_latex=False, print_formula=False, simplify_fractions=True).replace('$', '') except: unit = units[i] table_symbols_content.add_row([ NoEscape(f'${symbol}$'), NoEscape(f'${unit}$'), NoEscape(descriptions[i]) ]) table_symbols_content.add_hline() return table_symbols_content
def make_table(headers: List, *args): table = LongTable('|l| l| l| p{10cm}|') table.add_hline() table.add_row([ NoEscape(f'\\textbf{{\\textcolor{{black}}{{{i}}}}}') for i in headers ]) table.add_hline() table.end_table_header() table.add_hline() table.add_row((MultiColumn(4, align='r', data='Continued on next page'), )) # table.add_hline() table.end_table_footer() # table.add_hline() # table.add_row((MultiColumn(n_cols, align='r', data=''),)) # table.add_hline() table.end_table_last_footer() for i in range(len(args[0])): table.add_row([NoEscape(j[i]) for j in args]) table.add_hline() return table
dataset = [ 'vehicle', 'ionosphere', 'ecoli', 'german', 'breast_cancer', 'cmc', 'hepatitis', 'haberman', 'transfusion', 'car', 'glass', 'abalone16_29', 'heart_cleveland', 'balance_scale', 'postoperative' ] sections = [ "Accuracy", "Sensitivity", "Specificity", "F-1 klasa mniejszosciowa", 'G-mean' ] random_state = 5 tables = [] for tab in range(5): table = LongTable('c|c|cccccc') table.add_hline() table.add_row(('Zbior danych', 'Glebokosc drzewa.', "-", "5", "10", "20", "50", "100")) table.add_hline() tables.append(table) # liczba powtorzen klasyfikacji iterations = 10 # liczba fold w sprawdzianie krzyzowym folds = 10 #glebokosc drzewa i liczba estymatorow depths = [None, 1, 3, 5] estimators = [5, 10, 20, 50, 100] depths_name = ['-'] depths_name.extend(depths[1:]) clfs = []
samp = 0.8 feat = 0.9 # liczbya fold w sprawdzianie krzyzowym folds = 10 # glebokosc drzew depths = [None, 3, 5, 7, 10, 15, 20] estimators = [5, 10, 20, 50] estimators_name = ['-'] estimators_name.extend(estimators) for tab in range(5): table = LongTable('c|c|ccccccc') table.add_hline() table.add_row(('Glebokosc drzewa', 'Liczba est.', "-", "3", "5", "7", "10", "15", "20")) table.add_hline() tables.append(table) clfs = [] temp_clf = [] for depth in depths: temp_clf.append(tree.DecisionTreeClassifier(max_depth=depth)) clfs.append(temp_clf) # tworzenie klasyfikatorow for estimator in estimators: temp2_clf = [] for depth in depths: temp2_clf.append( BaggingClassifier(tree.DecisionTreeClassifier(max_depth=depth), n_estimators=estimator,
def write_file(m_l=3, m_u=70, s_l=3, s_u=60, findProc=False): doc = Document('BIGRUN_ALL') doc_one = Document('BIGRUN_ONE') doc_open = Document('Open') doc_non_FC = Document('Non_FC') doc_V3 = Document('V3') doc_gaps = Document('GAPS') table = LongTable('|c|c|c|c|c|c|c|c|') table.add_hline() table.add_row((bold('M'), bold('S'), bold('Method'), bold('Open?'), bold('LB'), bold('UB'), bold('LB-CD'), bold('UB-CD'))) table.add_hline() table.add_hline() table_one = LongTable('|c|c|c|c|c|c|c|c|') table_one.add_hline() table_one.add_row((bold('M'), bold('S'), bold('Method'), bold('Open?'), bold('LB'), bold('UB'), bold('LB-CD'), bold('UB-CD'))) table_one.add_hline() table_one.add_hline() table_open = LongTable('|c|c|c|c|c|c|c|c|') table_open.add_hline() table_open.add_row((bold('M'), bold('S'), bold('Method'), bold('Open?'), bold('LB'), bold('UB'), bold('LB-CD'), bold('UB-CD'))) table_open.add_hline() table_open.add_hline() table_non_FC = LongTable('|c|c|c|c|c|c|c|c|') table_non_FC.add_hline() table_non_FC.add_row((bold('M'), bold('S'), bold('Method'), bold('Open?'), bold('LB'), bold('UB'), bold('LB-CD'), bold('UB-CD'))) table_non_FC.add_hline() table_non_FC.add_hline() table_V3 = LongTable('|c|c|c|c|c|c|c|c|') table_V3.add_hline() table_V3.add_row((bold('M'), bold('S'), bold('Method'), bold('Open?'), bold('LB'), bold('UB'), bold('LB-CD'), bold('UB-CD'))) table_V3.add_hline() table_V3.add_hline() table_gaps = LongTable('|c|c|c|c|c|c|c|c|') table_gaps.add_hline() table_gaps.add_row((bold('M'), bold('S'), bold('Method'), bold('Open?'), bold('LB'), bold('UB'), bold('LB-CD'), bold('UB-CD'))) table_gaps.add_hline() table_gaps.add_hline() bigrun_csv = open('data/bigrun_all.csv', 'w') csv_writer = csv.writer(bigrun_csv) csv_writer.writerow(['M', 'S', 'FC', 'HALF', 'INT', 'MID', 'EBM', 'HBM', 'VHBM']) for s in range(s_l, s_u + 1): m_start = s + 1 if s + 1 > m_l else m_l for m in range(m_start, m_u + 1): if relatively_prime(m, s): ub, ans_types, all_results = f(m, s, bigrun=True) csv_writer.writerow([m, s] + all_results) open_prob = '' lb = '' lb_cd = '' ub_cd = '' used_gaps = False try: if checkProc(findProc, m, s, ub): open_prob = '' else: used_gaps = True lb = Fraction(ub.numerator - 2, ub.denominator) lb = lb if lb > Fraction(1, 3) else Fraction(1, 3) lb, lb_type = closer_bounds(m, s, lb, ub, max_denom=750) if lb_type == 'Open': open_prob = 'Open' lb_cd, ub_cd = convert_den(lb, ub) else: ans_types = [lb_type] ub = lb lb = '' except procedures.TimeoutError: open_prob = 'Timeout' except KeyError: open_prob = 'Timeout' ans_types_str = functools.reduce(lambda a, b: a + ',' + str(b), ans_types) row = (m, s, ans_types_str, open_prob, str(lb), str(ub), lb_cd, ub_cd) table.add_row(row) row_one = (m, s, ans_types[0], open_prob, str(lb), str(ub), lb_cd, ub_cd) table_one.add_row(row_one) print(row_one) table.add_hline() table_one.add_hline() if len(open_prob) > 0: table_open.add_row(row) table_open.add_hline() if len(open_prob) > 0 or 'FC' not in ans_types_str: table_non_FC.add_row(row) table_non_FC.add_hline() V, _, _ = calcSv(m, s) if V == 3: if not used_gaps: _, ans_types_all = f(m, s, bigrun=False) ans_types_all_str = functools.reduce(lambda a, b: a + ',' + str(b), ans_types) row = (m, s, ans_types_all_str, open_prob, str(lb), str(ub), lb_cd, ub_cd) table_V3.add_row(row) table_V3.add_hline() if len(open_prob) == 0 and used_gaps: table_gaps.add_row(row) table_gaps.add_hline() doc.append(table) doc.generate_pdf('bigrun/BIGRUN_all', clean_tex=False) doc_one.append(table_one) doc_one.generate_pdf('bigrun/BIGRUN_one', clean_tex=False) doc_open.append(table_open) doc_open.generate_pdf('bigrun/BIGRUN_opens', clean_tex=False) doc_non_FC.append(table_non_FC) doc_non_FC.generate_pdf('bigrun/BIGRUN_non_FC', clean_tex=False) doc_V3.append(table_V3) doc_V3.generate_pdf('bigrun/BIGRUN_V3', clean_tex=False) doc_gaps.append(table_gaps) doc_gaps.generate_pdf('bigrun/BIGRUN_GAPS', clean_tex=False)
temp_clf.append(KNeighborsClassifier(n_neighbors=neighbors)) clfs.append(temp_clf) # dodawanie klasyfikatorow for estimator in estimators: temp2_clf = [] for neighbors in n_neighbors: temp2_clf.append( BaggingClassifier(KNeighborsClassifier(n_neighbors=neighbors), n_estimators=estimator, max_features=1.0, max_samples=0.8)) clfs.append(temp2_clf) for tab in range(5): table = LongTable('c|c|ccccc') table.add_hline() table.add_row(('Glebokosc drzewa', 'Liczba est.', "1", "2", "3", "5", "7")) table.add_hline() tables.append(table) for data in dataset: db = getattr(importdata, 'load_' + data)() print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") print('Zbior danych: %s' % data) importdata.print_info(db.target) # klasyfikacja for id, (clfs_, name) in enumerate(zip(clfs, estimators_name)): rows = [] if id == 0: