-
Notifications
You must be signed in to change notification settings - Fork 0
/
Figure6.py
92 lines (62 loc) · 2.38 KB
/
Figure6.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
#!/usr/bin/env python
# coding: utf-8
import keras
import numpy as np
import time
import warnings
from eigenpro import kernels
from eigenpro import mnist
from eigenpro import ciphar
from eigenpro import synthetic
from eigenpro import utils
from eigenpro import training
### Dataset
dataset_dict = {}
num_classes = 10
(x_train_full, y_train_full), (x_test_full, y_test_full) = mnist.load()
y_train_full = keras.utils.to_categorical(y_train_full, num_classes)
y_test_full = keras.utils.to_categorical(y_test_full, num_classes)
dataset = ((x_train_full, y_train_full), (x_test_full, y_test_full))
dataset_dict['MNIST'] = dataset
# num_classes = 10
# (x_train_full, y_train_full), (x_test_full, y_test_full) = ciphar.load()
# y_train_full = keras.utils.to_categorical(y_train_full, num_classes)
# y_test_full = keras.utils.to_categorical(y_test_full, num_classes)
# dataset = ((x_train_full, y_train_full), (x_test_full, y_test_full))
# dataset_dict['CIPHAR'] = dataset
# num_classes = 2
# (x_train_full, y_train_full), (x_test_full, y_test_full) = synthetic.load(1)
# y_train_full = keras.utils.to_categorical(y_train_full, num_classes)
# y_test_full = keras.utils.to_categorical(y_test_full, num_classes)
# dataset = ((x_train_full, y_train_full), (x_test_full, y_test_full))
# dataset_dict['Synthetic1'] = dataset
num_classes = 2
(x_train_full, y_train_full), (x_test_full, y_test_full) = synthetic.load(2)
y_train_full = keras.utils.to_categorical(y_train_full, num_classes)
y_test_full = keras.utils.to_categorical(y_test_full, num_classes)
dataset = ((x_train_full, y_train_full), (x_test_full, y_test_full))
dataset_dict['Synthetic2'] = dataset
### Kernel
kernel_dict = {}
sg = 5
kernel_sgd = lambda x,y: kernels.Gaussian(x, y, sg)
kernel_inv = lambda x,y: training.Gaussian(x, y, sg)
kernel_dict["Gaussian"] = (kernel_sgd, kernel_inv)
sl = 10
kernel_sgd_l = lambda x,y: kernels.Laplace(x, y, sl)
kernel_inv_l = lambda x,y: training.Laplace(x, y, sl)
kernel_dict["Laplace"] = (kernel_sgd_l, kernel_inv_l)
### Size
# size_list = [200, 400, 600, 2000]
size_list = [2000, 4000, 10000, 20000, 50000]
### Noise
# noise_list = [0, 10]
noise_list = [0, 1, 10]
### Training
trainers = training.training(dataset_dict, kernel_dict, size_list, noise_list)
with open('output/figure6-' + time.strftime("%Y%m%d-%H%M%S") + '.txt', 'w') as f:
print(trainers, file=f)
print()
print()
print()
print(trainers)