def test_predict_2(): number_of_classes = 10 number_of_training_samples_to_use = 3 (X_train, y_train), (X_test, y_test) = tf.keras.datasets.mnist.load_data() X_train_vectorized = ((X_train.reshape( X_train.shape[0], -1)).T)[:, 0:number_of_training_samples_to_use] y_train = y_train[0:number_of_training_samples_to_use] input_dimensions = X_train_vectorized.shape[0] model = Hebbian(input_dimensions=input_dimensions, number_of_classes=number_of_classes, transfer_function="Linear", seed=5) Y_hat = model.predict(X_train_vectorized) np.testing.assert_almost_equal(Y_hat, np.array( \ [[-4101.41409432, -3820.1709349, -1235.86331202], [854.07167203, 4061.22006877, 434.40971256], [-552.17756811, -1791.61373625, -2591.16737069], [-355.4367891, -3858.75847581, 1320.1141753], [1087.86080571, -607.49532925, -460.80234811], [-2459.84338339, -1681.30331925, -255.00327678], [-460.58803655, -4439.85928602, -1093.82071536], [4066.25628304, 4814.90762933, 1955.78972208], [564.64444411, -3117.99849963, -419.49244877], [-2374.84426405, -2878.08764629, 2979.99404738]]), decimal=2) model = Hebbian(input_dimensions=input_dimensions, number_of_classes=number_of_classes, transfer_function="Hard_limit", seed=5) Y_hat = model.predict(X_train_vectorized) assert (np.allclose(Y_hat, np.array( \ [[0, 0, 0], [1, 1, 1], [0, 0, 0], [0, 0, 1], [1, 0, 0], [0, 0, 0], [0, 0, 0], [1, 1, 1], [1, 0, 0], [0, 0, 1]]),rtol=1e-3, atol=1e-3)) model = Hebbian(input_dimensions=input_dimensions, number_of_classes=number_of_classes, transfer_function="Hard_limit", seed=5) Y_hat = model.predict(X_train_vectorized) assert np.allclose(Y_hat, np.array( \ [[0.00000000e+000, 0.00000000e+000, 0.00000000e+000], [1.00000000e+000, 1.00000000e+000, 1.00000000e+000], [1.55714531e-240, 0.00000000e+000, 0.00000000e+000], [4.32278692e-155, 0.00000000e+000, 1.00000000e+000], [1.00000000e+000, 1.47275575e-264, 7.51766500e-201], [0.00000000e+000, 0.00000000e+000, 1.79260263e-111], [9.31445172e-201, 0.00000000e+000, 0.00000000e+000], [1.00000000e+000, 1.00000000e+000, 1.00000000e+000], [1.00000000e+000, 0.00000000e+000, 6.55759060e-183], [0.00000000e+000, 0.00000000e+000, 1.00000000e+000]]),rtol=1e-3, atol=1e-3)
def test_predict(): input_dimensions = 2 number_of_classes = 2 model = Hebbian(input_dimensions=input_dimensions, number_of_classes=number_of_classes, transfer_function="Hard_limit",seed=1) X_train = np.array([[-1.43815556, 0.10089809, -1.25432937, 1.48410426], [-1.81784194, 0.42935033, -1.2806198, 0.06527391]]) model.initialize_all_weights_to_zeros() Y_hat = model.predict(X_train) assert (np.array_equal(Y_hat, np.array([[0,0,0,0], [0,0,0,0]]))) or \ (np.array_equal(Y_hat, np.array([[1,1,1,1], [1,1,1,1]])))