Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
RoberLopez committed Dec 4, 2024
1 parent 9d61b0a commit 3550fa3
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 128 deletions.
4 changes: 2 additions & 2 deletions examples/amazon_reviews/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ int main()

output_data = neural_network.calculate_outputs(input_data);

cout << "\n\n" << review_1 << endl << "\nBad:" << output_data(0,0) << "%\tGood:" << (1 - output_data(0,0)) << "%" << endl;
cout << "\n" << review_2 << endl << "\nBad:" << output_data(1,0) << "%\tGood:" << (1 - output_data(1,0)) << "%\n" << endl;
cout << "\n\n" << review_1 << "\nBad:" << output_data(0,0) << "%\tGood:" << (1 - output_data(0,0)) << "%" << endl;
cout << "\n" << review_2 << "\nBad:" << output_data(1,0) << "%\tGood:" << (1 - output_data(1,0)) << "%\n" << endl;

// Save results

Expand Down
33 changes: 8 additions & 25 deletions opennn/adaptive_moment_estimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,23 +202,9 @@ TrainingResults AdaptiveMomentEstimation::perform_training()

NeuralNetwork* neural_network = loss_index->get_neural_network();

set_neural_network_variable_names();
set_names();

if(neural_network->has(Layer::Type::Scaling2D))
{
ScalingLayer2D* scaling_layer_2d = static_cast<ScalingLayer2D*>(neural_network->get_first(Layer::Type::Scaling2D));

scaling_layer_2d->set_descriptives(input_variable_descriptives);
scaling_layer_2d->set_scalers(input_variable_scalers);
}

if(neural_network->has(Layer::Type::Unscaling))
{
target_variable_descriptives = data_set->scale_variables(DataSet::VariableUse::Target);

UnscalingLayer* unscaling_layer = static_cast<UnscalingLayer*>(neural_network->get_first(Layer::Type::Unscaling));
unscaling_layer->set(target_variable_descriptives, target_variable_scalers);
}
set_scaling();

ForwardPropagation training_forward_propagation(training_batch_samples_number, neural_network);
ForwardPropagation selection_forward_propagation(selection_batch_samples_number, neural_network);
Expand Down Expand Up @@ -383,7 +369,7 @@ TrainingResults AdaptiveMomentEstimation::perform_training()

if(epoch == maximum_epochs_number)
{
if(display) cout << "Epoch " << epoch << endl << "Maximum epochs number reached: " << epoch << endl;
if(display) cout << "Epoch " << epoch << "\nMaximum epochs number reached: " << epoch << endl;

stop_training = true;

Expand All @@ -392,7 +378,7 @@ TrainingResults AdaptiveMomentEstimation::perform_training()

if(elapsed_time >= maximum_time)
{
if(display) cout << "Epoch " << epoch << endl << "Maximum training time reached: " << write_time(elapsed_time) << endl;
if(display) cout << "Epoch " << epoch << "\nMaximum training time reached: " << write_time(elapsed_time) << endl;

stop_training = true;

Expand All @@ -407,7 +393,7 @@ TrainingResults AdaptiveMomentEstimation::perform_training()

results.stopping_condition = StoppingCondition::LossGoal;

if(display) cout << "Epoch " << epoch << endl << "Loss goal reached: " << results.training_error_history(epoch) << endl;
if(display) cout << "Epoch " << epoch << "\nLoss goal reached: " << results.training_error_history(epoch) << endl;
}

if(training_accuracy >= training_accuracy_goal)
Expand All @@ -416,12 +402,12 @@ TrainingResults AdaptiveMomentEstimation::perform_training()

results.stopping_condition = StoppingCondition::LossGoal;

if(display) cout << "Epoch " << epoch << endl << "Accuracy goal reached: " << training_accuracy << endl;
if(display) cout << "Epoch " << epoch << "\nAccuracy goal reached: " << training_accuracy << endl;
}

if(selection_failures >= maximum_selection_failures)
{
if(display) cout << "Epoch " << epoch << endl << "Maximum selection failures reached: " << selection_failures << endl;
if(display) cout << "Epoch " << epoch << "\nMaximum selection failures reached: " << selection_failures << endl;

stop_training = true;

Expand All @@ -447,10 +433,7 @@ TrainingResults AdaptiveMomentEstimation::perform_training()

}

data_set->unscale_variables(DataSet::VariableUse::Input, input_variable_descriptives);

if(neural_network->has(Layer::Type::Unscaling))
data_set->unscale_variables(DataSet::VariableUse::Target, target_variable_descriptives);
set_unscaling();

if(display) results.print();

Expand Down
10 changes: 5 additions & 5 deletions opennn/conjugate_gradient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,12 @@ TrainingResults ConjugateGradient::perform_training()

results.stopping_condition = StoppingCondition::LossGoal;

if(display) cout << "Epoch " << epoch << endl << "Loss goal reached: " << results.training_error_history(epoch) << endl;
if(display) cout << "Epoch " << epoch << "\nLoss goal reached: " << results.training_error_history(epoch) << endl;
}

if(has_selection && selection_failures >= maximum_selection_failures)
{
if(display) cout << "Epoch " << epoch << endl << "Maximum selection failures reached: " << selection_failures << endl;
if(display) cout << "Epoch " << epoch << "\nMaximum selection failures reached: " << selection_failures << endl;

stop_training = true;

Expand All @@ -387,7 +387,7 @@ TrainingResults ConjugateGradient::perform_training()

if(epoch == maximum_epochs_number)
{
if(display) cout << "Epoch " << epoch << endl << "Maximum epochs number reached: " << epoch << endl;
if(display) cout << "Epoch " << epoch << "\nMaximum epochs number reached: " << epoch << endl;

stop_training = true;

Expand All @@ -396,7 +396,7 @@ TrainingResults ConjugateGradient::perform_training()

if(elapsed_time >= maximum_time)
{
if(display) cout << "Epoch " << epoch << endl << "Maximum training time reached: " << write_time(elapsed_time) << endl;
if(display) cout << "Epoch " << epoch << "\nMaximum training time reached: " << write_time(elapsed_time) << endl;

stop_training = true;

Expand All @@ -407,7 +407,7 @@ TrainingResults ConjugateGradient::perform_training()

if(loss_decrease <= minimum_loss_decrease)
{
if(display) cout << "Epoch " << epoch << endl << "Minimum loss decrease reached: " << minimum_loss_decrease << endl;
if(display) cout << "Epoch " << epoch << "\nMinimum loss decrease reached: " << minimum_loss_decrease << endl;

stop_training = true;

Expand Down
8 changes: 4 additions & 4 deletions opennn/genetic_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ void GeneticAlgorithm::evaluate_population()
{
individual = population.chip(i, 0);

cout << endl << "Individual " << i + 1 << endl;
cout << "\nIndividual " << i + 1 << endl;

individual_raw_variables_indices = get_individual_as_raw_variables_indexes_from_variables(individual);

Expand Down Expand Up @@ -669,7 +669,7 @@ void GeneticAlgorithm::perform_mutation()

InputsSelectionResults GeneticAlgorithm::perform_inputs_selection()
{
if(display) cout << "Performing genetic inputs selection..." << endl << endl;
if(display) cout << "Performing genetic inputs selection...\n" << endl;

initialize_population();

Expand Down Expand Up @@ -798,7 +798,7 @@ InputsSelectionResults GeneticAlgorithm::perform_inputs_selection()
{
stop = true;

if(display) cout << "Epoch " << epoch << endl << "Maximum time reached: " << write_time(elapsed_time) << endl;
if(display) cout << "Epoch " << epoch << "\nMaximum time reached: " << write_time(elapsed_time) << endl;

inputs_selection_results.stopping_condition = InputsSelection::StoppingCondition::MaximumTime;
}
Expand All @@ -807,7 +807,7 @@ InputsSelectionResults GeneticAlgorithm::perform_inputs_selection()
{
stop = true;

if(display) cout << "Epoch " << epoch << endl << "Maximum epochs number reached: " << epoch << endl;
if(display) cout << "Epoch " << epoch << "\nMaximum epochs number reached: " << epoch << endl;

inputs_selection_results.stopping_condition = InputsSelection::StoppingCondition::MaximumEpochs;
}
Expand Down
2 changes: 1 addition & 1 deletion opennn/growing_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ InputsSelectionResults GrowingInputs::perform_inputs_selection()
{
stop = true;

if(display) cout << "Epoch " << epoch << endl << "Maximum time reached: " << write_time(elapsed_time) << endl;
if(display) cout << "Epoch " << epoch << "\nMaximum time reached: " << write_time(elapsed_time) << endl;

inputs_selection_results.stopping_condition = InputsSelection::StoppingCondition::MaximumTime;
}
Expand Down
14 changes: 7 additions & 7 deletions opennn/growing_neurons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ NeuronsSelectionResults GrowingNeurons::perform_neurons_selection()
// Main loop

for(Index epoch = 0; epoch < maximum_epochs_number; epoch++)
{
if(display) cout << endl << "Growing neurons epoch: " << epoch << endl;
{
if(display) cout << "\nGrowing neurons epoch: " << epoch << endl;

// Neural network

Expand Down Expand Up @@ -163,7 +163,7 @@ NeuronsSelectionResults GrowingNeurons::perform_neurons_selection()
{
end = true;

if(display) cout << "Epoch " << epoch << endl << "Maximum time reached: " << write_time(elapsed_time) << endl;
if(display) cout << "Epoch " << epoch << "\nMaximum time reached: " << write_time(elapsed_time) << endl;

neurons_selection_results.stopping_condition = GrowingNeurons::StoppingCondition::MaximumTime;
}
Expand All @@ -172,7 +172,7 @@ NeuronsSelectionResults GrowingNeurons::perform_neurons_selection()
{
end = true;

if(display) cout << "Epoch " << epoch << endl << "Selection error goal reached: " << training_results.get_selection_error() << endl;
if(display) cout << "Epoch " << epoch << "\nSelection error goal reached: " << training_results.get_selection_error() << endl;

neurons_selection_results.stopping_condition = GrowingNeurons::StoppingCondition::SelectionErrorGoal;
}
Expand All @@ -181,7 +181,7 @@ NeuronsSelectionResults GrowingNeurons::perform_neurons_selection()
{
end = true;

if(display) cout << "Epoch " << epoch << endl << "Maximum epochs number reached: " << epoch << endl;
if(display) cout << "Epoch " << epoch << "\nMaximum epochs number reached: " << epoch << endl;

neurons_selection_results.stopping_condition = GrowingNeurons::StoppingCondition::MaximumEpochs;
}
Expand All @@ -190,7 +190,7 @@ NeuronsSelectionResults GrowingNeurons::perform_neurons_selection()
{
end = true;

if(display) cout << "Epoch " << epoch << endl << "Maximum selection failures reached: " << selection_failures << endl;
if(display) cout << "Epoch " << epoch << "\nMaximum selection failures reached: " << selection_failures << endl;

neurons_selection_results.stopping_condition = GrowingNeurons::StoppingCondition::MaximumSelectionFailures;
}
Expand All @@ -199,7 +199,7 @@ NeuronsSelectionResults GrowingNeurons::perform_neurons_selection()
{
end = true;

if(display) cout << "Epoch " << epoch << endl << "Maximum number of neurons reached: " << neurons_number << endl;
if(display) cout << "Epoch " << epoch << "\nMaximum number of neurons reached: " << neurons_number << endl;

neurons_selection_results.stopping_condition = GrowingNeurons::StoppingCondition::MaximumNeurons;
}
Expand Down
4 changes: 2 additions & 2 deletions opennn/image_data_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void ImageDataSet::set_image_data_random()
}

if (display)
cout << endl << "Random image data set generated." << endl;
cout << "\nRandom image data set generated." << endl;
}


Expand Down Expand Up @@ -544,7 +544,7 @@ void ImageDataSet::read_bmp()
long long seconds = (total_milliseconds % 60000) / 1000;
long long milliseconds = total_milliseconds % 1000;

cout << endl << "Image data set loaded in: "
cout << "\nImage data set loaded in: "
<< minutes << " minutes, "
<< seconds << " seconds, "
<< milliseconds << " milliseconds." << endl;
Expand Down
34 changes: 5 additions & 29 deletions opennn/levenberg_marquardt_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,34 +205,14 @@ TrainingResults LevenbergMarquardtAlgorithm::perform_training()
const vector<Index> input_variable_indices = data_set->get_variable_indices(DataSet::VariableUse::Input);
const vector<Index> target_variable_indices = data_set->get_variable_indices(DataSet::VariableUse::Target);

const vector<Scaler> input_variable_scalers = data_set->get_variable_scalers(DataSet::VariableUse::Input);
const vector<Scaler> target_variable_scalers = data_set->get_variable_scalers(DataSet::VariableUse::Target);

vector<Descriptives> input_variable_descriptives;
vector<Descriptives> target_variable_descriptives;

// Neural network

NeuralNetwork* neural_network = loss_index->get_neural_network();

set_neural_network_variable_names();
set_names();

if(neural_network->has(Layer::Type::Scaling2D))
{
input_variable_descriptives = data_set->scale_variables(DataSet::VariableUse::Input);
ScalingLayer2D* scaling_layer_2d = static_cast<ScalingLayer2D*>(neural_network->get_first(Layer::Type::Scaling2D));
scaling_layer_2d->set_descriptives(input_variable_descriptives);
scaling_layer_2d->set_scalers(input_variable_scalers);
}
set_scaling();

if(neural_network->has(Layer::Type::Unscaling))
{
target_variable_descriptives = data_set->scale_variables(DataSet::VariableUse::Target);

UnscalingLayer* unscaling_layer = static_cast<UnscalingLayer*>(neural_network->get_first(Layer::Type::Unscaling));
unscaling_layer->set(target_variable_descriptives, target_variable_scalers);
}

Batch training_batch(training_samples_number, data_set);
training_batch.fill(training_samples_indices, input_variable_indices, target_variable_indices);

Expand Down Expand Up @@ -334,7 +314,7 @@ TrainingResults LevenbergMarquardtAlgorithm::perform_training()

if(loss_decrease < minimum_loss_decrease)
{
if(display) cout << "Epoch " << epoch << endl << "Minimum loss decrease reached: " << loss_decrease << endl;
if(display) cout << "Epoch " << epoch << "\nMinimum loss decrease reached: " << loss_decrease << endl;

stop_training = true;

Expand All @@ -354,7 +334,7 @@ TrainingResults LevenbergMarquardtAlgorithm::perform_training()

if(epoch == maximum_epochs_number)
{
if(display) cout << "Epoch " << epoch << endl << "Maximum epochs number reached: " << epoch << endl;
if(display) cout << "Epoch " << epoch << "\nMaximum epochs number reached: " << epoch << endl;

stop_training = true;

Expand Down Expand Up @@ -390,11 +370,7 @@ TrainingResults LevenbergMarquardtAlgorithm::perform_training()
optimization_data);
}

if(neural_network->has(Layer::Type::Scaling2D))
data_set->unscale_variables(DataSet::VariableUse::Input, input_variable_descriptives);

if(neural_network->has(Layer::Type::Unscaling))
data_set->unscale_variables(DataSet::VariableUse::Target, target_variable_descriptives);
set_unscaling();

if(display) results.print();

Expand Down
Loading

0 comments on commit 3550fa3

Please sign in to comment.