Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
RoberLopez committed Jan 15, 2025
1 parent 113c190 commit 8839ba6
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 77 deletions.
17 changes: 8 additions & 9 deletions tests/genetic_algorithm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void GeneticAlgorithmTest::test_initialize_population()

TEST(GeneticAlgorithmTest, FitnessAssignment)
{
/*

DataSet data_set;

Tensor<type, 1> selection_errors;
Expand Down Expand Up @@ -156,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();
Expand All @@ -171,17 +171,15 @@ TEST(GeneticAlgorithmTest, FitnessAssignment)

TEST(GeneticAlgorithmTest, Selection)
{
/*

Tensor<bool, 2> population;

Tensor<bool, 1> selection;

Tensor<type, 1> selection_errors;

Tensor<type, 1> fitness;
// Test 1
/*
genetic_algorithm.set_individuals_number(4);
fitness.resize(4);
Expand Down Expand Up @@ -277,9 +275,10 @@ TEST(GeneticAlgorithmTest, Selection)

TEST(GeneticAlgorithmTest, Crossover)
{
/*

Tensor<type, 2> data(10,5);
data.setRandom();
/*
data_set.set_data(data);
Tensor<bool, 2> population;
Expand Down Expand Up @@ -393,7 +392,7 @@ TEST(GeneticAlgorithmTest, Mutation)

TEST(GeneticAlgorithmTest, InputSelection)
{
/*

Tensor<type, 2> data;

InputsSelectionResults input_selection_results;
Expand All @@ -409,7 +408,7 @@ TEST(GeneticAlgorithmTest, InputSelection)
data(i,2) = type(10.0);
data(i,3) = type(i);
}
/*
data_set.set_data(data);
neural_network.set(NeuralNetwork::ModelType::Approximation, {2}, {6}, {1});
Expand Down
2 changes: 1 addition & 1 deletion tests/growing_neurons_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ TEST(GrowingNeuronsTest, NeuronsSelection)
training_strategy.set_display(false);

growing_neurons.set_trials_number(1);
growing_neurons.set_maximum_neurons_number(7);
growing_neurons.set_maximum_neurons(7);
growing_neurons.set_selection_error_goal(type(1.0e-3f));
growing_neurons.set_display(false);

Expand Down
130 changes: 63 additions & 67 deletions tests/transformer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ TEST(Transformer, GeneralConstructor)

TEST(Transformer, Outputs)
{
/*

Tensor<type, 2> inputs;
Tensor<type, 2> context;
Tensor<type, 2> outputs;
Expand All @@ -84,17 +84,19 @@ TEST(Transformer, Outputs)

// Test two layers perceptron with all zeros

input_length = 1;
context_length = 1;
input_dimensions = 1;
context_dimension = 1;
embedding_depth = 1;
perceptron_depth = 1;
heads_number = 1;
layers_number = 1;
/*
transformer.set({ input_length, context_length, input_dimensions, context_dimension,
embedding_depth, perceptron_depth, heads_number, layers_number });
Index input_length = 1;
Index context_length = 1;
Index input_dimensions = 1;
Index context_dimension = 1;
Index embedding_depth = 1;
Index perceptron_depth = 1;
Index heads_number = 1;
Index layers_number = 1;
Index batch_samples_number = 1;

Transformer transformer(input_length, context_length, input_dimensions, context_dimension,
embedding_depth, perceptron_depth, heads_number, layers_number);

transformer.set_parameters_constant(type(0));

inputs.resize(batch_samples_number, input_length);
Expand All @@ -105,9 +107,9 @@ TEST(Transformer, Outputs)

outputs = transformer.calculate_outputs(inputs, context);

EXPECT_EQ(outputs.dimension(0) == batch_samples_number);
EXPECT_EQ(outputs.dimension(1) == input_length);
EXPECT_EQ(outputs.dimension(2) == input_dimensions);
EXPECT_EQ(outputs.dimension(0), batch_samples_number);
EXPECT_EQ(outputs.dimension(1), input_length);
EXPECT_EQ(outputs.dimension(2), input_dimensions);

//EXPECT_EQ(outputs.abs() < type(NUMERIC_LIMITS_MIN));

Expand All @@ -117,7 +119,7 @@ TEST(Transformer, Outputs)
Index inputs_number = 2;
Index neurons_number = 4;
Index outputs_number = 5;
/*
transformer.set(Transformer::ModelType::Approximation, { inputs_number}, {neurons_number}, {outputs_number });
transformer.set_parameters_constant(type(0));
Expand Down Expand Up @@ -248,78 +250,72 @@ TEST(Transformer, Outputs)

TEST(Transformer, ForwardPropagate)
{
/*
{
// Test
batch_samples_number = 1;
input_length = 4;
context_length = 3;
input_dimensions = 5;
context_dimension = 6;
Index batch_samples_number = 1;

embedding_depth = 4;
perceptron_depth = 6;
heads_number = 4;
layers_number = 1;
Index input_length = 4;
Index context_length = 3;
Index input_dimensions = 5;
Index context_dimension = 6;

bool is_training = true;
Index embedding_depth = 4;
Index perceptron_depth = 6;
Index heads_number = 4;
Index layers_number = 1;

data.resize(batch_samples_number, context_length + 2 * input_length);
bool is_training = true;
/*
data.resize(batch_samples_number, context_length + 2 * input_length);
for(Index i = 0; i < batch_samples_number; i++)
{
for(Index j = 0; j < context_length; j++)
data(i, j) = type(rand() % context_dimension);
for(Index i = 0; i < batch_samples_number; i++)
{
for(Index j = 0; j < context_length; j++)
data(i, j) = type(rand() % context_dimension);
for(Index j = 0; j < 2 * input_length; j++)
data(i, j + context_length) = type(rand() % input_dimensions);
}
for(Index j = 0; j < 2 * input_length; j++)
data(i, j + context_length) = type(rand() % input_dimensions);
}
data_set.set(data);
data_set.set(data);
data_set.set(DataSet::SampleUse::Training);
data_set.set(DataSet::SampleUse::Training);
for(Index i = 0; i < context_length; i++)
data_set.set_raw_variable_use(i, DataSet::VariableUse::Context);
for(Index i = 0; i < context_length; i++)
data_set.set_raw_variable_use(i, DataSet::VariableUse::Context);
for(Index i = 0; i < input_length; i++)
data_set.set_raw_variable_use(i + context_length, DataSet::VariableUse::Input);
for(Index i = 0; i < input_length; i++)
data_set.set_raw_variable_use(i + context_length, DataSet::VariableUse::Input);
for(Index i = 0; i < input_length; i++)
data_set.set_raw_variable_use(i + context_length + input_length, DataSet::VariableUse::Target);
for(Index i = 0; i < input_length; i++)
data_set.set_raw_variable_use(i + context_length + input_length, DataSet::VariableUse::Target);
training_samples_indices = data_set.get_sample_indices(DataSet::SampleUse::Training);
context_variables_indices = data_set.get_variable_indices(DataSet::VariableUse::Context);
input_variables_indices = data_set.get_variable_indices(DataSet::VariableUse::Input);
target_variables_indices = data_set.get_variable_indices(DataSet::VariableUse::Target);
training_samples_indices = data_set.get_sample_indices(DataSet::SampleUse::Training);
context_variables_indices = data_set.get_variable_indices(DataSet::VariableUse::Context);
input_variables_indices = data_set.get_variable_indices(DataSet::VariableUse::Input);
target_variables_indices = data_set.get_variable_indices(DataSet::VariableUse::Target);
batch.set(batch_samples_number, &data_set);
batch.set(batch_samples_number, &data_set);
batch.fill(training_samples_indices, input_variables_indices, target_variables_indices, context_variables_indices);
batch.fill(training_samples_indices, input_variables_indices, target_variables_indices, context_variables_indices);
transformer.set({ input_length, context_length, input_dimensions, context_dimension,
embedding_depth, perceptron_depth, heads_number, layers_number });
transformer.set({ input_length, context_length, input_dimensions, context_dimension,
embedding_depth, perceptron_depth, heads_number, layers_number });
ForwardPropagation forward_propagation(data_set.get_samples_number(DataSet::SampleUse::Training), &transformer);
ForwardPropagation forward_propagation(data_set.get_samples_number(DataSet::SampleUse::Training), &transformer);
transformer.forward_propagate(batch.get_input_pairs(), forward_propagation, is_training);
transformer.forward_propagate(batch.get_input_pairs(), forward_propagation, is_training);
ProbabilisticLayer3DForwardPropagation* probabilistic_layer_forward_propagation
= static_cast<ProbabilisticLayer3DForwardPropagation*>(forward_propagation.layers[transformer.get_layers_number() - 1]);
ProbabilisticLayer3DForwardPropagation* probabilistic_layer_forward_propagation
= static_cast<ProbabilisticLayer3DForwardPropagation*>(forward_propagation.layers[transformer.get_layers_number() - 1]);
Tensor<type, 3> probabilistic_activations = probabilistic_layer_forward_propagation->outputs;
Tensor<type, 3> probabilistic_activations = probabilistic_layer_forward_propagation->outputs;
EXPECT_EQ(probabilistic_activations.rank() == 3);
EXPECT_EQ(probabilistic_activations.dimension(0) == batch_samples_number);
EXPECT_EQ(probabilistic_activations.dimension(1) == input_length);
EXPECT_EQ(probabilistic_activations.dimension(2) == input_dimensions + 1);
EXPECT_EQ(probabilistic_activations.rank() == 3);
EXPECT_EQ(probabilistic_activations.dimension(0) == batch_samples_number);
EXPECT_EQ(probabilistic_activations.dimension(1) == input_length);
EXPECT_EQ(probabilistic_activations.dimension(2) == input_dimensions + 1);
EXPECT_EQ(check_activations_sums(probabilistic_activations));
EXPECT_EQ(check_activations_sums(probabilistic_activations));
}
{
// Test
Expand Down

0 comments on commit 8839ba6

Please sign in to comment.