This repository has been archived by the owner on Jun 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
61 lines (48 loc) · 1.92 KB
/
main.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
import numpy as np
from rul_prediction.rul_predictor import RULPredictor
from rul_prediction.data_extraction import DataExtraction
import matplotlib.pyplot as plt
if __name__ == '__main__':
data_extractor = DataExtraction()
rp = RULPredictor()
data_extractor.set_md_threshold('./dataset/Learning_set/Bearing1_1/', mode='max')
rp.w = data_extractor.w
MD_MEAN = data_extractor.mean
MD_THRESHOLD = data_extractor.MD_THRESHOLD
data = data_extractor.get_test_data('./dataset/Learning_set/Bearing1_1/', mode='max', save_to_file=True, file_path='./my_data/test_data_1_1_wrt_1_1.npz')
# data = data_extractor.get_test_data_from_file(file_path='./my_data/test_data_1_1_wrt_1_1.npz')
data_extractor.plot_test_data(data, load_from_file=False, file_path=None)
pred_ruls = []
pred_times = []
start = 0
it = start
for t, md in data[start:]:
if md > MD_THRESHOLD:
y = np.log(np.absolute(md - MD_MEAN))
rp.reading(y ,t / 10 ** 6) # Update theta using EM
rul = rp.predict_RUL()
print(f"Iteration: {it}\tTime: {t / 10 ** 6}\tRUL: {rul}")
pred_times.append(it)
pred_ruls.append(rul)
it += 1
# Actual RUL
actual_ruls = [*range(pred_times[-1]-pred_times[0], -1, -1)]
actual_ruls = list(map(lambda x: x*10, actual_ruls)) # time between two files is 10s
# RUL plot
plt.plot(pred_times, actual_ruls, label='Actual')
plt.plot(pred_times, pred_ruls, label='Predicted')
plt.xlabel("Sample number")
plt.ylabel("RUL in seconds")
plt.legend()
plt.title("Bearing1_1 RUL Plot")
plt.grid()
plt.show()
# Error Plot
error = list(np.array(actual_ruls) - np.array(pred_ruls))
plt.plot(pred_times, error, label='Error')
plt.xlabel("Sample number")
plt.ylabel("Tracking error")
plt.legend()
plt.title("Bearing1_1 Error plot")
plt.grid()
plt.show()