ind1 = np.random.choice(np.arange(y.size), 5000) x = x[ind1,:] y = y[ind1] # xtest = x_test[indices2,:] ytest = t_test[indices2] ytest = np.cast[int](ytest) ytest[ytest==4]=-1 ytest[ytest==9]=1 ind2 = np.random.choice(np.arange(ytest.size),500) xtest = xtest[ind2,:] ytest = ytest[ind2] ''' import mnist_subset x, y, xtest, ytest = mnist_subset.init(4, 9, 2500, 500) #### Useing data from class here #mnist_49_3000 = sio.loadmat('mnist_49_3000.mat') #X = mnist_49_3000['x'] #Y = mnist_49_3000['y'] #X = X.T #Y = Y[0,:] # #numofx =1000 #x = X[:numofx,:] # X= x+xtest #y = Y[:numofx] #xtest = X[numofx:, :] #ytest = Y[numofx:] numoftrain = 10
#!/usr/bin/env python3 # -*- coding: utf-8 -*- #Author: Saibal De #Class: EECS545 Machine Learning #Title: LP with Random Queries #Date: 12-12-2018 import numpy as np import mnist_subset import mnist_graph from lp import LP x_train, y_train, _, _ = mnist_subset.init(4, 9, 2500, 0) graph = mnist_graph.init(x_train) y_train = (1 + y_train) / 2 inds = np.random.choice(np.arange(2500), 150, replace=False) accuracy = np.zeros(150, dtype=np.float) num_query = np.arange(1, 151) for i in range(150): graph.set_label(i, y_train[i]) LP(graph) accuracy[i] = graph.accuracy(y_train) np.savez("test_lp_random.npz", num_query=num_query, accuracy=accuracy)
#Author: Saibal De #Class: EECS545 Machine Learning #Title: LP with VOpt Queries #Date: 12-13-2018 import numpy as np import mnist_subset import mnist_graph from lp import LP from VM import VM num_train = 2500 num_test = 0 x_train, y_train, _, _ = mnist_subset.init(4, 9, num_train, num_test) graph = mnist_graph.init(x_train) y_train = (1 + y_train) / 2 num_query = np.arange(10, 151, 10) accuracy = np.zeros(num_queries.size, dtype=np.float) for j in range(num_queries.size): # Reset graph graph.u = [i for i in range(num_train)] graph.l = [] # Run VM indices = VM(graph.laplacian, num_train, num_queries[j]) # Query labels
import matplotlib.pyplot as plt import mnist_subset import mnist_graph from lp import LP from TSA import query_with_TSA # Parameters digit1 = 4 digit2 = 9 num_train = 1000 num_test = 0 # Load data and generate graph x_train, y_train, _, _ = mnist_subset.init(digit1, digit2, num_train, num_test) y_train = (1 + y_train) / 2 graph = mnist_graph.init(x_train) q = (y_train == 1).sum() / y_train.size print(graph.weights.max()) # Randomly initialize some labels np.random.seed(0) num_init_labels = 25 init_labels = np.random.choice(np.arange(0, num_train), num_init_labels, replace=False) for i in init_labels: graph.set_label(i, y_train[i])