From 10:00 CET Friday 22nd November we will adjust how the server works to deal with some recently reported problems. Therefore there may be a load problem, if you experience more problems than usual trying to access the forum then please PM AndyS or any of the moderators so they can inform me.


OpenNN memory problem



  • I use a modified version of airfoil_self_noise from the OpenNN (http://www.opennn.net/) library which is attached.I use Qt Creator 4.8.2 (community) to compile it using the kit : MSVC 2017 64 bit with Microsoft Visual C++ compiler 15.0 (x86_AMD64) & cdb debugger.Compilation ends successfully without problems in both cases(see in file :case1 & case2) but when I run the exe_case1 there is no problem while when I run the exe_case2 I obtain this error:

    Error :OpenNN Exception: TrainingStrategy class.
    LevenbergMarquardtAlgorithm* get_Levenberg_Marquardt_algorithm_pointer(void) const method.
    Levenberg_Marquardt algorithm pointer is NULL.

    The only difference between the two is in the lines 293-309.[0_1552903063134_main.cpp](Uploading 100%)

    I'm not a C++ expert so this problem is difficult for me. Can you help me?

    Thanks!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Can you post the code ? Your upload didn't work.



  • Here is my code:

    // System includes
    
     #include <iostream>
     #include <fstream>
     #include <sstream>
     #include <string>
     #include <cstring>
     #include <time.h>
    
     // OpenNN includes
    
     #include "../../opennn/opennn.h"
     #include <levenberg_marquardt_algorithm.h>
     #include <quasi_newton_method.h>
    
     using namespace OpenNN;
    
     int main(void)
     {
    try
    {
        int rank = 0;
    
       #ifdef __OPENNN_MPI__
    
        int size = 1;
    
        MPI_Init(NULL,NULL);
    
        MPI_Comm_size(MPI_COMM_WORLD, &size);
    
        MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    
       #endif
    
        if(rank == 0)
        {
            std::cout << "OpenNN. Airfoil Self-Noise Application." << std::endl;
        }
    
        srand((unsigned)time(NULL));
    
        // Global variables
    
        DataSet data_set;
    
        NeuralNetwork neural_network;
    
        LossIndex loss_index;
    
        TrainingStrategy training_strategy;
    
        // Local variables
    
        DataSet local_data_set;
    
        NeuralNetwork local_neural_network;
    
        LossIndex local_loss_index;
    
        TrainingStrategy local_training_strategy;
    
        if(rank == 0)
        {
    
    
            // Data set
            data_set.set_data_file_name("../data/temprenetinputs11.csv"); // controllare dati
            data_set.set_separator("Space");
            data_set.load_data();
    
            printf("%s\n","data_set");
            std::cout << typeid(data_set).name() << std::endl;
    
            // Variables
    
            Variables* variables_pointer = data_set.get_variables_pointer();
    
             variables_pointer->set_name(0, "1");
            variables_pointer->set_units(0, "pip");
              variables_pointer->set_use(0, Variables::Input);
             variables_pointer->set_name(1, "2");
            variables_pointer->set_units(1, "pip");
              variables_pointer->set_use(1, Variables::Input);
             variables_pointer->set_name(2, "3");
            variables_pointer->set_units(2, "pip");
              variables_pointer->set_use(2, Variables::Input);
             variables_pointer->set_name(3, "4");
            variables_pointer->set_units(3, "pip");
              variables_pointer->set_use(3, Variables::Input);
             variables_pointer->set_name(4, "5");
            variables_pointer->set_units(4, "pip");
              variables_pointer->set_use(4, Variables::Input);
             variables_pointer->set_name(5, "6");
            variables_pointer->set_units(5, "pip");
              variables_pointer->set_use(5, Variables::Input);
             variables_pointer->set_name(6, "7");
            variables_pointer->set_units(6, "pip");
              variables_pointer->set_use(6, Variables::Input);
             variables_pointer->set_name(7, "8");
            variables_pointer->set_units(7, "pip");
              variables_pointer->set_use(7, Variables::Input);
             variables_pointer->set_name(8, "9");
            variables_pointer->set_units(8, "pip");
              variables_pointer->set_use(8, Variables::Input);
             variables_pointer->set_name(9, "10");
            variables_pointer->set_units(9, "pip");
              variables_pointer->set_use(9, Variables::Input);
             variables_pointer->set_name(10, "11");
            variables_pointer->set_units(10, "pip");
              variables_pointer->set_use(10, Variables::Input);
             variables_pointer->set_name(11, "12");
            variables_pointer->set_units(11, "pip");
              variables_pointer->set_use(11, Variables::Input);
             variables_pointer->set_name(12, "13");
            variables_pointer->set_units(12, "pip");
              variables_pointer->set_use(12, Variables::Input);
             variables_pointer->set_name(13, "14");
            variables_pointer->set_units(13, "pip");
              variables_pointer->set_use(13, Variables::Input);
             variables_pointer->set_name(14, "15");
            variables_pointer->set_units(14, "pip");
              variables_pointer->set_use(14, Variables::Input);
             variables_pointer->set_name(15, "16");
            variables_pointer->set_units(15, "pip");
              variables_pointer->set_use(15, Variables::Input);
             variables_pointer->set_name(16, "17");
            variables_pointer->set_units(16, "pip");
              variables_pointer->set_use(16, Variables::Input);
             variables_pointer->set_name(17, "18");
            variables_pointer->set_units(17, "pip");
              variables_pointer->set_use(17, Variables::Input);
             variables_pointer->set_name(18, "19");
            variables_pointer->set_units(18, "pip");
              variables_pointer->set_use(18, Variables::Input);
             variables_pointer->set_name(19, "20");
            variables_pointer->set_units(19, "pip");
              variables_pointer->set_use(19, Variables::Input);
             variables_pointer->set_name(20, "21");
            variables_pointer->set_units(20, "pip");
              variables_pointer->set_use(20, Variables::Input);
             variables_pointer->set_name(21, "22");
            variables_pointer->set_units(21, "pip");
              variables_pointer->set_use(21, Variables::Input);
             variables_pointer->set_name(22, "23");
            variables_pointer->set_units(22, "pip");
              variables_pointer->set_use(22, Variables::Input);
             variables_pointer->set_name(23, "24");
            variables_pointer->set_units(23, "pip");
              variables_pointer->set_use(23, Variables::Input);
             variables_pointer->set_name(24, "25");
            variables_pointer->set_units(24, "pip");
              variables_pointer->set_use(24, Variables::Input);
              variables_pointer->set_name(25, "26");
             variables_pointer->set_units(25, "pip");
               variables_pointer->set_use(25, Variables::Input);
              variables_pointer->set_name(26, "27");
             variables_pointer->set_units(26, "pip");
               variables_pointer->set_use(26, Variables::Input);
              variables_pointer->set_name(27, "28");
             variables_pointer->set_units(27, "pip");
               variables_pointer->set_use(27, Variables::Input);
              variables_pointer->set_name(28, "29");
             variables_pointer->set_units(28, "pip");
               variables_pointer->set_use(28, Variables::Input);
              variables_pointer->set_name(29, "30");
             variables_pointer->set_units(29, "pip");
               variables_pointer->set_use(29, Variables::Input);
              variables_pointer->set_name(30, "31");
             variables_pointer->set_units(30, "pip");
               variables_pointer->set_use(30, Variables::Input);
              variables_pointer->set_name(31, "32");
             variables_pointer->set_units(31, "pip");
               variables_pointer->set_use(31, Variables::Input);
              variables_pointer->set_name(32, "33");
             variables_pointer->set_units(32, "pip");
               variables_pointer->set_use(32, Variables::Input);
              variables_pointer->set_name(33, "34");
             variables_pointer->set_units(33, "pip");
               variables_pointer->set_use(33, Variables::Input);
              variables_pointer->set_name(34, "35");
             variables_pointer->set_units(34, "pip");
               variables_pointer->set_use(34, Variables::Input);
              variables_pointer->set_name(35, "36");
             variables_pointer->set_units(35, "pip");
               variables_pointer->set_use(35, Variables::Input);
              variables_pointer->set_name(36, "37");
             variables_pointer->set_units(36, "pip");
               variables_pointer->set_use(36, Variables::Input);
              variables_pointer->set_name(37, "38");
             variables_pointer->set_units(37, "pip");
               variables_pointer->set_use(37, Variables::Input);
              variables_pointer->set_name(38, "39");
             variables_pointer->set_units(38, "pip");
               variables_pointer->set_use(38, Variables::Input);
              variables_pointer->set_name(39, "40");
             variables_pointer->set_units(39, "pip");
               variables_pointer->set_use(39, Variables::Input);
               variables_pointer->set_name(40, "41");
              variables_pointer->set_units(40, "pip");
                variables_pointer->set_use(40, Variables::Input);
               variables_pointer->set_name(41, "42");
              variables_pointer->set_units(41, "pip");
                variables_pointer->set_use(41, Variables::Input);
               variables_pointer->set_name(42, "43");
              variables_pointer->set_units(42, "pip");
                variables_pointer->set_use(42, Variables::Input);
    
            variables_pointer->set_name(43, "target");
            variables_pointer->set_use(43, Variables::Target);
    
    
            const Matrix<std::string> inputs_information = variables_pointer->arrange_inputs_information();
            const Matrix<std::string> targets_information = variables_pointer->arrange_targets_information();
    
            // Instances
    
            Instances* instances_pointer = data_set.get_instances_pointer();
    
            instances_pointer->split_random_indices();
            //instances_pointer->split_random_indices(0.7, 0.15, 0.15);
    
            const Vector< Statistics<double> > inputs_statistics = data_set.scale_inputs_minimum_maximum(); // mapminmax
            const Vector< Statistics<double> > targets_statistics = data_set.scale_targets_minimum_maximum();
    
            // Neural network
    
            const size_t inputs_number = variables_pointer->count_inputs_number();
            const size_t hidden_perceptrons_number = 100;
            const size_t outputs_number = variables_pointer->count_targets_number();
    
            neural_network.set(inputs_number, hidden_perceptrons_number, outputs_number); // quale funzione di attivazione?
            //NeuralNetwork neural_network(inputs_number, hidden_perceptrons_number, outputs_number);                                                                              // validation ??
    
            Inputs* inputs = neural_network.get_inputs_pointer();
    
            inputs->set_information(inputs_information);
    
            Outputs* outputs = neural_network.get_outputs_pointer();
    
            outputs->set_information(targets_information);
    
            neural_network.construct_scaling_layer();
    
            ScalingLayer* scaling_layer_pointer = neural_network.get_scaling_layer_pointer();
    
            scaling_layer_pointer->set_statistics(inputs_statistics);
    
            scaling_layer_pointer->set_scaling_method(ScalingLayer::NoScaling);
    
            neural_network.construct_unscaling_layer();
    
            UnscalingLayer* unscaling_layer_pointer = neural_network.get_unscaling_layer_pointer();
    
            unscaling_layer_pointer->set_statistics(targets_statistics);
    
            unscaling_layer_pointer->set_unscaling_method(UnscalingLayer::NoUnscaling);
    
            // Loss index
    
            loss_index.set_data_set_pointer(&data_set);
            loss_index.set_neural_network_pointer(&neural_network);  // mse??
            loss_index.set_regularization_type(LossIndex::NEURAL_PARAMETERS_NORM);  // ??
    
            // Training strategy object
    
            training_strategy.set(&loss_index);
            //TrainingStrategy training_strategy(&neural_network, &data_set);
    
          // non sono i dati
          // Error :OpenNN Exception: TrainingStrategy class.
          // LevenbergMarquardtAlgorithm* get_Levenberg_Marquardt_algorithm_pointer(void) const method.
          // Levenberg_Marquardt algorithm pointer is NULL.
          // ottenere il valore esatto del pointer es.:0.0000
    
          //     CASE 2 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
          LevenbergMarquardtAlgorithm* Levenberg_Marquardt_algorithm_pointer = training_strategy.get_Levenberg_Marquardt_algorithm_pointer();
          Levenberg_Marquardt_algorithm_pointer->set_maximum_iterations_number(1000);
          Levenberg_Marquardt_algorithm_pointer->set_display_period(10);
          Levenberg_Marquardt_algorithm_pointer->set_minimum_loss_increase(1.0e-6);
          Levenberg_Marquardt_algorithm_pointer ->set_reserve_loss_history(true);
    
          //     CASE 1 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
           QuasiNewtonMethod* quasi_Newton_method_pointer = training_strategy.get_quasi_Newton_method_pointer();
           quasi_Newton_method_pointer->set_maximum_iterations_number(1000);
           quasi_Newton_method_pointer->set_display_period(10);
           quasi_Newton_method_pointer->set_minimum_loss_increase(1.0e-6);
           quasi_Newton_method_pointer->set_reserve_loss_history(true);
    
         // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
        }
    
    #ifdef __OPENNN_MPI__
        MPI_Barrier(MPI_COMM_WORLD);
    
        local_data_set.set_MPI(&data_set);
    
        local_neural_network.set_MPI(&neural_network);
    
        local_loss_index.set_MPI(&local_data_set,&local_neural_network,&loss_index);
    
        local_training_strategy.set_MPI(&local_loss_index,&training_strategy);
    
        MPI_Barrier(MPI_COMM_WORLD);
    
        TrainingStrategy::Results training_strategy_results = local_training_strategy.perform_training();
    #else
        TrainingStrategy::Results training_strategy_results = training_strategy.perform_training();
    #endif
    
        if(rank == 0)
        {
     #ifdef __OPENNN_MPI__
            neural_network.set_multilayer_perceptron_pointer(local_neural_network.get_multilayer_perceptron_pointer());
     #endif
            // Testing analysis
    
            TestingAnalysis testing_analysis(&neural_network, &data_set);
    
            TestingAnalysis::LinearRegressionResults linear_regression_results = testing_analysis.perform_linear_regression_analysis();
    
            // Save results
    
            ScalingLayer* scaling_layer_pointer = neural_network.get_scaling_layer_pointer();
            UnscalingLayer* unscaling_layer_pointer = neural_network.get_unscaling_layer_pointer();
    
            scaling_layer_pointer->set_scaling_method(ScalingLayer::MinimumMaximum);
            unscaling_layer_pointer->set_unscaling_method(UnscalingLayer::MinimumMaximum);
    
            data_set.save("../data/data_set.xml");
    
            neural_network.save("../data/neural_network.xml");
            neural_network.save_expression("../data/expression.txt");
    
            loss_index.save("../data/loss_index.xml");
    
            training_strategy.save("../data/training_strategy.xml");
            training_strategy_results.save("../data/training_strategy_results.dat");
    
            linear_regression_results.save("../data/linear_regression_analysis_results.dat");
        }
    
     #ifdef __OPENNN_MPI__
    
        MPI_Barrier(MPI_COMM_WORLD);
    
        MPI_Finalize();
    
     #endif
        return(0);
    }
    catch(std::exception& e)
    {
        std::cerr << e.what() << std::endl;
    
        std::getchar();
        return(1);
     }
     }
    
    
     // OpenNN: Open Neural Networks Library.
     // Copyright (C) 2005-2015 Roberto Lopez.
     //
     // This library is free software; you can redistribute it and/or
     // modify it under the terms of the GNU Lesser General Public
     // License as published by the Free Software Foundation; either
     // version 2.1 of the License, or any later version.
     //
    // This library is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    // Lesser General Public License for more details.
    // You should have received a copy of the GNU Lesser General Public
    // License along with this library; if not, write to the Free Software
    // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA[0_1552982666677_main.cpp](Uploading 100%) 
    

    Thanks!


Log in to reply