<s> import numpy as np <EOL> from neupy import algorithms <EOL> from base import BaseTestCase <EOL> from utils import vectors_for_testing <EOL> class OjaTestCase ( BaseTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( OjaTestCase , self ) . setUp ( ) <EOL> self . data = np . array ( [ <EOL> [ <NUM_LIT:2> , <NUM_LIT:2> ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:4> , <NUM_LIT:4> ] , <EOL> [ <NUM_LIT:5> , <NUM_LIT:5> ] , <EOL> ] ) <EOL> self . result = np . array ( [ <EOL> [ <NUM_LIT> ] , <EOL> [ <NUM_LIT> ] , <EOL> [ <NUM_LIT> ] , <EOL> [ <NUM_LIT> ] , <EOL> ] ) <EOL> def test_oja_minimization ( self ) : <EOL> ojanet = algorithms . Oja ( <EOL> minimized_data_size = <NUM_LIT:1> , <EOL> step = <NUM_LIT> , <EOL> weights = np . ones ( ( <NUM_LIT:2> , <NUM_LIT:1> ) ) * <NUM_LIT:0.1> , <EOL> verbose = False <EOL> ) <EOL> ojanet . train ( self . data , epsilon = <NUM_LIT> , epochs = <NUM_LIT:100> ) <EOL> minimized_data = ojanet . predict ( self . data ) <EOL> np . testing . assert_array_almost_equal ( <EOL> minimized_data , self . result , <EOL> decimal = <NUM_LIT:2> <EOL> ) <EOL> reconstructed = ojanet . reconstruct ( minimized_data ) <EOL> np . testing . assert_array_almost_equal ( <EOL> reconstructed , self . data , <EOL> decimal = <NUM_LIT:3> <EOL> ) <EOL> def test_oja_exceptions ( self ) : <EOL> ojanet = algorithms . Oja ( minimized_data_size = <NUM_LIT:1> , step = <NUM_LIT> , <EOL> verbose = False ) <EOL> with self . assertRaises ( ValueError ) : <EOL> ojanet . reconstruct ( np . random . random ( ( <NUM_LIT:4> , <NUM_LIT:1> ) ) ) <EOL> with self . assertRaises ( ValueError ) : <EOL> ojanet . predict ( np . random . random ( ( <NUM_LIT:4> , <NUM_LIT:1> ) ) ) <EOL> ojanet . train ( self . data , epsilon = <NUM_LIT> ) <EOL> with self . assertRaises ( ValueError ) : <EOL> ojanet . reconstruct ( np . random . random ( ( <NUM_LIT:3> , <NUM_LIT:3> ) ) ) <EOL> with self . assertRaises ( ValueError ) : <EOL> ojanet . train ( np . random . random ( ( <NUM_LIT:4> , <NUM_LIT:10> ) ) ) <EOL> def test_train_different_inputs ( self ) : <EOL> self . assertInvalidVectorTrain ( <EOL> algorithms . Oja ( minimized_data_size = <NUM_LIT:1> , verbose = False ) , <EOL> np . array ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> ) <EOL> def test_predict_different_inputs ( self ) : <EOL> ojanet = algorithms . Oja ( minimized_data_size = <NUM_LIT:1> , verbose = False , <EOL> step = <NUM_LIT> ) <EOL> data = np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ] ) . T <EOL> target = np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ] ) . T <EOL> ojanet . train ( data , epsilon = <NUM_LIT> , epochs = <NUM_LIT:100> ) <EOL> self . assertInvalidVectorPred ( ojanet , data . ravel ( ) , target , <EOL> decimal = <NUM_LIT:2> ) <EOL> def test_reconstruct_different_inputs ( self ) : <EOL> ojanet = algorithms . Oja ( minimized_data_size = <NUM_LIT:1> , verbose = False , <EOL> step = <NUM_LIT> ) <EOL> data = np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ] ) . T <EOL> target = np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ] ) . T <EOL> input_vector = data . ravel ( ) <EOL> ojanet . train ( data , epsilon = <NUM_LIT> , epochs = <NUM_LIT:100> ) <EOL> test_vectors = vectors_for_testing ( input_vector ) <EOL> for i , test_vector in enumerate ( test_vectors , start = <NUM_LIT:1> ) : <EOL> np . testing . assert_array_almost_equal ( <EOL> ojanet . reconstruct ( test_vector ) , <EOL> target , <EOL> decimal = <NUM_LIT:1> <EOL> ) </s>
