def partition_data(X, y): """ Shuffles the input data and splits it into a new set of images. This resembles the experimental setup used in the paper on the Local Phase Quantization descriptor in: "Recognition of Blurred Faces Using Local Phase Quantization", Timo Ahonen, Esa Rahtu, Ville Ojansivu, Janne Heikkila What it does is to build a subset for each class, so it has 1 image for training and the rest for testing. The original dataset is shuffled for each call, hence you always get a new partitioning. """ Xs,ys = shuffle_array(X,y) # Maps index to class: mapping = {} for i in xrange(len(y)): yi = ys[i] try: mapping[yi].append(i) except KeyError: mapping[yi] = [i] # Get one image for each subject: Xtrain, ytrain = [], [] Xtest, ytest = [], [] # Finally build partition: for key, indices in mapping.iteritems(): # Add images: Xtrain.extend([ Xs[i] for i in indices[:1] ]) ytrain.extend([ ys[i] for i in indices[:1] ]) Xtest.extend([ Xs[i] for i in indices[1:20]]) ytest.extend([ ys[i] for i in indices[1:20]]) # Return shuffled partitions: return Xtrain, ytrain, Xtest, ytest
def partition_data(X, y): """ Shuffles the input data and splits it into a new set of images. This resembles the experimental setup used in the paper on the Local Phase Quantization descriptor in: "Recognition of Blurred Faces Using Local Phase Quantization", Timo Ahonen, Esa Rahtu, Ville Ojansivu, Janne Heikkila What it does is to build a subset for each class, so it has 1 image for training and the rest for testing. The original dataset is shuffled for each call, hence you always get a new partitioning. """ Xs, ys = shuffle_array(X, y) # Maps index to class: mapping = {} for i in xrange(len(y)): yi = ys[i] try: mapping[yi].append(i) except KeyError: mapping[yi] = [i] # Get one image for each subject: Xtrain, ytrain = [], [] Xtest, ytest = [], [] # Finally build partition: for key, indices in mapping.iteritems(): # Add images: Xtrain.extend([Xs[i] for i in indices[:1]]) ytrain.extend([ys[i] for i in indices[:1]]) Xtest.extend([Xs[i] for i in indices[1:20]]) ytest.extend([ys[i] for i in indices[1:20]]) # Return shuffled partitions: return Xtrain, ytrain, Xtest, ytest
def partition_data(X, y): Xs,ys = shuffle_array(X,y) mapping = {} for i in xrange(len(y)): yi = ys[i] try: mapping[yi].append(i) except KeyError: mapping[yi] = [i] Xtrain, ytrain = [], [] Xtest, ytest = [], [] for key, indices in mapping.iteritems(): Xtrain.extend([ Xs[i] for i in indices[:1] ]) ytrain.extend([ ys[i] for i in indices[:1] ]) Xtest.extend([ Xs[i] for i in indices[1:20]]) ytest.extend([ ys[i] for i in indices[1:20]]) return Xtrain, ytrain, Xtest, ytest