From 0b243ca17e09820da92258d30e8fc146017859d8 Mon Sep 17 00:00:00 2001 From: Ko van der Sloot Date: Thu, 2 May 2024 01:11:49 +0200 Subject: [PATCH] and more cleanup --- include/timbl/MBLClass.h | 4 ++-- include/timbl/TimblAPI.h | 2 ++ include/timbl/TimblExperiment.h | 31 +++++++++++++++++++------------ src/MBLClass.cxx | 8 ++++---- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/include/timbl/MBLClass.h b/include/timbl/MBLClass.h index 506ba55..577f557 100644 --- a/include/timbl/MBLClass.h +++ b/include/timbl/MBLClass.h @@ -91,8 +91,8 @@ namespace Timbl { bool writeWeights( std::ostream& ) const; bool readWeights( std::istream&, WeightType ); bool writeNamesFile( std::ostream& ) const; - bool ShowOptions( std::ostream& ) const; - bool ShowSettings( std::ostream& ) const; + virtual bool ShowOptions( std::ostream& ); + virtual bool ShowSettings( std::ostream& ); void writePermutation( std::ostream& ) const; void LearningInfo( std::ostream& ); virtual ~MBLClass() override; diff --git a/include/timbl/TimblAPI.h b/include/timbl/TimblAPI.h index ff8d905..5a08408 100644 --- a/include/timbl/TimblAPI.h +++ b/include/timbl/TimblAPI.h @@ -50,7 +50,9 @@ namespace Timbl{ class TimblAPI { friend class TimblExperiment; public: + // cppcheck-suppress noExplicitConstructor TimblAPI( const TiCC::CL_Options&, const std::string& = "" ); + // cppcheck-suppress noExplicitConstructor TimblAPI( const std::string&, const std::string& = "" ); TimblAPI( const TimblAPI& ); ~TimblAPI(); diff --git a/include/timbl/TimblExperiment.h b/include/timbl/TimblExperiment.h index 4e9017d..ef749bb 100644 --- a/include/timbl/TimblExperiment.h +++ b/include/timbl/TimblExperiment.h @@ -178,8 +178,8 @@ namespace Timbl { bool GetCurrentWeights( std::vector& ); xmlNode *weightsToXML(); nlohmann::json weights_to_JSON(); - bool ShowOptions( std::ostream& ); - bool ShowSettings( std::ostream& ); + bool ShowOptions( std::ostream& ) override; + bool ShowSettings( std::ostream& ) override; xmlNode *settingsToXML(); nlohmann::json settings_to_JSON() override; bool showBestNeighbors( std::ostream& ) const; @@ -306,6 +306,7 @@ namespace Timbl { class IB1_Experiment: public TimblExperiment { public: + // cppcheck-suppress noExplicitConstructor IB1_Experiment( const size_t N = DEFAULT_MAX_FEATS, const std::string& s= "", const bool init = true ); @@ -330,7 +331,8 @@ namespace Timbl { class IB2_Experiment: public IB1_Experiment { public: - IB2_Experiment( size_t N, const std::string& s="" ): + // cppcheck-suppress noExplicitConstructor + IB2_Experiment( size_t N, const std::string& s="" ): IB1_Experiment( N, s ) { IB2_offset( 0 ); }; @@ -351,6 +353,7 @@ namespace Timbl { class LOO_Experiment: public IB1_Experiment { public: + // cppcheck-suppress noExplicitConstructor LOO_Experiment( int N, const std::string& s = "" ): IB1_Experiment( N, s ) { }; @@ -366,6 +369,7 @@ namespace Timbl { class CV_Experiment: public IB1_Experiment { public: + // cppcheck-suppress noExplicitConstructor CV_Experiment( int N = DEFAULT_MAX_FEATS, const std::string& s = "" ): IB1_Experiment( N, s ), CV_fileW(Unknown_w) { }; CV_Experiment( const CV_Experiment& ) = delete; // forbid copies @@ -392,9 +396,10 @@ namespace Timbl { class TRIBL_Experiment: public TimblExperiment { public: - TRIBL_Experiment( const size_t N = DEFAULT_MAX_FEATS, - const std::string& s = "", - const bool init = true ): + // cppcheck-suppress noExplicitConstructor + TRIBL_Experiment( const size_t N = DEFAULT_MAX_FEATS, + const std::string& s = "", + const bool init = true ): TimblExperiment( TRIBL_a, s ) { if ( init ) init_options_table( N ); }; @@ -415,9 +420,10 @@ namespace Timbl { class TRIBL2_Experiment: public TimblExperiment { public: - TRIBL2_Experiment( const size_t N = DEFAULT_MAX_FEATS, - const std::string& s = "", - const bool init = true ): + // cppcheck-suppress noExplicitConstructor + TRIBL2_Experiment( const size_t N = DEFAULT_MAX_FEATS, + const std::string& s = "", + const bool init = true ): TimblExperiment( TRIBL2_a, s ) { if ( init ) init_options_table( N ); }; @@ -437,9 +443,10 @@ namespace Timbl { class IG_Experiment: public TimblExperiment { public: - IG_Experiment( const size_t N = DEFAULT_MAX_FEATS, - const std::string& s = "", - const bool init = true ): + // cppcheck-suppress noExplicitConstructor + IG_Experiment( const size_t N = DEFAULT_MAX_FEATS, + const std::string& s = "", + const bool init = true ): TimblExperiment( IGTREE_a, s ) { if ( init ) init_options_table( N ); }; diff --git a/src/MBLClass.cxx b/src/MBLClass.cxx index 3815fd5..f8959d7 100644 --- a/src/MBLClass.cxx +++ b/src/MBLClass.cxx @@ -412,14 +412,14 @@ namespace Timbl { } } - bool MBLClass::ShowOptions( ostream& os ) const { + bool MBLClass::ShowOptions( ostream& os ) { os << "Possible Experiment Settings (current value between []):" << endl; Options.Show_Options( os ); os << endl; return true; } - bool MBLClass::ShowSettings( ostream& os ) const{ + bool MBLClass::ShowSettings( ostream& os ) { os << "Current Experiment Settings :" << endl; Options.Show_Settings( os ); os << endl; @@ -975,7 +975,7 @@ namespace Timbl { bool MBLClass::allocate_arrays(){ size_t Dim = targets.values_array.size(); - for ( const auto& feat : features.feats ){ + for ( auto *feat : features.feats ){ if ( !feat->Ignore() && !feat->isNumerical() ) { if ( !feat->AllocSparseArrays( Dim ) ){ @@ -1541,7 +1541,7 @@ namespace Timbl { double Entropy = 0.0; // first get the Database Entropy size_t totval = targets.TotalValues(); - for ( const auto& it : targets.values_array ){ + for ( const auto *it : targets.values_array ){ double Ratio = it->ValFreq() / (double)totval; if ( Ratio > 0 ){ Entropy += Ratio * Log2(Ratio);