10 KiB
10 KiB
<html lang="en">
<head>
</head>
</html>
LCOV - code coverage report | ||||||||||||||||||||||
![]() | ||||||||||||||||||||||
|
||||||||||||||||||||||
![]() |
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 <limits> 8 : #include "bayesnet/utils/bayesnetUtils.h" 9 : #include "IWSS.h" 10 : namespace bayesnet { 11 9 : IWSS::IWSS(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 9 : FeatureSelect(samples, features, className, maxFeatures, classNumStates, weights), threshold(threshold) 13 : { 14 9 : if (threshold < 0 || threshold > .5) { 15 4 : throw std::invalid_argument("Threshold has to be in [0, 0.5]"); 16 : } 17 9 : } 18 5 : void IWSS::fit() 19 : { 20 5 : initialize(); 21 5 : computeSuLabels(); 22 5 : auto featureOrder = argsort(suLabels); // sort descending order 23 5 : auto featureOrderCopy = featureOrder; 24 : // Add first and second features to result 25 : // First with its own score 26 5 : auto first_feature = pop_first(featureOrderCopy); 27 5 : selectedFeatures.push_back(first_feature); 28 5 : selectedScores.push_back(suLabels.at(first_feature)); 29 : // Second with the score of the candidates 30 5 : selectedFeatures.push_back(pop_first(featureOrderCopy)); 31 5 : auto merit = computeMeritCFS(); 32 5 : selectedScores.push_back(merit); 33 17 : for (const auto feature : featureOrderCopy) { 34 17 : selectedFeatures.push_back(feature); 35 : // Compute merit with selectedFeatures 36 17 : auto meritNew = computeMeritCFS(); 37 17 : double delta = merit != 0.0 ? std::abs(merit - meritNew) / merit : 0.0; 38 17 : if (meritNew > merit || delta < threshold) { 39 12 : if (meritNew > merit) { 40 0 : merit = meritNew; 41 : } 42 12 : selectedScores.push_back(meritNew); 43 : } else { 44 5 : selectedFeatures.pop_back(); 45 5 : break; 46 : } 47 12 : if (selectedFeatures.size() == maxFeatures) { 48 0 : break; 49 : } 50 : } 51 5 : fitted = true; 52 5 : } 53 : } |
![]() |
Generated by: LCOV version 2.0-1 |
</html>