[6536f9]: / run_exp_1.py

Download this file

121 lines (105 with data), 6.4 kB

  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
import run
import sys
import os
import numpy as np
import matplotlib.pyplot as plt
def run_experiment1(data_path):
os.makedirs('exp1_results', exist_ok=True)
accuracies1 = []
accuracies2 = []
accuracies3 = []
accuracies4 = []
accuracies5 = []
for num_subjects in range(20, 150, 20):
print(f"Training for {num_subjects} subjects with III+V3+V5")
accuracy, total_train_time, total_eval_time = run.run(NUM_SEGMENTS=500,
NUM_SECONDS=2,
NUM_BATCH=16,
LEADS=[0,1,2],
NUM_EPOCHS=200,
DATA_PATH = data_path,
FS=128,
NUM_PATIENTS=num_subjects)
accuracies1.append(accuracy)
with open('exp1_results/result-III-V3-V5.txt', 'a') as f:
f.write(f"With number subjects: {num_subjects}:\n")
f.write(f"Accuracy: {accuracy}, Time train: {total_train_time}, Time eval: {total_eval_time}\n\n")
for num_subjects in range(20, 150, 20):
print(f"Training for {num_subjects} subjects with III+V3")
accuracy, total_train_time, total_eval_time = run.run(NUM_SEGMENTS=500,
NUM_SECONDS=2,
NUM_BATCH=16,
LEADS=[0,1],
NUM_EPOCHS=200,
DATA_PATH = data_path,
FS=128,
NUM_PATIENTS=num_subjects)
accuracies2.append(accuracy)
with open('exp1_results/result-III-V3.txt', 'a') as f:
f.write(f"With number subjects: {num_subjects}:\n")
f.write(f"Accuracy: {accuracy}, Time train: {total_train_time}, Time eval: {total_eval_time}\n\n")
for num_subjects in range(20, 150, 20):
print(f"Training for {num_subjects} subjects with V5")
accuracy, total_train_time, total_eval_time = run.run(NUM_SEGMENTS=500,
NUM_SECONDS=2,
NUM_BATCH=16,
LEADS=[2],
NUM_EPOCHS=200,
DATA_PATH = data_path,
FS=128,
NUM_PATIENTS=num_subjects)
accuracies3.append(accuracy)
with open('exp1_results/result-V5.txt', 'a') as f:
f.write(f"With number subjects: {num_subjects}:\n")
f.write(f"Accuracy: {accuracy}, Time train: {total_train_time}, Time eval: {total_eval_time}\n\n")
for num_subjects in range(20, 150, 20):
print(f"Training for {num_subjects} subjects with V3")
accuracy, total_train_time, total_eval_time = run.run(NUM_SEGMENTS=500,
NUM_SECONDS=2,
NUM_BATCH=16,
LEADS=[1],
NUM_EPOCHS=200,
DATA_PATH = data_path,
FS=128,
NUM_PATIENTS=num_subjects)
accuracies4.append(accuracy)
with open('exp1_results/result-V3.txt', 'a') as f:
f.write(f"With number subjects: {num_subjects}:\n")
f.write(f"Accuracy: {accuracy}, Time train: {total_train_time}, Time eval: {total_eval_time}\n\n")
for num_subjects in range(20, 150, 20):
print(f"Training for {num_subjects} subjects with III")
accuracy, total_train_time, total_eval_time = run.run(NUM_SEGMENTS=500,
NUM_SECONDS=2,
NUM_BATCH=16,
LEADS=[0],
NUM_EPOCHS=200,
DATA_PATH = data_path,
FS=128,
NUM_PATIENTS=num_subjects)
accuracies5.append(accuracy)
with open('exp1_results/result-III.txt', 'a') as f:
f.write(f"With number subjects: {num_subjects}:\n")
f.write(f"Accuracy: {accuracy}, Time train: {total_train_time}, Time eval: {total_eval_time}\n\n")
#plotting
num_subjects = list(range(20, 150, 20))
plt.figure(figsize=(10, 8), dpi=100)
plt.plot(num_subjects, accuracies1, '#8C2155',marker='.', label='III+V3+V5')
plt.plot(num_subjects, accuracies2, '#F99083',marker='.', label='III+V3')
plt.plot(num_subjects, accuracies3, '#8AA29E',marker='.', label='V5')
plt.plot(num_subjects, accuracies4, '#98CE00',marker='.', label='V3')
plt.plot(num_subjects, accuracies5, '#FFC857',marker='.', label='III')
plt.xlabel('Number of subjects', fontsize=16)
plt.ylabel('Accuracy (%)', fontsize=16)
plt.tick_params(axis='both', which='major', labelsize=12)
plt.legend()
plt.xlim((np.min(num_subjects),np.max(num_subjects)))
plt.grid(True, 'both')
plt.savefig('exp1_results/fig_exp1.png')
plt.show()
plt.close()
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python run_exp_1.py <data_path>")
sys.exit(1)
data_path = sys.argv[1]
run_experiment1(data_path)