-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool.py
More file actions
142 lines (125 loc) · 4.31 KB
/
tool.py
File metadata and controls
142 lines (125 loc) · 4.31 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import numpy as np
from scipy.stats import norm
class DisaggregationTool:
def __init__(self):
pass
def charging_status(self, row, Rate_EST, alpha):
if row["consumption"] > max(
Rate_EST + row["base_load"], row["regular_profile"] + Rate_EST * alpha
):
return 1
elif row["consumption"] < Rate_EST + row["base_load"]:
return -1000
else:
return 0
def change_point_status_start(self, row, Rate_EST, beta):
threshold1 = Rate_EST * beta
threshold2 = Rate_EST * beta
if 5 <= row["Month"] <= 10:
if row["dif1"] > threshold1 or row["dif2"] > threshold1:
return 1
else:
return 0
else:
if row["dif1"] > threshold2 or row["dif2"] > threshold2:
return 1
else:
return 0
def change_point_status_end(self, row, Rate_EST, beta):
threshold1 = Rate_EST * beta
threshold2 = Rate_EST * beta
if 5 <= row["Month"] <= 10:
if row["dif1"] < -threshold1 or row["dif2"] < -threshold1:
return -1
else:
return 0
else:
if row["dif1"] < -threshold2 or row["dif2"] < -threshold2:
return -1
else:
return 0
def ChargingDetection(self, data, start, end, mean, std, Rate_EST, dic):
cnt = 1
if (
not data.iloc[start]["forward"] * data.iloc[start]["backward"]
or (end - start) >= 24
):
return False
if start - end >= 3:
threshold = 0.01 / (end - start)
else:
threshold = 0.01 / (end - start)
for k in range(start, end):
if not data.iloc[k]["forward"] * data.iloc[k]["backward"]:
return False
normal_load = data.iloc[k]["consumption"] - Rate_EST
if (
(norm.cdf(x=normal_load, loc=mean, scale=std) < threshold)
or normal_load < data.iloc[k]["base_load"]
) and start <= k < end - 1:
return False
if (
(
norm.cdf(
x=data.iloc[k]["consumption"] - Rate_EST / 2,
loc=mean,
scale=std,
)
< threshold
)
or data.iloc[k]["consumption"] - Rate_EST / 2
< data.iloc[k]["base_load"]
) and k >= end - 1:
return False
if data.iloc[k]["higher"] == 1:
cnt += 1
elif data.iloc[k]["higher"] < 0 and k < end - 1:
cnt += data.iloc[k]["higher"]
else:
cnt -= 2
if cnt < 0:
return False
return True
def estimation(self, Rate_EST, n, Charging_period, bound):
estimate = []
for i in range(n):
if i in Charging_period:
estimate.append(Rate_EST)
elif i in bound:
estimate.append(Rate_EST / 2)
else:
estimate.append(0)
return estimate
def distribution(self, data, start, end, visited):
normal = []
cur = start - 1
while len(normal) <= 7:
if cur - 1 not in visited:
normal.append(data.iloc[cur - 1]["consumption"])
cur -= 1
else:
cur -= 1
cur = end + 1
while len(normal) <= 15:
if cur + 1 >= len(data):
break
if cur + 1 not in visited:
normal.append(data.iloc[cur + 1]["consumption"])
cur += 1
else:
cur += 1
return np.mean(normal), np.std(normal)
def consecutive_filter(self, candidate):
delete = set()
for i in range(len(candidate) - 2):
if (
candidate[i][1] + 2 == candidate[i + 1][0]
or candidate[i][1] + 1 == candidate[i + 1][0]
):
delete.add(i)
delete.add(i + 1)
candidate_filter = []
for i in range(len(candidate)):
if i not in delete:
candidate_filter.append(candidate[i])
return candidate_filter