Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this user
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
delriot
/
AugmentingMathematicalDataset
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Projects
0
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Projects
Security
Insights
Files
94aaa66
DatasetsBeforeProcessing
Heuristics
config
datasets
packages
README.md
basic_ml.py
choose_hyperparams.py
create_clean_dataset.py
main.py
main_heuristics.py
main_regression.py
make_plots.py
output.txt
replicating_Dorians_features.py
test_train_datasets.py
train_models.py
Breadcrumbs
AugmentingMathematicalDataset
/
main_heuristics.py
Blame
Blame
Latest commit
History
History
87 lines (82 loc) · 4.01 KB
Breadcrumbs
AugmentingMathematicalDataset
/
main_heuristics.py
Top
File metadata and controls
Code
Blame
87 lines (82 loc) · 4.01 KB
Raw
import csv import math import pickle import random import numpy as np from Heuristics.heuristics_guess import not_greedy_heuristic_guess from Heuristics.heuristics_guess import choose_order_given_projections from find_filename import find_dataset_filename from test_models import compute_metrics nvar = 3 testing_method = 'Normal' test_dataset_filename = find_dataset_filename('Test', testing_method) with open(test_dataset_filename, 'rb') as test_dataset_file: testing_dataset = pickle.load(test_dataset_file) output_file = "heuristics_output_acc_time.csv" # Testing in heuristics that make all the choice at once first_heuristic = 1 for heuristic in ['gmods', 'brown', 'random', 'virtual best']: reps = 100 sum_metrics = dict() for i in range(reps): if heuristic == 'virtual best': chosen_indices = [np.argmin(timings) for timings in testing_dataset['timings']] elif heuristic == 'random': chosen_indices = [random.randint(0, 5) for timings in testing_dataset['timings']] else: chosen_indices = [not_greedy_heuristic_guess(projection[0][0], heuristic) for projection in testing_dataset['projections']] metrics = compute_metrics(chosen_indices, testing_dataset['labels'], testing_dataset['timings'], testing_dataset['cells']) if len(sum_metrics) == 0: sum_metrics = metrics else: sum_metrics = {key: metrics[key] + sum_metrics[key] for key in metrics} aveg_metrics = {key: sum_metrics[key]/reps for key in sum_metrics} augmented_metrics = {key: aveg_metrics[key] if key in ['Accuracy', 'Markup'] else math.factorial(nvar)*aveg_metrics[key] for key in sum_metrics} print(heuristic, augmented_metrics) if first_heuristic == 1: first_heuristic = 0 keys = list(augmented_metrics.keys()) with open(output_file, 'a') as f: f.write('Choosing the whole ordering in the beggining \n') f.write(', '.join(['Model'] + keys) + '\n') with open(output_file, 'a', newline='') as f: writer = csv.writer(f) writer.writerow([heuristic] + [augmented_metrics[key] for key in keys]) # Testing on greedy heuristics for heuristic in ['brown', 'gmods', 'random', 'virtual best']: reps = 100 sum_metrics = dict() for i in range(reps): if heuristic == 'virtual best': chosen_indices = [np.argmin(timings) for timings in testing_dataset['timings']] elif heuristic == 'random': chosen_indices = [random.randint(0, 5) for timings in testing_dataset['timings']] else: chosen_indices = [choose_order_given_projections(projection, heuristic) for projection in testing_dataset['projections']] metrics = compute_metrics(chosen_indices, testing_dataset['labels'], testing_dataset['timings'], testing_dataset['cells']) if len(sum_metrics) == 0: sum_metrics = metrics else: sum_metrics = {key: metrics[key] + sum_metrics[key] for key in metrics} aveg_metrics = {key: sum_metrics[key]/reps for key in sum_metrics} augmented_metrics = {key: aveg_metrics[key] if key in ['Accuracy', 'Markup'] else math.factorial(nvar)*aveg_metrics[key] for key in sum_metrics} print(heuristic, augmented_metrics) if first_heuristic == 1: first_heuristic = 0 keys = list(augmented_metrics.keys()) with open(output_file, 'a') as f: f.write('Now choosing greedily \n') f.write(', '.join(['Model'] + keys) + '\n') with open(output_file, 'a', newline='') as f: writer = csv.writer(f) writer.writerow([heuristic] + [augmented_metrics[key] for key in keys]) # print(sum(min(timings) for timings in testing_dataset['timings']))
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
You can’t perform that action at this time.