# Training data train_samples = [] for digit in range(10): # 0->9 for ten_by_ten_matrix in dataset.sample(5, digit, digit): # 5 x 'digit' train_samples.append(ten_by_ten_matrix) train_samples = np.asarray(train_samples).reshape(50, 100) X_train = train_samples.astype('float32') y_train = dtl.get_layer_output()[1] Y_train = np_utils.to_categorical(y_train) # 50*10 one hot matrix (encoded outputs) # Testing data i = 0 test_samples = [] y_test = np.zeros((50, 1)) for digit in range(10): # 0->9 for ten_by_ten_matrix in dataset.new_sample(5, digit): test_samples.append(ten_by_ten_matrix) y_test[i] = digit i += 1 test_samples = np.asarray(test_samples).reshape(50, 100) X_test = test_samples.astype('float32') Y_test = np_utils.to_categorical(y_test) # 50*10 one hot matrix (encoded outputs) num_classes = Y_test.shape[1] def keras_model(): # create model model = Sequential() # first hidden layer with 20 neurons model.add(Dense(100, input_shape=(100,))) model.add(Activation('relu'))
dataset = MNIST(n_components=100, reshape=False) np.random.seed(7) # for reproducibility max_voltage = 64 # Training data x_train, y_train = dtl.get_layer_output() X_train = x_train.astype('float32') / max_voltage # normalize Y_train = np_utils.to_categorical(y_train) # 50*10 one hot matrix (encoded outputs) # Testing data y_test = np.array(y_train, copy=True) x_test = np.array(x_train, copy=True) new_x = [] for digit in range(10): # 0->9 for vector in dataset.new_sample(1, digit): print('c**k {}'.format(digit)) voltages = dtl.classify(vector) # output of tempotron layer, list len 10 new_x.append(voltages) y_test = np.append(y_test, [digit]) x_test = np.append(x_test, np.asarray(new_x)).reshape(len(x_test)+len(new_x), 10) X_test = x_test.astype('float32') / max_voltage Y_test = np_utils.to_categorical(y_test) """ np.random.seed(7) # for reproducibility # load data, output matrices from tempotron # With 50 training images and 50 testing images