-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
242 lines (228 loc) · 9.34 KB
/
utils.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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
from skmultiflow.data import DataStream, WaveformGenerator, SEAGenerator, HyperplaneGenerator
import pandas as pd
import numpy as np
import csv
from OAL_classifier.clf_OALE import OALE_strategy
from OAL_classifier.clf_ROALE_DI import ROALE_DI_strategy
from OAL_strategies.str_MTSGQS import MTSGQS_strategy
from OAL_strategies.str_DSA_AI import DSA_AI_strategy
from OAL_strategies.str_US_fix import US_fix_strategy
from OAL_strategies.str_US_var import US_var_strategy
from OAL_strategies.str_CogDQS import CogDQS_strategy
from OAL_strategies.str_RS import RS_strategy
from OAL_strategies.str_DMI_DD import DMI_DD_strategy
from classifier.clf_BLS import BLS
from classifier.clf_SRP import SRP
from classifier.clf_DES import DES_ICD
from skmultiflow.bayes import NaiveBayes
from classifier.clf_ACDWM import ACDWM
from classifier.clf_OLI2DS import OLI2DS
from classifier.clf_BLS_QR import BLS_QR
from OSSL_classifier.clf_OSSBLS import OSSBLS
from OSSL_classifier.clf_ISSBLS import ISSBLS
from OSSL_classifier.clf_SOSELM import SOSELM
from classifier.clf_ARF import ARF
from skmultiflow.meta import LeveragingBaggingClassifier, OnlineUnderOverBaggingClassifier,OzaBaggingClassifier, OzaBaggingADWINClassifier, DynamicWeightedMajorityClassifier
from skmultiflow.meta import OnlineAdaC2Classifier
def get_stream(name):
if name == "Jiaolong":
with open('./datasets/Jiaolong_DSMS_V2.csv', 'r') as csvfile:
csvreader = csv.reader(csvfile)
next(csvreader, None)
X = []
Y = []
for row in csvreader:
data_row = row[:-1]
label = row[-1]
X.append(data_row)
Y.append(label)
X = np.array(X, dtype=float)
Y = np.array(Y, dtype=int)
stream = DataStream(X, Y)
elif name == "Waveform":
stream = WaveformGenerator(random_state=1)
elif name == "SEA":
stream = SEAGenerator(random_state=1)
elif name == "Hyperplane":
stream = HyperplaneGenerator(random_state=1)
else:
data = pd.read_csv('./datasets/' + name + '.csv')
data = data.values
vol, col = data.shape
X = data[:, 0:col - 1]
Y = data[:, col - 1]
Y = np.array([int(i) for i in Y])
stream = DataStream(X, Y)
return stream
def get_pt(stream, n_pt):
data, labels = stream.next_sample(n_pt)
return data, labels
class para_init:
def __init__(self, X_pt_source=np.array([[]]), y_pt_source=np.array([[]]), n_class=2, n_ratio_max=0.2, n_anchor=10, theta=0.2):
self.n_class = n_class
self.X_pt_source = X_pt_source
self.y_pt_source = y_pt_source
self.n_ratio_max = n_ratio_max
self.n_anchor = n_anchor
self.theta = theta
def get_method(self, name):
if name == "ROALE_DI":
return ROALE_DI_strategy(self.X_pt_source, self.y_pt_source, L=self.n_class)
if name == "OALE":
return OALE_strategy(self.X_pt_source, self.y_pt_source, L=self.n_class)
def get_clf(self, name):
if name == "clf_ARF":
return ARF()
elif name == "clf_LB":
return LeveragingBaggingClassifier()
elif name=="clf_OB":
return OzaBaggingClassifier()
elif name=="clf_OBADWIN":
return OzaBaggingADWINClassifier()
elif name=='clf_DWM':
return DynamicWeightedMajorityClassifier()
elif name == "clf_OOB":
return OnlineUnderOverBaggingClassifier()
elif name == "clf_SRP":
return SRP(n_estimators=3, n_class=self.n_class)
elif name == "clf_AdaC2":
return OnlineAdaC2Classifier()
elif name == "clf_BLS_QR":
return BLS_QR(Nf=20,
Ne=10,
N1=20,
N2=10,
M1=1,
M2=5,
E1=1,
E2=100,
E3=1,
map_function='sigmoid',
enhence_function='sigmoid',
reg=0.001,
n_class=3)
elif name == "clf_BLS":
return BLS(Nf=40,
Ne=10,
N1=60,
N2=10,
map_function='sigmoid',
enhence_function='sigmoid',
reg=0.001)
elif name == "clf_OSSBLS":
return OSSBLS(Nf=10,
Ne=10,
N1=10,
N2=10,
map_function='sigmoid',
enhence_function='sigmoid',
reg=0.001,
gamma=0.005,
n_anchor=10)
elif name == "clf_OSSBLS":
return OSSBLS(Nf=10,
Ne=10,
N1=10,
N2=10,
map_function='sigmoid',
enhence_function='sigmoid',
reg=0.001,
gamma=0.001,
n_anchor=self.n_anchor,
n_class=3)
elif name == "clf_ISSBLS":
return ISSBLS(
Nf=10,
Ne=10,
N1=10,
N2=10,
map_function='sigmoid',
enhence_function='sigmoid',
reg=0.001,
gamma=0.05)
elif name == "clf_SOSELM":
return SOSELM(
Ne=20,
N2=10,
enhence_function='sigmoid',
reg=0.001,
gamma=0.05)
elif name == "clf_NB":
return NaiveBayes()
elif name == "clf_DES":
return DES_ICD(base_classifier=NaiveBayes(), window_size=50, max_classifier=10)
elif name == "clf_DES_5":
return DES_ICD(base_classifier=NaiveBayes(), window_size=50, max_classifier=5)
elif name == "clf_ACDWM":
return ACDWM(chunk_size=0, max_ensemble_size=10)
elif name == "clf_OLI2DS":
return OLI2DS(C=0.0100000, Lambda=30, B=1, theta=8, gama=0, sparse=0, mode="capricious")
raise ValueError("Not valid")
def get_str(self, name, chunk_size, query_size, clf):
name = name + "_str"
if name == "DSA_AI_str":
return DSA_AI_strategy(n_class=self.n_class, X_memory_collection=self.X_pt_source,
y_memory_collection=self.y_pt_source, d=self.X_pt_source.shape[1],
kappa=3, gamma=0.4)
elif name == "Supervised_str":
return None
elif name == "MTSGQS_str":
return MTSGQS_strategy(n_class=self.n_class, kappa=2, gamma=0.4, n_capacity=100)
elif name == "US_fix_str":
return US_fix_strategy(theta=0.5)
elif name == "US_var_str":
return US_var_strategy(theta=0.5)
elif name == "CogDQS_str":
return CogDQS_strategy(B=0.25, n=1, c=3, cw_size=10, window_size=200, s=0.01)
elif name == "RS_str":
return RS_strategy(label_ratio=self.n_ratio_max)
if name == "DMI_DD_str":
return DMI_DD_strategy(n_class=self.n_class, chunk_size=chunk_size, query_size=query_size, clf=clf, X_pt=self.X_pt_source, y_pt=self.y_pt_source)
raise ValueError("Not valid")
# def clf_init(self):
# clf_ARF = ARF()
# clf_SRP = SRP()
# clf_BLS = BLS(Nf=10,
# Ne=10,
# N1=10,
# N2=10,
# map_function='sigmoid',
# enhence_function='sigmoid',
# reg=0.001)
# clf_OSSBLS = OSSBLS(
# Nf=10,
# Ne=10,
# N1=10,
# N2=10,
# map_function='sigmoid',
# enhence_function='sigmoid',
# reg=0.001,
# gamma=0.05,
# n_anchor=10)
# clf_ISSBLS = ISSBLS(
# Nf=10,
# Ne=10,
# N1=10,
# N2=10,
# map_function='sigmoid',
# enhence_function='sigmoid',
# reg=0.001,
# gamma=0.05)
#
# clf_SOSELM = SOSELM(
# Ne=20,
# N2=10,
# enhence_function='sigmoid',
# reg=0.001,
# gamma=0.05)
#
# return clf_ARF, clf_SRP, clf_BLS, clf_OSSBLS, clf_ISSBLS, clf_SOSELM
# def str_init(self):
# DSA_AI_str = DSA_AI_strategy(n_class=self.n_class, X_memory_collection=self.X_pt_source, y_memory_collection=self.y_pt_source, d=self.X_pt_source.shape[1],
# kappa=2, gamma=0.4)
# MTSGQS_str = MTSGQS_strategy(n_class=self.n_class, kappa=2, gamma=0.4, n_capacity=100)
# US_fix_str = US_fix_strategy(theta=0.5)
# US_var_str = US_var_strategy(theta=0.5)
# CogDQS_str = CogDQS_strategy(B=0.25, n=1, c=2, cw_size=10, window_size=200, s=0.01)
# RS_str = RS_strategy(label_ratio=self.n_ratio_max)
# return DSA_AI_str, MTSGQS_str, US_fix_str, US_var_str, CogDQS_str, RS_str