Parse log file Returns (train_dict_list, test_dict_list) train_dict_list and test_dict_list are lists of dicts that define the table rows
(path_to_log)
| 15 | |
| 16 | |
| 17 | def parse_log(path_to_log): |
| 18 | """Parse log file |
| 19 | Returns (train_dict_list, test_dict_list) |
| 20 | |
| 21 | train_dict_list and test_dict_list are lists of dicts that define the table |
| 22 | rows |
| 23 | """ |
| 24 | |
| 25 | regex_iteration = re.compile('Iteration (\d+)') |
| 26 | regex_train_output = re.compile('Train net output #(\d+): (\S+) = ([\.\deE+-]+)') |
| 27 | regex_test_output = re.compile('Test net output #(\d+): (\S+) = ([\.\deE+-]+)') |
| 28 | regex_learning_rate = re.compile('lr = ([-+]?[0-9]*\.?[0-9]+([eE]?[-+]?[0-9]+)?)') |
| 29 | |
| 30 | # Pick out lines of interest |
| 31 | iteration = -1 |
| 32 | learning_rate = float('NaN') |
| 33 | train_dict_list = [] |
| 34 | test_dict_list = [] |
| 35 | train_row = None |
| 36 | test_row = None |
| 37 | |
| 38 | logfile_year = extract_seconds.get_log_created_year(path_to_log) |
| 39 | with open(path_to_log) as f: |
| 40 | start_time = extract_seconds.get_start_time(f, logfile_year) |
| 41 | last_time = start_time |
| 42 | |
| 43 | for line in f: |
| 44 | iteration_match = regex_iteration.search(line) |
| 45 | if iteration_match: |
| 46 | iteration = float(iteration_match.group(1)) |
| 47 | if iteration == -1: |
| 48 | # Only start parsing for other stuff if we've found the first |
| 49 | # iteration |
| 50 | continue |
| 51 | |
| 52 | try: |
| 53 | time = extract_seconds.extract_datetime_from_line(line, |
| 54 | logfile_year) |
| 55 | except ValueError: |
| 56 | # Skip lines with bad formatting, for example when resuming solver |
| 57 | continue |
| 58 | |
| 59 | # if it's another year |
| 60 | if time.month < last_time.month: |
| 61 | logfile_year += 1 |
| 62 | time = extract_seconds.extract_datetime_from_line(line, logfile_year) |
| 63 | last_time = time |
| 64 | |
| 65 | seconds = (time - start_time).total_seconds() |
| 66 | |
| 67 | learning_rate_match = regex_learning_rate.search(line) |
| 68 | if learning_rate_match: |
| 69 | learning_rate = float(learning_rate_match.group(1)) |
| 70 | |
| 71 | train_dict_list, train_row = parse_line_for_net_output( |
| 72 | regex_train_output, train_row, train_dict_list, |
| 73 | line, iteration, seconds, learning_rate |
| 74 | ) |
no test coverage detected