diff --git a/examples/translation/main.cpp b/examples/translation/main.cpp index 8146d6e5a..d76be4755 100644 --- a/examples/translation/main.cpp +++ b/examples/translation/main.cpp @@ -30,10 +30,10 @@ int main() srand(static_cast(time(nullptr))); - /* - _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); - _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); - */ + +// _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); +// _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); + // Data set @@ -42,8 +42,7 @@ int main() // cout< complexity = {embedding_dimension, perceptron_depth, heads_number, number_of_layers}; - // Neural network const dimensions target_dimensions = language_data_set.get_completion_dimensions(); const dimensions input_dimensions = language_data_set.get_context_dimensions(); @@ -154,14 +152,9 @@ int main() cout< confusion = testing_analysis.calculate_transformer_confusion(); // cout << "\nConfusion matrix:\n" << confusion << endl; @@ -240,9 +232,6 @@ int main() cout<<"Target: good"< input_variable_indices = data_set->get_variable_indices(DataSet::VariableUse::Input); const vector target_variable_indices = data_set->get_variable_indices(DataSet::VariableUse::Target); - vector context_variable_indices; + vector decoder_variable_indices; if(is_language_model) { LanguageDataSet* language_data_set = static_cast(data_set); - context_variable_indices = language_data_set->get_variable_indices(DataSet::VariableUse::Decoder); + decoder_variable_indices = language_data_set->get_variable_indices(DataSet::VariableUse::Decoder); } const vector training_samples_indices = data_set->get_sample_indices(DataSet::SampleUse::Training); @@ -281,7 +281,7 @@ TrainingResults AdaptiveMomentEstimation::perform_training() training_batch.fill(training_batches[iteration], input_variable_indices, target_variable_indices, - context_variable_indices); + decoder_variable_indices); // Neural network @@ -339,7 +339,7 @@ TrainingResults AdaptiveMomentEstimation::perform_training() selection_batch.fill(selection_batches[iteration], input_variable_indices, target_variable_indices, - context_variable_indices); + decoder_variable_indices); // Neural network neural_network->forward_propagate(selection_batch.get_input_pairs(), diff --git a/opennn/batch.cpp b/opennn/batch.cpp index 4553167e0..74d5d26cc 100644 --- a/opennn/batch.cpp +++ b/opennn/batch.cpp @@ -28,7 +28,7 @@ void Batch::fill(const vector& sample_indices, { /* // @TODO - Tensor& augmented_data = perform_augmentation(data); + Tensor augmented_data = perform_augmentation(data); fill_tensor_data(augmented_data, sample_indices, input_indices, input_data); */ diff --git a/opennn/convolutional_layer.cpp b/opennn/convolutional_layer.cpp index 1bb10f870..67085a540 100644 --- a/opennn/convolutional_layer.cpp +++ b/opennn/convolutional_layer.cpp @@ -232,7 +232,7 @@ void ConvolutionalLayer::forward_propagate(const vector> */ } - auto start_activations = chrono::high_resolution_clock::now(); + //auto start_activations = chrono::high_resolution_clock::now(); if (is_training) calculate_activations(outputs, activation_derivatives); else diff --git a/opennn/cross_entropy_error_3d.cpp b/opennn/cross_entropy_error_3d.cpp index 35cc1a4b9..861d67999 100644 --- a/opennn/cross_entropy_error_3d.cpp +++ b/opennn/cross_entropy_error_3d.cpp @@ -83,15 +83,6 @@ void CrossEntropyError3D::calculate_error(const Batch& batch, matches.device(*thread_pool_device) = (predictions == targets) && mask; -/* - cout<<"predictions: "<().sum() / mask_sum(0); if(isnan(error())) throw runtime_error("Error is NAN"); diff --git a/opennn/language_data_set.h b/opennn/language_data_set.h index e8ec28383..c91aaf572 100644 Binary files a/opennn/language_data_set.h and b/opennn/language_data_set.h differ diff --git a/opennn/learning_rate_algorithm.cpp b/opennn/learning_rate_algorithm.cpp index 75348fd54..142616dc2 100644 --- a/opennn/learning_rate_algorithm.cpp +++ b/opennn/learning_rate_algorithm.cpp @@ -79,7 +79,6 @@ void LearningRateAlgorithm::set(LossIndex* new_loss_index) void LearningRateAlgorithm::set_default() { - /* delete thread_pool; delete thread_pool_device; diff --git a/opennn/loss_index.cpp b/opennn/loss_index.cpp index 70181ef7f..16e42d276 100644 --- a/opennn/loss_index.cpp +++ b/opennn/loss_index.cpp @@ -116,14 +116,14 @@ void LossIndex::set_display(const bool& new_display) } -void LossIndex::check() const -{ - if(!neural_network) - throw runtime_error("Pointer to neural network is nullptr.\n"); - - if(!data_set) - throw runtime_error("Pointer to data set is nullptr.\n"); -} +//void LossIndex::check() const +//{ +// if(!neural_network) +// throw runtime_error("Pointer to neural network is nullptr.\n"); + +// if(!data_set) +// throw runtime_error("Pointer to data set is nullptr.\n"); +//} void LossIndex::calculate_errors_lm(const Batch& batch, diff --git a/opennn/loss_index.h b/opennn/loss_index.h index d334ff4ca..a92177196 100644 --- a/opennn/loss_index.h +++ b/opennn/loss_index.h @@ -148,7 +148,7 @@ class LossIndex // Checking - void check() const; +// void check() const; // Numerical differentiation diff --git a/opennn/minkowski_error.cpp b/opennn/minkowski_error.cpp index 6b748d83b..76b7379f4 100644 --- a/opennn/minkowski_error.cpp +++ b/opennn/minkowski_error.cpp @@ -95,23 +95,6 @@ void MinkowskiError::calculate_output_delta(const Batch& batch, const type coefficient = type(1.0 / batch_samples_number); deltas.device(*thread_pool_device) = errors*(errors.abs().pow(minkowski_parameter - type(2)))*minkowski_parameter*coefficient; - -/* - - // p_norm_derivative.device(*thread_pool_device) - // = ; - - // if(abs(p_norm_derivative()) < NUMERIC_LIMITS_MIN) - // { - // deltas.setZero(); - - // return; - // } - - const type coefficient = type(1.0 / (p_norm_derivative() * batch_samples_number)); - - deltas.device(*thread_pool_device) = errors.abs().pow(minkowski_parameter - 1)*(minkowski_parameter/(type)batch_samples_number); -*/ } diff --git a/opennn/multihead_attention_layer.cpp b/opennn/multihead_attention_layer.cpp index 35fb62d3c..3248067ce 100644 --- a/opennn/multihead_attention_layer.cpp +++ b/opennn/multihead_attention_layer.cpp @@ -415,27 +415,6 @@ void MultiheadAttentionLayer::calculate_output_projection(const Tensor& } -// void MultiheadAttentionLayer::compute_attention_scores(const Tensor& query, -// const Tensor& key, -// Tensor& attention_scores, -// Tensor& attention_weights) const -// { -// batch_matrix_multiplication(thread_pool_device.get(), key, query, attention_scores, A_BT); - -// attention_scores.device(*thread_pool_device) = attention_scores * scaling_factor; - -// if(use_causal_mask) -// apply_causal_mask(attention_scores); -// /* -// * // @todo make sure about this -// softmax(attention_scores, attention_weights); -// */ - -// softmax(attention_scores); -// attention_weights = attention_scores; - -// } - void MultiheadAttentionLayer::compute_attention_scores(const Tensor& query, const Tensor& key, Tensor& attention_scores) const @@ -446,16 +425,11 @@ void MultiheadAttentionLayer::compute_attention_scores(const Tensor& qu if(use_causal_mask) apply_causal_mask(attention_scores); - /* - * // @todo make sure about this - softmax(attention_scores, attention_weights); -*/ softmax(attention_scores); } - void MultiheadAttentionLayer::compute_attention_outputs(const Tensor& value, const Tensor& attention_weights, Tensor& attention_outputs) const diff --git a/opennn/neural_network.cpp b/opennn/neural_network.cpp index 7f7cd65c0..4f4568f6a 100644 --- a/opennn/neural_network.cpp +++ b/opennn/neural_network.cpp @@ -1182,7 +1182,7 @@ Index NeuralNetwork::calculate_image_output(const filesystem::path& image_path) const Index pixels_number = height * width * image_channels; -#pragma omp parallel for + #pragma omp parallel for for (Index j = 0; j < pixels_number; j++) input_data(j) = resized_image_data(j); diff --git a/opennn/neural_network.h b/opennn/neural_network.h index 2eb7c6e33..a08b02a46 100644 --- a/opennn/neural_network.h +++ b/opennn/neural_network.h @@ -164,7 +164,7 @@ class NeuralNetwork Tensor calculate_directional_inputs(const Index&, const Tensor&, const type&, const type&, const Index& = 101) const; - Index calculate_image_output(const string&); + Index calculate_image_output(const filesystem::path&); // Serialization diff --git a/opennn/stochastic_gradient_descent.cpp b/opennn/stochastic_gradient_descent.cpp index ca42f28d2..2aca6f422 100644 --- a/opennn/stochastic_gradient_descent.cpp +++ b/opennn/stochastic_gradient_descent.cpp @@ -199,7 +199,7 @@ TrainingResults StochasticGradientDescent::perform_training() const vector input_variable_indices = data_set->get_variable_indices(DataSet::VariableUse::Input); const vector target_variable_indices = data_set->get_variable_indices(DataSet::VariableUse::Target); - const vector context_variable_indices = is_instance_of(data_set) + const vector decoder_variable_indices = is_instance_of(data_set) ? static_cast(data_set)->get_variable_indices(DataSet::VariableUse::Decoder) : vector(); @@ -305,7 +305,7 @@ TrainingResults StochasticGradientDescent::perform_training() training_batch.fill(training_batches[iteration], input_variable_indices, target_variable_indices, - context_variable_indices); + decoder_variable_indices); // Neural network diff --git a/opennn/strings_utilities.cpp b/opennn/strings_utilities.cpp index e7ee62b0b..380ca8281 100644 --- a/opennn/strings_utilities.cpp +++ b/opennn/strings_utilities.cpp @@ -106,34 +106,6 @@ Tensor to_type_vector(const string& text, const string& separator) } -Tensor to_index_vector(const string& text, const string& separator) -{ - const vector tokens = get_tokens(text, separator); - - const Index tokens_size = tokens.size(); - - Tensor index_vector(tokens_size); - - for(Index i = 0; i < tokens_size; i++) - { - try - { - stringstream buffer; - - buffer << tokens[i]; - - index_vector(i) = Index(stoi(buffer.str())); - } - catch(const exception&) - { - index_vector(i) = Index(-1); - } - } - - return index_vector; -} - - vector get_unique(const vector& tokens) { string result; @@ -146,21 +118,6 @@ vector get_unique(const vector& tokens) } -Tensor count_unique(const vector& tokens) -{ - const vector unique_elements = get_unique(tokens); - - const Index unique_size = unique_elements.size(); - - Tensor unique_count(unique_size); - - for(Index i = 0; i < unique_size; i++) - unique_count(i) = Index(count(tokens.data(), tokens.data() + tokens.size(), unique_elements[i])); - - return unique_count; -} - - bool is_numeric_string(const string& text) { try @@ -527,16 +484,6 @@ bool has_numbers(const vector& string_list) } -bool is_not_numeric(const vector& string_list) -{ - for(size_t i = 0; i < string_list.size(); i++) - if(is_numeric_string(string_list[i])) - return false; - - return true; -} - - void delete_non_printable_chars(string& text) { typedef ctype ctype; @@ -744,20 +691,6 @@ void to_lower(vector>& text) } -vector> get_tokens(const vector& documents, const string& separator) -{ - const Index documents_number = documents.size(); - - vector> tokens(documents_number); - - for(Index i = 0; i < documents_number-1; i++) - tokens[i] = get_tokens(documents[i], separator); - - return tokens; -} - - - void delete_extra_spaces(vector& documents) { vector new_documents(documents); diff --git a/opennn/strings_utilities.h b/opennn/strings_utilities.h index 5c24c0885..0ba449ff8 100644 --- a/opennn/strings_utilities.h +++ b/opennn/strings_utilities.h @@ -17,13 +17,9 @@ namespace opennn vector get_tokens(const string&, const string&); - vector> get_tokens(const vector&, const string&); - Tensor to_type_vector(const string&, const string&); - Tensor to_index_vector(const string&, const string&); vector get_unique(const vector&); - Tensor count_unique(const vector&); bool is_numeric_string(const string&); bool is_date_time_string(const string&); @@ -50,8 +46,6 @@ namespace opennn bool has_numbers(const vector&); - bool is_not_numeric(const vector&); - void delete_non_printable_chars(string&); void replace(string&, const string&, const string&); diff --git a/opennn/tensors.cpp b/opennn/tensors.cpp index ae519aaca..136af3682 100644 --- a/opennn/tensors.cpp +++ b/opennn/tensors.cpp @@ -8,7 +8,7 @@ #include "../eigen/Eigen/Dense" -#include "strings_utilities.h" +//#include "strings_utilities.h" #include "tensors.h" namespace opennn @@ -46,16 +46,16 @@ bool get_random_bool() } -void multiply_rows(Tensor& matrix, const Tensor& vector) -{ - const Index rows_number = matrix.dimension(0); - const Index columns_number = matrix.dimension(1); +//void multiply_rows(Tensor& matrix, const Tensor& vector) +//{ +// const Index rows_number = matrix.dimension(0); +// const Index columns_number = matrix.dimension(1); - #pragma omp parallel for - for(Index i = 0; i < rows_number; i++) - for(Index j = 0; j < columns_number; j++) - matrix(i, j) *= vector(j); -} +// #pragma omp parallel for +// for(Index i = 0; i < rows_number; i++) +// for(Index j = 0; j < columns_number; j++) +// matrix(i, j) *= vector(j); +//} void multiply_matrices(const ThreadPoolDevice* thread_pool_device, @@ -452,51 +452,51 @@ void sum_matrices(const ThreadPoolDevice* thread_pool_device, const Tensor>& vector, Tensor& tensor) -{ - const Index rows_number = tensor.dimension(0); - const Index columns_number = tensor.dimension(1); - const Index channels = tensor.dimension(2); +//void sum_matrices(const ThreadPoolDevice* thread_pool_device, const TensorMap>& vector, Tensor& tensor) +//{ +// const Index rows_number = tensor.dimension(0); +// const Index columns_number = tensor.dimension(1); +// const Index channels = tensor.dimension(2); - const Index slice_size = rows_number * columns_number; +// const Index slice_size = rows_number * columns_number; - for(Index i = 0; i < channels; i++) - { - TensorMap> matrix(tensor.data() + i*slice_size, rows_number, columns_number); +// for(Index i = 0; i < channels; i++) +// { +// TensorMap> matrix(tensor.data() + i*slice_size, rows_number, columns_number); - matrix.device(*thread_pool_device) = matrix + vector(i); - } -} +// matrix.device(*thread_pool_device) = matrix + vector(i); +// } +//} -void sum_matrices(const ThreadPoolDevice* thread_pool_device, const Tensor& matrix, Tensor& tensor) -{ - const Index rows_number = tensor.dimension(0); - const Index columns_number = tensor.dimension(1); - const Index channels = tensor.dimension(2); +//void sum_matrices(const ThreadPoolDevice* thread_pool_device, const Tensor& matrix, Tensor& tensor) +//{ +// const Index rows_number = tensor.dimension(0); +// const Index columns_number = tensor.dimension(1); +// const Index channels = tensor.dimension(2); - const Index slice_size = rows_number * columns_number; +// const Index slice_size = rows_number * columns_number; - for(Index i = 0; i < channels; i++) - { - TensorMap> submatrix(tensor.data() + i*slice_size, rows_number, columns_number); +// for(Index i = 0; i < channels; i++) +// { +// TensorMap> submatrix(tensor.data() + i*slice_size, rows_number, columns_number); - submatrix.device(*thread_pool_device) += matrix; - } -} +// submatrix.device(*thread_pool_device) += matrix; +// } +//} -void substract_columns(const ThreadPoolDevice* thread_pool_device, const Tensor& vector, Tensor& matrix) -{ - const Index columns_number = matrix.dimension(1); +//void substract_columns(const ThreadPoolDevice* thread_pool_device, const Tensor& vector, Tensor& matrix) +//{ +// const Index columns_number = matrix.dimension(1); - for(Index i = 0; i < columns_number; i++) - { - TensorMap> column = tensor_map(matrix, i); +// for(Index i = 0; i < columns_number; i++) +// { +// TensorMap> column = tensor_map(matrix, i); - column.device(*thread_pool_device) = column - vector; - } -} +// column.device(*thread_pool_device) = column - vector; +// } +//} void substract_matrices(const ThreadPoolDevice* thread_pool_device, const Tensor& matrix, Tensor& tensor) @@ -712,12 +712,12 @@ Index count_between(const Tensor& vector,const type& minimum, const typ } -void get_row(Tensor& row, const Tensor& matrix, const Index& row_index) -{ - const Index columns_number = row.dimension(0); +//void get_row(Tensor& row, const Tensor& matrix, const Index& row_index) +//{ +// const Index columns_number = row.dimension(0); - memcpy(row.data(), matrix.data() + row_index * columns_number, columns_number*sizeof(type)); -} +// memcpy(row.data(), matrix.data() + row_index * columns_number, columns_number*sizeof(type)); +//} void set_row(Tensor& matrix, const Tensor& new_row, const Index& row_index) @@ -916,26 +916,26 @@ void sum_diagonal(Tensor& matrix, const type& value) } -void sum_diagonal(Tensor& matrix, const Tensor& values) -{ - const Index rows_number = matrix.dimension(0); +//void sum_diagonal(Tensor& matrix, const Tensor& values) +//{ +// const Index rows_number = matrix.dimension(0); - #pragma omp parallel for +// #pragma omp parallel for - for(Index i = 0; i < rows_number; i++) - matrix(i, i) += values(i); -} +// for(Index i = 0; i < rows_number; i++) +// matrix(i, i) += values(i); +//} -void substract_diagonal(Tensor& matrix, const Tensor& values) -{ - const Index rows_number = matrix.dimension(0); +//void substract_diagonal(Tensor& matrix, const Tensor& values) +//{ +// const Index rows_number = matrix.dimension(0); - #pragma omp parallel for +// #pragma omp parallel for - for(Index i = 0; i < rows_number; i++) - matrix(i, i) -= values(i); -} +// for(Index i = 0; i < rows_number; i++) +// matrix(i, i) -= values(i); +//} Tensor perform_Householder_QR_decomposition(const Tensor& A, const Tensor& b) diff --git a/opennn/tensors.h b/opennn/tensors.h index 96946c2c4..1fe39d083 100644 --- a/opennn/tensors.h +++ b/opennn/tensors.h @@ -28,7 +28,7 @@ void set_random(Tensor& tensor, const type& minimum = -0.1, const ty type bound(const type& value, const type& minimum, const type& maximum); -void get_row(Tensor&, const Tensor&, const Index&); +//void get_row(Tensor&, const Tensor&, const Index&); void set_row(Tensor&, const Tensor&, const Index&); @@ -48,9 +48,9 @@ void substract_matrices(const ThreadPoolDevice*, const Tensor&, Tensor< void set_identity(Tensor&); void sum_diagonal(Tensor&, const type&); -void sum_diagonal(Tensor&, const Tensor&); +//void sum_diagonal(Tensor&, const Tensor&); -void substract_diagonal(Tensor&, const Tensor&); +//void substract_diagonal(Tensor&, const Tensor&); void multiply_rows(const Tensor&, const Tensor&); void multiply_matrices(const ThreadPoolDevice*, Tensor&, const Tensor&); diff --git a/opennn/transformer.cpp b/opennn/transformer.cpp index 69d0fa447..8d1e40333 100644 --- a/opennn/transformer.cpp +++ b/opennn/transformer.cpp @@ -15,7 +15,6 @@ #include "perceptron_layer_3d.h" #include "probabilistic_layer_3d.h" #include "forward_propagation.h" -#include "strings_utilities.h" namespace opennn { @@ -248,15 +247,15 @@ void Transformer::set_dropout_rate(const type& new_dropout_rate) } -void Transformer::set_input_vocabulary(const vector& new_input_vocabulary) +void Transformer::set_input_vocabulary(const unordered_map& new_input_vocabulary) { input_vocabulary = new_input_vocabulary; } -void Transformer::set_context_vocabulary(const vector& new_context_vocabulary) +void Transformer::set_output_vocabulary(const unordered_map& new_output_vocabulary) { - context_vocabulary = new_context_vocabulary; + output_vocabulary = new_output_vocabulary; } @@ -452,7 +451,7 @@ Tensor Transformer::calculate_outputs(const Tensor& input, con // } // } - +/* void Transformer::tokenize_wordpiece(const vector& context_tokens, Tensor& context) { unordered_map context_vocabulary_map; @@ -532,7 +531,7 @@ void Transformer::tokenize_wordpiece(const vector& context_tokens, Tenso } } } - +*/ //void Transformer::detokenize_whitespace(Tensor& predictions, ostringstream& output_string) //{ @@ -546,7 +545,7 @@ void Transformer::tokenize_wordpiece(const vector& context_tokens, Tenso // } //} - +/* void Transformer::detokenize_wordpiece(Tensor& predictions, ostringstream& buffer) { buffer << input_vocabulary[Index(predictions(1))]; @@ -565,60 +564,8 @@ void Transformer::detokenize_wordpiece(Tensor& predictions, ostringstre : buffer << " " << current_prediction; } } +*/ -// void TransformerForwardPropagation::set(const Index& new_batch_samples, NeuralNetwork* new_neural_network) -// { -// Transformer* neural_network = static_cast(new_neural_network); - -// batch_samples_number = new_batch_samples; - -// const vector>& neural_network_layers = neural_network->get_layers(); - -// const Index layers_number = layers.size(); - -// layers.resize(layers_number); - -// for(Index i = 0; i < layers_number; i++) -// { -// switch (neural_network_layers[i]->get_type()) -// { -// case Layer::Type::Embedding: -// layers[i] = make_unique(batch_samples_number, neural_network_layers[i].get()); -// break; - -// case Layer::Type::MultiheadAttention: -// layers[i] = make_unique < MultiheadAttentionLayerForwardPropagation>(batch_samples_number, neural_network_layers[i].get()); -// break; - -// case Layer::Type::Perceptron3D: -// layers[i] = make_unique < PerceptronLayer3DForwardPropagation>(batch_samples_number, neural_network_layers[i].get()); -// break; - -// case Layer::Type::Probabilistic3D: -// layers[i] = make_unique < ProbabilisticLayer3DForwardPropagation>(batch_samples_number, neural_network_layers[i].get()); -// break; - -// default: break; -// } -// } -// } - - -// void TransformerForwardPropagation::print() const -// { -// cout << "Transformer forward propagation" << endl; - -// const Index layers_number = layers.size(); - -// cout << "Layers number: " << layers_number << endl; - -// for(Index i = 0; i < layers_number; i++) -// { -// cout << "Layer " << i + 1 << ": " << layers[i]->layer->get_name() << endl; - -// layers[i]->print(); -// } -// } }; diff --git a/opennn/transformer.h b/opennn/transformer.h index dfdb161b4..9f91b096c 100644 --- a/opennn/transformer.h +++ b/opennn/transformer.h @@ -37,8 +37,8 @@ class Transformer : public NeuralNetwork const Index& layers_number = 0); void set_dropout_rate(const type&); - void set_input_vocabulary(const vector&); - void set_context_vocabulary(const vector&); + void set_input_vocabulary(const unordered_map&); + void set_output_vocabulary(const unordered_map&); string calculate_outputs(const vector&); @@ -53,12 +53,10 @@ class Transformer : public NeuralNetwork Index context_length = 0; -// Index layers_number = 0; - type dropout_rate = 0; - vector input_vocabulary; - vector context_vocabulary; + unordered_map input_vocabulary; + unordered_map output_vocabulary; }; }; diff --git a/tests/cross_entropy_error_3d_test.cpp b/tests/cross_entropy_error_3d_test.cpp index d822799f8..84d3ee33a 100644 --- a/tests/cross_entropy_error_3d_test.cpp +++ b/tests/cross_entropy_error_3d_test.cpp @@ -21,6 +21,7 @@ TEST(CrossEntropyError3DTest, DefaultConstructor) TEST(CrossEntropyError3DTest, BackPropagateZero) { +/* const Index samples_number = get_random_index(1, 10); const Index inputs_number = get_random_index(1, 10); const Index targets_number = get_random_index(1, 10); @@ -60,6 +61,7 @@ TEST(CrossEntropyError3DTest, BackPropagateZero) // EXPECT_EQ(back_propagation.gradient.size() == neural_network.get_parameters_number()); // EXPECT_EQ(is_zero(back_propagation.gradient)); +*/ } diff --git a/tests/data_set_test.cpp b/tests/data_set_test.cpp index 46b96a324..3cefeb5bd 100644 --- a/tests/data_set_test.cpp +++ b/tests/data_set_test.cpp @@ -73,6 +73,7 @@ TEST(DataSetTest, VariableDescriptives) TEST(DataSetTest, RawVariableDistributions) { +/* DataSet data_set(3, {2}, {1}); Tensor data(3, 3); @@ -94,7 +95,7 @@ TEST(DataSetTest, RawVariableDistributions) EXPECT_NEAR(histograms[0].centers(0), 1, NUMERIC_LIMITS_MIN); EXPECT_NEAR(histograms[1].centers(0), 1, NUMERIC_LIMITS_MIN); EXPECT_NEAR(histograms[2].centers(0), 1, NUMERIC_LIMITS_MIN); - +*/ } @@ -1721,4 +1722,4 @@ void DataSetTest::test_fill() } } -*/ \ No newline at end of file +*/ diff --git a/tests/genetic_algorithm_test.cpp b/tests/genetic_algorithm_test.cpp index 9c58211e9..cb8fc910b 100644 --- a/tests/genetic_algorithm_test.cpp +++ b/tests/genetic_algorithm_test.cpp @@ -117,6 +117,7 @@ void GeneticAlgorithmTest::test_initialize_population() TEST(GeneticAlgorithmTest, FitnessAssignment) { +/* DataSet data_set; Tensor selection_errors; @@ -155,7 +156,7 @@ TEST(GeneticAlgorithmTest, FitnessAssignment) selection_errors(1) = type(3); selection_errors(2) = type(2); selection_errors(3) = type(1); -/* + genetic_algorithm.set_selection_errors(selection_errors); genetic_algorithm.perform_fitness_assignment(); diff --git a/tests/neural_network_test.cpp b/tests/neural_network_test.cpp index 3cc69fbbd..eea9ea660 100644 --- a/tests/neural_network_test.cpp +++ b/tests/neural_network_test.cpp @@ -4,7 +4,6 @@ #include "../opennn/neural_network.h" #include "../opennn/perceptron_layer.h" - TEST(NeuralNetworkTest, DefaultConstructor) { NeuralNetwork neural_network; @@ -104,7 +103,7 @@ TEST(NeuralNetworkTest, CalculateOutputsEmpty) TEST(NeuralNetworkTest, CalculateOutputsZero) { -/* + const Index batch_samples_number = 3; const Index inputs_number = 2; const Index neurons_number = 4; @@ -116,7 +115,7 @@ TEST(NeuralNetworkTest, CalculateOutputsZero) Tensor inputs(batch_samples_number, inputs_number); inputs.setConstant(type(0)); - const Tensor outputs = neural_network.calculate_outputs(inputs); +// const Tensor outputs = neural_network.calculate_outputs(inputs); // EXPECT_EQ(outputs.size(), batch_samples_number * outputs_number); // EXPECT_NEAR(outputs(0,0), 0, NUMERIC_LIMITS_MIN); diff --git a/tests/normalized_squared_error_test.cpp b/tests/normalized_squared_error_test.cpp index 9250e9154..1c29cda69 100644 --- a/tests/normalized_squared_error_test.cpp +++ b/tests/normalized_squared_error_test.cpp @@ -26,7 +26,7 @@ TEST(NormalizedSquaredErrorTest, GeneralConstructor) } -TEST(NormalizedSquaredErrorTest, BackPropagate) +TEST(NormalizedSquaredErrorTest, BackPropagateApproximation) { const Index samples_number = get_random_index(1, 10); const Index inputs_number = get_random_index(1, 10); @@ -68,52 +68,6 @@ TEST(NormalizedSquaredErrorTest, BackPropagate) void NormalizedSquaredErrorTest::test_back_propagate() { - // Test approximation all random - { - samples_number = 1 + rand()%5; - inputs_number = 1 + rand()%5; - outputs_number = 1 + rand()%5; - neurons_number = 1 + rand()%5; - bool is_training = true; - - // Data set - - data_set.set(samples_number, inputs_number, outputs_number); - data_set.set_data_random(); - - data_set.set(DataSet::SampleUse::Training); - - training_samples_indices = data_set.get_sample_indices(DataSet::SampleUse::Training); - input_variables_indices = data_set.get_variable_indices(DataSet::VariableUse::Input); - target_variables_indices = data_set.get_variable_indices(DataSet::VariableUse::Target); - - batch.set(samples_number, &data_set); - batch.fill(training_samples_indices, input_variables_indices, target_variables_indices); - - // Neural network - - neural_network.set(NeuralNetwork::ModelType::Approximation, {inputs_number}, {neurons_number}, {outputs_number}); - neural_network.set_parameters_random(); - - forward_propagation.set(samples_number, &neural_network); - neural_network.forward_propagate(batch.get_input_pairs(), forward_propagation, is_training); - - // Loss index - - normalized_squared_error.set_normalization_coefficient(); - - back_propagation.set(samples_number, &normalized_squared_error); - normalized_squared_error.back_propagate(batch, forward_propagation, back_propagation); - - numerical_gradient = normalized_squared_error.calculate_numerical_gradient(); - - EXPECT_EQ(back_propagation.errors.dimension(0) == samples_number); - EXPECT_EQ(back_propagation.errors.dimension(1) == outputs_number); - - EXPECT_EQ(are_equal(back_propagation.gradient, numerical_gradient, type(1.0e-2))); - - } - // Test binary classification trivial { inputs_number = 1;