Skip to content
Snippets Groups Projects
Commit 080f5413 authored by Luc Giffon's avatar Luc Giffon
Browse files

update nys vs nystrom experiment

parent 1ce25f01
No related branches found
No related tags found
No related merge requests found
import numpy as np
if __name__ == '__main__':
batch_size = np.logspace(3, 9, dtype=int, base=2, num=5)
num_epochs = np.linspace(200, 200, num=1)
gamma = 0.003
subsample_size = np.logspace(3, 9, dtype=int, base=2, num=5)
networks_types = ["nystroem", "deepstrom"]
for network in networks_types:
s_network = "--" + network + " "
s_gamma = s_network + "-G " + str(gamma) + " "
for nys_size in subsample_size:
s_nys = s_gamma + "-m " + str(nys_size) + " "
if network == "deepstrom":
for num_epoch in num_epochs:
s_epoch = s_nys + "-e" + " " + str(int(num_epoch)) + " "
for b_size in batch_size:
s_batch = s_epoch + "-s " + str(b_size) + " "
print(s_batch)
else:
print(s_nys)
...@@ -9,10 +9,10 @@ Options: ...@@ -9,10 +9,10 @@ Options:
-h --help Show this screen. -h --help Show this screen.
--nystroem Run the nystroem version. --nystroem Run the nystroem version.
--deepstrom Run the deepstrom version. --deepstrom Run the deepstrom version.
-e numepoch --num-epoch=numepoch The number of epoch. [default: 1]
-s batchsize --batch-size=batchsize The number of example in each batch [default: 50]
-G gammavalue --gamma-nystrom=gammavalue The gamma value used in nystrom. -G gammavalue --gamma-nystrom=gammavalue The gamma value used in nystrom.
-m subsamplesize --subsample-size-nystrom=subsamplesize The subsample size for nystrom. -m subsamplesize --subsample-size-nystrom=subsamplesize The subsample size for nystrom.
-e numepoch --num-epoch=numepoch The number of epoch. [default: 1]
-s batchsize --batch-size=batchsize The number of example in each batch [default: 50]
""" """
import tensorflow as tf import tensorflow as tf
...@@ -21,7 +21,7 @@ import skluc.mldatasets as dataset ...@@ -21,7 +21,7 @@ import skluc.mldatasets as dataset
from sklearn.kernel_approximation import Nystroem from sklearn.kernel_approximation import Nystroem
from sklearn.svm import SVC from sklearn.svm import SVC
from nystrom.nystrom_approx import nystrom_layer from skluc.nystrom.nystrom_approx import nystrom_layer
from skluc.neural_networks import batch_generator, classification_mnist from skluc.neural_networks import batch_generator, classification_mnist
tf.logging.set_verbosity(tf.logging.ERROR) tf.logging.set_verbosity(tf.logging.ERROR)
...@@ -29,10 +29,18 @@ tf.logging.set_verbosity(tf.logging.ERROR) ...@@ -29,10 +29,18 @@ tf.logging.set_verbosity(tf.logging.ERROR)
import docopt import docopt
def deepstrom_classif(X_train, Y_train, X_nystrom, batch_size, def deepstrom_classif(X_train,
num_epoch, dataset_cycling, Y_train,
gamma, data_shape, output_dim, output_nystrom_layer, X_nystrom,
X_test=None, Y_test=None): batch_size,
num_epoch,
dataset_cycling,
gamma,
data_shape,
output_dim,
output_nystrom_layer,
X_test=None,
Y_test=None):
with tf.Graph().as_default(): with tf.Graph().as_default():
...@@ -77,7 +85,8 @@ def deepstrom_classif(X_train, Y_train, X_nystrom, batch_size, ...@@ -77,7 +85,8 @@ def deepstrom_classif(X_train, Y_train, X_nystrom, batch_size,
# testing or predicting may not be wanted # testing or predicting may not be wanted
accuracy = sess.run([accuracy_op], feed_dict={ accuracy = sess.run([accuracy_op], feed_dict={
x: X_test, y_: Y_test, keep_prob: 1.0}) x: X_test, y_: Y_test, keep_prob: 1.0})
print(accuracy) lst_output = [str(accuracy[0]), str(x_nystrom.shape[0]), str(gamma), str(batch_size), str(num_epoch)]
print(",".join(lst_output))
def nystroem_classif(X_train, Y_train, X_test, Y_test, subsample, gamma): def nystroem_classif(X_train, Y_train, X_test, Y_test, subsample, gamma):
...@@ -87,22 +96,26 @@ def nystroem_classif(X_train, Y_train, X_test, Y_test, subsample, gamma): ...@@ -87,22 +96,26 @@ def nystroem_classif(X_train, Y_train, X_test, Y_test, subsample, gamma):
X_test_transformed = nys.transform(X_test) X_test_transformed = nys.transform(X_test)
clf = SVC(kernel="linear") clf = SVC(kernel="linear")
clf.fit(X_train_transformed, Y_train) clf.fit(X_train_transformed, Y_train)
print(clf.score(X_test_transformed, Y_test)) score = clf.score(X_test_transformed, Y_test)
lst_output = [str(score), str(len(subsample)), str(gamma)]
print(",".join(lst_output))
if __name__ == "__main__": if __name__ == "__main__":
arguments = docopt.docopt(__doc__) arguments = docopt.docopt(__doc__)
print(arguments) # print(arguments)
SUBSAMPLE_SIZE = int(arguments["--subsample-size-nystrom"]) SUBSAMPLE_SIZE = int(arguments["--subsample-size-nystrom"])
gamma = float(arguments["--gamma-nystrom"]) gamma = float(arguments["--gamma-nystrom"])
nystroem = arguments["--nystroem"] nystroem = arguments["--nystroem"]
deepstrom = arguments["--deepstrom"] deepstrom = arguments["--deepstrom"]
num_epoch = int(arguments["--num-epoch"]) num_epoch = int(float(arguments["--num-epoch"]))
batch_size = int(arguments["--batch-size"]) batch_size = int(arguments["--batch-size"])
mnist = dataset.MnistDataset() mnist = dataset.MnistDataset()
mnist.load() mnist.load()
mnist.normalize() mnist.normalize()
np.random.seed(0)
indexes_nystrom = np.random.permutation(60000)[:SUBSAMPLE_SIZE] indexes_nystrom = np.random.permutation(60000)[:SUBSAMPLE_SIZE]
if nystroem: if nystroem:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment