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 : #ifndef BAYESNET_METRICS_H 8 : #define BAYESNET_METRICS_H 9 : #include <vector> 10 : #include <string> 11 : #include <torch/torch.h> 12 : namespace bayesnet { 13 : class Metrics { 14 : public: 15 413 : Metrics() = default; 16 : Metrics(const torch::Tensor& samples, const std::vector<std::string>& features, const std::string& className, const int classNumStates); 17 : Metrics(const std::vector<std::vector<int>>& vsamples, const std::vector<int>& labels, const std::vector<std::string>& features, const std::string& className, const int classNumStates); 18 : std::vector<int> SelectKBestWeighted(const torch::Tensor& weights, bool ascending = false, unsigned k = 0); 19 : std::vector<double> getScoresKBest() const; 20 : double mutualInformation(const torch::Tensor& firstFeature, const torch::Tensor& secondFeature, const torch::Tensor& weights); 21 : std::vector<float> conditionalEdgeWeights(std::vector<float>& weights); // To use in Python 22 : torch::Tensor conditionalEdge(const torch::Tensor& weights); 23 : std::vector<std::pair<int, int>> maximumSpanningTree(const std::vector<std::string>& features, const torch::Tensor& weights, const int root); 24 : protected: 25 : torch::Tensor samples; // n+1xm torch::Tensor used to fit the model where samples[-1] is the y std::vector 26 : std::string className; 27 : double entropy(const torch::Tensor& feature, const torch::Tensor& weights); 28 : std::vector<std::string> features; 29 : template <class T> 30 192 : std::vector<std::pair<T, T>> doCombinations(const std::vector<T>& source) 31 : { 32 192 : std::vector<std::pair<T, T>> result; 33 1013 : for (int i = 0; i < source.size(); ++i) { 34 821 : T temp = source[i]; 35 2590 : for (int j = i + 1; j < source.size(); ++j) { 36 1769 : result.push_back({ temp, source[j] }); 37 : } 38 : } 39 192 : return result; 40 0 : } 41 : template <class T> 42 10 : T pop_first(std::vector<T>& v) 43 : { 44 10 : T temp = v[0]; 45 10 : v.erase(v.begin()); 46 10 : return temp; 47 : } 48 : private: 49 : int classNumStates = 0; 50 : std::vector<double> scoresKBest; 51 : std::vector<int> featuresKBest; // sorted indices of the features 52 : double conditionalEntropy(const torch::Tensor& firstFeature, const torch::Tensor& secondFeature, const torch::Tensor& weights); 53 : }; 54 : } 55 : #endif |
![]() |
Generated by: LCOV version 2.0-1 |
</html>