# LCOV - BayesNet Coverage Report - bayesnet/feature_selection/FCBF.cc

LCOV - code coverage report

Current view: | top level - bayesnet/feature_selection - FCBF.cc (source / functions) |  |  | Coverage | Total | Hit
Test: | BayesNet Coverage Report |  | Lines: | 100.0 % | 26 | 26
Test Date: | 2024-05-06 17:54:04 |  | Functions: | 100.0 % | 2 | 2
Legend: | Lines: hit not hit |

                Line data    Source code

           1              : // ***************************************************************
           2              : // SPDX-FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
           3              : // SPDX-FileType: SOURCE
           4              : // SPDX-License-Identifier: MIT
           5              : // ***************************************************************
           6              :
           7              : #include "bayesnet/utils/bayesnetUtils.h"
           8              : #include "FCBF.h"
           9              : namespace bayesnet {
          10              :
          11           76 :     FCBF::FCBF(const torch::Tensor& samples, const std::vector<std::string>& features, const std::string& className, const int maxFeatures, const int classNumStates, const torch::Tensor& weights, const double threshold) :
          12           76 :         FeatureSelect(samples, features, className, maxFeatures, classNumStates, weights), threshold(threshold)
          13              :     {
          14           76 :         if (threshold < 1e-7) {
          15           20 :             throw std::invalid_argument("Threshold cannot be less than 1e-7");
          16              :         }
          17           76 :     }
          18           56 :     void FCBF::fit()
          19              :     {
          20           56 :         initialize();
          21           56 :         computeSuLabels();
          22           56 :         auto featureOrder = argsort(suLabels); // sort descending order
          23           56 :         auto featureOrderCopy = featureOrder;
          24          419 :         for (const auto& feature : featureOrder) {
          25              :             // Don't self compare
          26          372 :             featureOrderCopy.erase(featureOrderCopy.begin());
          27          372 :             if (suLabels.at(feature) == 0.0) {
          28              :                 // The feature has been removed from the list
          29          153 :                 continue;
          30              :             }
          31          219 :             if (suLabels.at(feature) < threshold) {
          32            5 :                 break;
          33              :             }
          34              :             // Remove redundant features
          35         1220 :             for (const auto& featureCopy : featureOrderCopy) {
          36         1006 :                 double value = computeSuFeatures(feature, featureCopy);
          37         1006 :                 if (value >= suLabels.at(featureCopy)) {
          38              :                     // Remove feature from list
          39          333 :                     suLabels[featureCopy] = 0.0;
          40              :                 }
          41              :             }
          42          214 :             selectedFeatures.push_back(feature);
          43          214 :             selectedScores.push_back(suLabels[feature]);
          44          214 :             if (selectedFeatures.size() == maxFeatures) {
          45            4 :                 break;
          46              :             }
          47              :         }
          48           56 :         fitted = true;
          49           56 :     }
          50              : }

Generated by: LCOV version 2.0-1