src/esn.cpp
ArrayBO EchoBay::esn_caller(const Eigen::VectorXd &optParams, YAML::Node confParams, 
                       const std::string outputFolder, const DataStorage &store, 
                       const bool guessEval, const std::string &computationType, 
                       const std::string &matrixFolder)
{
    // Number of guesses
    int guesses = confParams["Guesses"].as<int>();

    MatrixBO fitnessMatrix(guesses, 2);
    ArrayBO fitnessOut;

    // Problem settings
    double lambda = parse_config<double>("lambda", -1, 0, optParams, confParams, 0);
    std::string problemType = confParams["Problem_Definition"]["type"].as<std::string>();
    std::string fitnessRule = confParams["Problem_Definition"]["Fitness_Function"].as<std::string>();
    // Readout blockStep
    int blockStep = confParams["blockStep"].as<int>();
    // Limits
    int Nu = store.get_dataCols(EchoBay::Train) + 1;

    // Build Reservoir object
    if (computationType == "train")
    {
#ifdef _OPENMP
        omp_lock_t guessLock;
        omp_init_lock(&guessLock);
#pragma omp parallel for
#endif
        for (int i = 0; i < guesses; i++)
        {
            Reservoir ESN = esn_config(optParams, confParams, Nu, i, "");
            // Call rest of execution
            fitnessMatrix.row(i) = esn_train(confParams, ESN, lambda, problemType, fitnessRule, outputFolder, store, guessEval, i);
#ifdef _OPENMP
            omp_set_lock(&guessLock);
#endif
            std::cout << "Guess: " << i << " ";
            std::cout << "multifitness " << fitnessMatrix.row(i) << std::endl;
#ifdef _OPENMP
            omp_unset_lock(&guessLock);
#endif
        }

        // Calculate output: Train = Mean, Test = Worst Case
        if (guessEval)
        {
            fitnessOut = fitnessMatrix.colwise().minCoeff();
        }
        else
        {
            fitnessOut = fitnessMatrix.colwise().mean();
        }
    }
    else
    {
        std::cout << "Testing optimal configuration on unknown data" << std::endl;
        for (int i = 0; i < guesses; i++)
        {
            Reservoir ESN = esn_config(optParams, confParams, Nu, i, matrixFolder);
            std::string tempName = matrixFolder + "/Wout_eigen.dat";
            MatrixBO Wout;
            read_matrix(tempName, Wout);
            fitnessMatrix.row(i) = esn_compute(confParams, ESN, store, problemType, fitnessRule, blockStep, Wout, outputFolder, guessEval, i);
        }

        // Only worst case in compute
        fitnessOut = fitnessMatrix.colwise().minCoeff();
    }

    std::cout << "Final multiFitness :" << fitnessOut.transpose() << std::endl;
    return fitnessOut;
}
/**
 * @brief Main optimization function. Configure or load an Echo State Network
 * 
 * @param optParams Eigen Vector used by Limbo to define hyper-parameters
 * @param confParams YAML Node containing hyper-parameters at high level
 * @param outputFolder Path to save all output files
 * @param store DataStorage object containing training data and labels. See also EchoBay::DataStorage
 * @param guessEval If true evaluates multiple guesses as the worst case, otherwise, get the mean of guesses
 * @param computationType "train" performs ESN training, otherwise, validation and testing
 * @param matrixFolder Path to the folder where Reservoir matrices will be saved or loaded
 * @return ArrayBO Return fitness value to the Bayesian Optimizer
 */
@brief Main optimization function. Configure or load an Echo State Network

@param optParams Eigen Vector used by Limbo to define hyper-parameters
@param confParams YAML Node containing hyper-parameters at high level
@param outputFolder Path to save all output files
@param store DataStorage object containing training data and labels. See also EchoBay::DataStorage
@param guessEval If true evaluates multiple guesses as the worst case, otherwise, get the mean of guesses
@param computationType "train" performs ESN training, otherwise, validation and testing
@param matrixFolder Path to the folder where Reservoir matrices will be saved or loaded
@return ArrayBO Return fitness value to the Bayesian Optimizer
@brief Main optimization function . Configure or load an Echo State Network @param optParams Eigen Vector used by Limbo to define hyper - parameters @param confParams YAML Node containing hyper - parameters at high level @param outputFolder Path to save all output files @param store DataStorage object containing training data and labels . See also EchoBay :: DataStorage @param guessEval If true evaluates multiple guesses as the worst case otherwise get the mean of guesses @param computationType " train " performs ESN training otherwise validation and testing @param matrixFolder Path to the folder where Reservoir matrices will be saved or loaded @return ArrayBO Return fitness value to the Bayesian Optimizer
ArrayBO EchoBay::esn_caller(const Eigen::VectorXd &optParams, YAML::Node confParams, 
                       const std::string outputFolder, const DataStorage &store, 
                       const bool guessEval, const std::string &computationType, 
                       const std::string &matrixFolder)
{
    int guesses = confParams["Guesses"].as<int>();
    MatrixBO fitnessMatrix(guesses, 2);
    ArrayBO fitnessOut;
    double lambda = parse_config<double>("lambda", -1, 0, optParams, confParams, 0);
    std::string problemType = confParams["Problem_Definition"]["type"].as<std::string>();
    std::string fitnessRule = confParams["Problem_Definition"]["Fitness_Function"].as<std::string>();
    int blockStep = confParams["blockStep"].as<int>();
    int Nu = store.get_dataCols(EchoBay::Train) + 1;
    if (computationType == "train")
    {
#ifdef _OPENMP
        omp_lock_t guessLock;
        omp_init_lock(&guessLock);
#pragma omp parallel for
#endif
        for (int i = 0; i < guesses; i++)
        {
            Reservoir ESN = esn_config(optParams, confParams, Nu, i, "");
            fitnessMatrix.row(i) = esn_train(confParams, ESN, lambda, problemType, fitnessRule, outputFolder, store, guessEval, i);
#ifdef _OPENMP
            omp_set_lock(&guessLock);
#endif
            std::cout << "Guess: " << i << " ";
            std::cout << "multifitness " << fitnessMatrix.row(i) << std::endl;
#ifdef _OPENMP
            omp_unset_lock(&guessLock);
#endif
        }
        if (guessEval)
        {
            fitnessOut = fitnessMatrix.colwise().minCoeff();
        }
        else
        {
            fitnessOut = fitnessMatrix.colwise().mean();
        }
    }
    else
    {
        std::cout << "Testing optimal configuration on unknown data" << std::endl;
        for (int i = 0; i < guesses; i++)
        {
            Reservoir ESN = esn_config(optParams, confParams, Nu, i, matrixFolder);
            std::string tempName = matrixFolder + "/Wout_eigen.dat";
            MatrixBO Wout;
            read_matrix(tempName, Wout);
            fitnessMatrix.row(i) = esn_compute(confParams, ESN, store, problemType, fitnessRule, blockStep, Wout, outputFolder, guessEval, i);
        }
        fitnessOut = fitnessMatrix.colwise().minCoeff();
    }
    std::cout << "Final multiFitness :" << fitnessOut.transpose() << std::endl;
    return fitnessOut;
}
ArrayBO EchoBay :: esn_caller ( const Eigen :: VectorXd & optParams , YAML :: Node confParams , const std :: string outputFolder , const DataStorage & store , const bool guessEval , const std :: string & computationType , const std :: string & matrixFolder ) { int guesses = confParams [ " " ] . as < int > ( ) ; MatrixBO fitnessMatrix ( guesses , 2 ) ; ArrayBO fitnessOut ; double lambda = parse_config < double > ( " " , -1 , 0 , optParams , confParams , 0 ) ; std :: string problemType = confParams [ " " ] [ " " ] . as < std :: string > ( ) ; std :: string fitnessRule = confParams [ " " ] [ " " ] . as < std :: string > ( ) ; int blockStep = confParams [ " " ] . as < int > ( ) ; int Nu = store . get_dataCols ( EchoBay :: Train ) + 1 ; if ( computationType == " " ) { #ifdef _OPENMP omp_lock_t guessLock ; omp_init_lock ( & guessLock ) ; #pragma  omp parallel for #endif for ( int i = 0 ; i < guesses ; i ++ ) { Reservoir ESN = esn_config ( optParams , confParams , Nu , i , " " ) ; fitnessMatrix . row ( i ) = esn_train ( confParams , ESN , lambda , problemType , fitnessRule , outputFolder , store , guessEval , i ) ; #ifdef _OPENMP omp_set_lock ( & guessLock ) ; #endif std :: cout << " " << i << " " ; std :: cout << " " << fitnessMatrix . row ( i ) << std :: endl ; #ifdef _OPENMP omp_unset_lock ( & guessLock ) ; #endif } if ( guessEval ) { fitnessOut = fitnessMatrix . colwise ( ) . minCoeff ( ) ; } else { fitnessOut = fitnessMatrix . colwise ( ) . mean ( ) ; } } else { std :: cout << " " << std :: endl ; for ( int i = 0 ; i < guesses ; i ++ ) { Reservoir ESN = esn_config ( optParams , confParams , Nu , i , matrixFolder ) ; std :: string tempName = matrixFolder + " " ; MatrixBO Wout ; read_matrix ( tempName , Wout ) ; fitnessMatrix . row ( i ) = esn_compute ( confParams , ESN , store , problemType , fitnessRule , blockStep , Wout , outputFolder , guessEval , i ) ; } fitnessOut = fitnessMatrix . colwise ( ) . minCoeff ( ) ; } std :: cout << " " << fitnessOut . transpose ( ) << std :: endl ; return fitnessOut ; }
@brief Main optimization function.
@brief Main optimization function .
// Number of guesses // Problem settings // Readout blockStep // Limits // Build Reservoir object // Call rest of execution // Calculate output: Train = Mean, Test = Worst Case // Only worst case in compute