-
Notifications
You must be signed in to change notification settings - Fork 6
/
test_multigaussian_sweepDifficulty.py
67 lines (52 loc) · 1.83 KB
/
test_multigaussian_sweepDifficulty.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
import numpy as np
import matplotlib.pyplot as plt
import glob
import sys
from math import *
import torch
import torch.nn as nn
from torch.nn import Parameter
from torch.nn import functional as F
import torch.optim
from torch.autograd import Variable
import time
import copy
import seaborn
from problem import problemGenerator
from architecture import ClassifierGenerator, NetworkSKL, tovar, toivar
from testing import evalClassifier, compareMethodsOnProblem
from sklearn.svm import SVC
from sklearn.ensemble import RandomForestClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import roc_auc_score
import xgboost as xgb
import warnings
def fxn():
warnings.warn("deprecated", DeprecationWarning)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
fxn()
net32_16 = ClassifierGenerator(32, 16, 384).cuda()
net32_16.load_state_dict(torch.load("models/classifier-generator-32-16.pth"))
net128_16 = ClassifierGenerator(128, 16, 384).cuda()
net128_16.load_state_dict(torch.load("models/classifier-generator-128-16.pth"))
methods = [
lambda: SVC(kernel='linear', C=1, probability=True),
lambda: SVC(kernel='rbf', C=1, probability=True),
RandomForestClassifier,
lambda: xgb.XGBClassifier(n_jobs = 64),
KNeighborsClassifier,
lambda: NetworkSKL(net32_16, ensemble=30),
lambda: NetworkSKL(net128_16, ensemble=30)]
# Sweep Sigma
f = open("results/Sigma-128-16-100.txt","wb")
f.write("Sigma;LSVC;;SVC;;RF;;XGB;;KNN;;$CG_{32,16}^{100,0.2}$;;$CG_{128,16}^{100,0.2}$;\n")
f.close()
for sigma in np.arange(0.05,1.5,0.05):
results = compareMethodsOnProblem(methods, 16, 128, sigma, N=100, samples=20)
f = open("results/Sigma-128-16-100.txt","a")
f.write("%.3g" % (sigma))
for i in range(len(results)):
f.write(";%.3g;%.3g" % (results[i][1],results[i][3]))
f.write("\n")
f.close()