271 lines
29 KiB
HTML
271 lines
29 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
<title>LCOV - coverage.info - bayesnet/classifiers/Classifier.cc</title>
|
|
<link rel="stylesheet" type="text/css" href="../../gcov.css">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<table width="100%" border=0 cellspacing=0 cellpadding=0>
|
|
<tr><td class="title">LCOV - code coverage report</td></tr>
|
|
<tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
|
|
|
|
<tr>
|
|
<td width="100%">
|
|
<table cellpadding=1 border=0 width="100%">
|
|
<tr>
|
|
<td width="10%" class="headerItem">Current view:</td>
|
|
<td width="10%" class="headerValue"><a href="../../index.html">top level</a> - <a href="index.html">bayesnet/classifiers</a> - Classifier.cc<span style="font-size: 80%;"> (source / <a href="Classifier.cc.func-c.html">functions</a>)</span></td>
|
|
<td width="5%"></td>
|
|
<td width="5%"></td>
|
|
<td width="5%" class="headerCovTableHead">Coverage</td>
|
|
<td width="5%" class="headerCovTableHead" title="Covered + Uncovered code">Total</td>
|
|
<td width="5%" class="headerCovTableHead" title="Exercised code only">Hit</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="headerItem">Test:</td>
|
|
<td class="headerValue">coverage.info</td>
|
|
<td></td>
|
|
<td class="headerItem">Lines:</td>
|
|
<td class="headerCovTableEntryHi">100.0 %</td>
|
|
<td class="headerCovTableEntry">126</td>
|
|
<td class="headerCovTableEntry">126</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="headerItem">Test Date:</td>
|
|
<td class="headerValue">2024-04-30 13:59:18</td>
|
|
<td></td>
|
|
<td class="headerItem">Functions:</td>
|
|
<td class="headerCovTableEntryHi">100.0 %</td>
|
|
<td class="headerCovTableEntry">24</td>
|
|
<td class="headerCovTableEntry">24</td>
|
|
</tr>
|
|
<tr><td><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
|
|
</table>
|
|
|
|
<table cellpadding=0 cellspacing=0 border=0>
|
|
<tr>
|
|
<td><br></td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<pre class="sourceHeading"> Line data Source code</pre>
|
|
<pre class="source">
|
|
<span id="L1"><span class="lineNum"> 1</span> : // ***************************************************************</span>
|
|
<span id="L2"><span class="lineNum"> 2</span> : // SPDX-FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez</span>
|
|
<span id="L3"><span class="lineNum"> 3</span> : // SPDX-FileType: SOURCE</span>
|
|
<span id="L4"><span class="lineNum"> 4</span> : // SPDX-License-Identifier: MIT</span>
|
|
<span id="L5"><span class="lineNum"> 5</span> : // ***************************************************************</span>
|
|
<span id="L6"><span class="lineNum"> 6</span> : </span>
|
|
<span id="L7"><span class="lineNum"> 7</span> : #include <sstream></span>
|
|
<span id="L8"><span class="lineNum"> 8</span> : #include "bayesnet/utils/bayesnetUtils.h"</span>
|
|
<span id="L9"><span class="lineNum"> 9</span> : #include "Classifier.h"</span>
|
|
<span id="L10"><span class="lineNum"> 10</span> : </span>
|
|
<span id="L11"><span class="lineNum"> 11</span> : namespace bayesnet {</span>
|
|
<span id="L12"><span class="lineNum"> 12</span> <span class="tlaGNC tlaBgGNC"> 2658 : Classifier::Classifier(Network model) : model(model), m(0), n(0), metrics(Metrics()), fitted(false) {}</span></span>
|
|
<span id="L13"><span class="lineNum"> 13</span> : const std::string CLASSIFIER_NOT_FITTED = "Classifier has not been fitted";</span>
|
|
<span id="L14"><span class="lineNum"> 14</span> <span class="tlaGNC"> 1932 : Classifier& Classifier::build(const std::vector<std::string>& features, const std::string& className, std::map<std::string, std::vector<int>>& states, const torch::Tensor& weights)</span></span>
|
|
<span id="L15"><span class="lineNum"> 15</span> : {</span>
|
|
<span id="L16"><span class="lineNum"> 16</span> <span class="tlaGNC"> 1932 : this->features = features;</span></span>
|
|
<span id="L17"><span class="lineNum"> 17</span> <span class="tlaGNC"> 1932 : this->className = className;</span></span>
|
|
<span id="L18"><span class="lineNum"> 18</span> <span class="tlaGNC"> 1932 : this->states = states;</span></span>
|
|
<span id="L19"><span class="lineNum"> 19</span> <span class="tlaGNC"> 1932 : m = dataset.size(1);</span></span>
|
|
<span id="L20"><span class="lineNum"> 20</span> <span class="tlaGNC"> 1932 : n = features.size();</span></span>
|
|
<span id="L21"><span class="lineNum"> 21</span> <span class="tlaGNC"> 1932 : checkFitParameters();</span></span>
|
|
<span id="L22"><span class="lineNum"> 22</span> <span class="tlaGNC"> 1884 : auto n_classes = states.at(className).size();</span></span>
|
|
<span id="L23"><span class="lineNum"> 23</span> <span class="tlaGNC"> 1884 : metrics = Metrics(dataset, features, className, n_classes);</span></span>
|
|
<span id="L24"><span class="lineNum"> 24</span> <span class="tlaGNC"> 1884 : model.initialize();</span></span>
|
|
<span id="L25"><span class="lineNum"> 25</span> <span class="tlaGNC"> 1884 : buildModel(weights);</span></span>
|
|
<span id="L26"><span class="lineNum"> 26</span> <span class="tlaGNC"> 1884 : trainModel(weights);</span></span>
|
|
<span id="L27"><span class="lineNum"> 27</span> <span class="tlaGNC"> 1860 : fitted = true;</span></span>
|
|
<span id="L28"><span class="lineNum"> 28</span> <span class="tlaGNC"> 1860 : return *this;</span></span>
|
|
<span id="L29"><span class="lineNum"> 29</span> : }</span>
|
|
<span id="L30"><span class="lineNum"> 30</span> <span class="tlaGNC"> 486 : void Classifier::buildDataset(torch::Tensor& ytmp)</span></span>
|
|
<span id="L31"><span class="lineNum"> 31</span> : {</span>
|
|
<span id="L32"><span class="lineNum"> 32</span> : try {</span>
|
|
<span id="L33"><span class="lineNum"> 33</span> <span class="tlaGNC"> 486 : auto yresized = torch::transpose(ytmp.view({ ytmp.size(0), 1 }), 0, 1);</span></span>
|
|
<span id="L34"><span class="lineNum"> 34</span> <span class="tlaGNC"> 1506 : dataset = torch::cat({ dataset, yresized }, 0);</span></span>
|
|
<span id="L35"><span class="lineNum"> 35</span> <span class="tlaGNC"> 486 : }</span></span>
|
|
<span id="L36"><span class="lineNum"> 36</span> <span class="tlaGNC"> 24 : catch (const std::exception& e) {</span></span>
|
|
<span id="L37"><span class="lineNum"> 37</span> <span class="tlaGNC"> 24 : std::stringstream oss;</span></span>
|
|
<span id="L38"><span class="lineNum"> 38</span> <span class="tlaGNC"> 24 : oss << "* Error in X and y dimensions *\n";</span></span>
|
|
<span id="L39"><span class="lineNum"> 39</span> <span class="tlaGNC"> 24 : oss << "X dimensions: " << dataset.sizes() << "\n";</span></span>
|
|
<span id="L40"><span class="lineNum"> 40</span> <span class="tlaGNC"> 24 : oss << "y dimensions: " << ytmp.sizes();</span></span>
|
|
<span id="L41"><span class="lineNum"> 41</span> <span class="tlaGNC"> 24 : throw std::runtime_error(oss.str());</span></span>
|
|
<span id="L42"><span class="lineNum"> 42</span> <span class="tlaGNC"> 48 : }</span></span>
|
|
<span id="L43"><span class="lineNum"> 43</span> <span class="tlaGNC"> 972 : }</span></span>
|
|
<span id="L44"><span class="lineNum"> 44</span> <span class="tlaGNC"> 1680 : void Classifier::trainModel(const torch::Tensor& weights)</span></span>
|
|
<span id="L45"><span class="lineNum"> 45</span> : {</span>
|
|
<span id="L46"><span class="lineNum"> 46</span> <span class="tlaGNC"> 1680 : model.fit(dataset, weights, features, className, states);</span></span>
|
|
<span id="L47"><span class="lineNum"> 47</span> <span class="tlaGNC"> 1680 : }</span></span>
|
|
<span id="L48"><span class="lineNum"> 48</span> : // X is nxm where n is the number of features and m the number of samples</span>
|
|
<span id="L49"><span class="lineNum"> 49</span> <span class="tlaGNC"> 192 : Classifier& Classifier::fit(torch::Tensor& X, torch::Tensor& y, const std::vector<std::string>& features, const std::string& className, std::map<std::string, std::vector<int>>& states)</span></span>
|
|
<span id="L50"><span class="lineNum"> 50</span> : {</span>
|
|
<span id="L51"><span class="lineNum"> 51</span> <span class="tlaGNC"> 192 : dataset = X;</span></span>
|
|
<span id="L52"><span class="lineNum"> 52</span> <span class="tlaGNC"> 192 : buildDataset(y);</span></span>
|
|
<span id="L53"><span class="lineNum"> 53</span> <span class="tlaGNC"> 180 : const torch::Tensor weights = torch::full({ dataset.size(1) }, 1.0 / dataset.size(1), torch::kDouble);</span></span>
|
|
<span id="L54"><span class="lineNum"> 54</span> <span class="tlaGNC"> 312 : return build(features, className, states, weights);</span></span>
|
|
<span id="L55"><span class="lineNum"> 55</span> <span class="tlaGNC"> 180 : }</span></span>
|
|
<span id="L56"><span class="lineNum"> 56</span> : // X is nxm where n is the number of features and m the number of samples</span>
|
|
<span id="L57"><span class="lineNum"> 57</span> <span class="tlaGNC"> 180 : Classifier& Classifier::fit(std::vector<std::vector<int>>& X, std::vector<int>& y, const std::vector<std::string>& features, const std::string& className, std::map<std::string, std::vector<int>>& states)</span></span>
|
|
<span id="L58"><span class="lineNum"> 58</span> : {</span>
|
|
<span id="L59"><span class="lineNum"> 59</span> <span class="tlaGNC"> 180 : dataset = torch::zeros({ static_cast<int>(X.size()), static_cast<int>(X[0].size()) }, torch::kInt32);</span></span>
|
|
<span id="L60"><span class="lineNum"> 60</span> <span class="tlaGNC"> 1254 : for (int i = 0; i < X.size(); ++i) {</span></span>
|
|
<span id="L61"><span class="lineNum"> 61</span> <span class="tlaGNC"> 4296 : dataset.index_put_({ i, "..." }, torch::tensor(X[i], torch::kInt32));</span></span>
|
|
<span id="L62"><span class="lineNum"> 62</span> : }</span>
|
|
<span id="L63"><span class="lineNum"> 63</span> <span class="tlaGNC"> 180 : auto ytmp = torch::tensor(y, torch::kInt32);</span></span>
|
|
<span id="L64"><span class="lineNum"> 64</span> <span class="tlaGNC"> 180 : buildDataset(ytmp);</span></span>
|
|
<span id="L65"><span class="lineNum"> 65</span> <span class="tlaGNC"> 168 : const torch::Tensor weights = torch::full({ dataset.size(1) }, 1.0 / dataset.size(1), torch::kDouble);</span></span>
|
|
<span id="L66"><span class="lineNum"> 66</span> <span class="tlaGNC"> 312 : return build(features, className, states, weights);</span></span>
|
|
<span id="L67"><span class="lineNum"> 67</span> <span class="tlaGNC"> 1278 : }</span></span>
|
|
<span id="L68"><span class="lineNum"> 68</span> <span class="tlaGNC"> 594 : Classifier& Classifier::fit(torch::Tensor& dataset, const std::vector<std::string>& features, const std::string& className, std::map<std::string, std::vector<int>>& states)</span></span>
|
|
<span id="L69"><span class="lineNum"> 69</span> : {</span>
|
|
<span id="L70"><span class="lineNum"> 70</span> <span class="tlaGNC"> 594 : this->dataset = dataset;</span></span>
|
|
<span id="L71"><span class="lineNum"> 71</span> <span class="tlaGNC"> 594 : const torch::Tensor weights = torch::full({ dataset.size(1) }, 1.0 / dataset.size(1), torch::kDouble);</span></span>
|
|
<span id="L72"><span class="lineNum"> 72</span> <span class="tlaGNC"> 1188 : return build(features, className, states, weights);</span></span>
|
|
<span id="L73"><span class="lineNum"> 73</span> <span class="tlaGNC"> 594 : }</span></span>
|
|
<span id="L74"><span class="lineNum"> 74</span> <span class="tlaGNC"> 990 : Classifier& Classifier::fit(torch::Tensor& dataset, const std::vector<std::string>& features, const std::string& className, std::map<std::string, std::vector<int>>& states, const torch::Tensor& weights)</span></span>
|
|
<span id="L75"><span class="lineNum"> 75</span> : {</span>
|
|
<span id="L76"><span class="lineNum"> 76</span> <span class="tlaGNC"> 990 : this->dataset = dataset;</span></span>
|
|
<span id="L77"><span class="lineNum"> 77</span> <span class="tlaGNC"> 990 : return build(features, className, states, weights);</span></span>
|
|
<span id="L78"><span class="lineNum"> 78</span> : }</span>
|
|
<span id="L79"><span class="lineNum"> 79</span> <span class="tlaGNC"> 1932 : void Classifier::checkFitParameters()</span></span>
|
|
<span id="L80"><span class="lineNum"> 80</span> : {</span>
|
|
<span id="L81"><span class="lineNum"> 81</span> <span class="tlaGNC"> 1932 : if (torch::is_floating_point(dataset)) {</span></span>
|
|
<span id="L82"><span class="lineNum"> 82</span> <span class="tlaGNC"> 12 : throw std::invalid_argument("dataset (X, y) must be of type Integer");</span></span>
|
|
<span id="L83"><span class="lineNum"> 83</span> : }</span>
|
|
<span id="L84"><span class="lineNum"> 84</span> <span class="tlaGNC"> 1920 : if (dataset.size(0) - 1 != features.size()) {</span></span>
|
|
<span id="L85"><span class="lineNum"> 85</span> <span class="tlaGNC"> 12 : throw std::invalid_argument("Classifier: X " + std::to_string(dataset.size(0) - 1) + " and features " + std::to_string(features.size()) + " must have the same number of features");</span></span>
|
|
<span id="L86"><span class="lineNum"> 86</span> : }</span>
|
|
<span id="L87"><span class="lineNum"> 87</span> <span class="tlaGNC"> 1908 : if (states.find(className) == states.end()) {</span></span>
|
|
<span id="L88"><span class="lineNum"> 88</span> <span class="tlaGNC"> 12 : throw std::invalid_argument("class name not found in states");</span></span>
|
|
<span id="L89"><span class="lineNum"> 89</span> : }</span>
|
|
<span id="L90"><span class="lineNum"> 90</span> <span class="tlaGNC"> 42624 : for (auto feature : features) {</span></span>
|
|
<span id="L91"><span class="lineNum"> 91</span> <span class="tlaGNC"> 40740 : if (states.find(feature) == states.end()) {</span></span>
|
|
<span id="L92"><span class="lineNum"> 92</span> <span class="tlaGNC"> 12 : throw std::invalid_argument("feature [" + feature + "] not found in states");</span></span>
|
|
<span id="L93"><span class="lineNum"> 93</span> : }</span>
|
|
<span id="L94"><span class="lineNum"> 94</span> <span class="tlaGNC"> 40740 : }</span></span>
|
|
<span id="L95"><span class="lineNum"> 95</span> <span class="tlaGNC"> 1884 : }</span></span>
|
|
<span id="L96"><span class="lineNum"> 96</span> <span class="tlaGNC"> 2550 : torch::Tensor Classifier::predict(torch::Tensor& X)</span></span>
|
|
<span id="L97"><span class="lineNum"> 97</span> : {</span>
|
|
<span id="L98"><span class="lineNum"> 98</span> <span class="tlaGNC"> 2550 : if (!fitted) {</span></span>
|
|
<span id="L99"><span class="lineNum"> 99</span> <span class="tlaGNC"> 24 : throw std::logic_error(CLASSIFIER_NOT_FITTED);</span></span>
|
|
<span id="L100"><span class="lineNum"> 100</span> : }</span>
|
|
<span id="L101"><span class="lineNum"> 101</span> <span class="tlaGNC"> 2526 : return model.predict(X);</span></span>
|
|
<span id="L102"><span class="lineNum"> 102</span> : }</span>
|
|
<span id="L103"><span class="lineNum"> 103</span> <span class="tlaGNC"> 24 : std::vector<int> Classifier::predict(std::vector<std::vector<int>>& X)</span></span>
|
|
<span id="L104"><span class="lineNum"> 104</span> : {</span>
|
|
<span id="L105"><span class="lineNum"> 105</span> <span class="tlaGNC"> 24 : if (!fitted) {</span></span>
|
|
<span id="L106"><span class="lineNum"> 106</span> <span class="tlaGNC"> 12 : throw std::logic_error(CLASSIFIER_NOT_FITTED);</span></span>
|
|
<span id="L107"><span class="lineNum"> 107</span> : }</span>
|
|
<span id="L108"><span class="lineNum"> 108</span> <span class="tlaGNC"> 12 : auto m_ = X[0].size();</span></span>
|
|
<span id="L109"><span class="lineNum"> 109</span> <span class="tlaGNC"> 12 : auto n_ = X.size();</span></span>
|
|
<span id="L110"><span class="lineNum"> 110</span> <span class="tlaGNC"> 12 : std::vector<std::vector<int>> Xd(n_, std::vector<int>(m_, 0));</span></span>
|
|
<span id="L111"><span class="lineNum"> 111</span> <span class="tlaGNC"> 60 : for (auto i = 0; i < n_; i++) {</span></span>
|
|
<span id="L112"><span class="lineNum"> 112</span> <span class="tlaGNC"> 96 : Xd[i] = std::vector<int>(X[i].begin(), X[i].end());</span></span>
|
|
<span id="L113"><span class="lineNum"> 113</span> : }</span>
|
|
<span id="L114"><span class="lineNum"> 114</span> <span class="tlaGNC"> 12 : auto yp = model.predict(Xd);</span></span>
|
|
<span id="L115"><span class="lineNum"> 115</span> <span class="tlaGNC"> 24 : return yp;</span></span>
|
|
<span id="L116"><span class="lineNum"> 116</span> <span class="tlaGNC"> 12 : }</span></span>
|
|
<span id="L117"><span class="lineNum"> 117</span> <span class="tlaGNC"> 2226 : torch::Tensor Classifier::predict_proba(torch::Tensor& X)</span></span>
|
|
<span id="L118"><span class="lineNum"> 118</span> : {</span>
|
|
<span id="L119"><span class="lineNum"> 119</span> <span class="tlaGNC"> 2226 : if (!fitted) {</span></span>
|
|
<span id="L120"><span class="lineNum"> 120</span> <span class="tlaGNC"> 12 : throw std::logic_error(CLASSIFIER_NOT_FITTED);</span></span>
|
|
<span id="L121"><span class="lineNum"> 121</span> : }</span>
|
|
<span id="L122"><span class="lineNum"> 122</span> <span class="tlaGNC"> 2214 : return model.predict_proba(X);</span></span>
|
|
<span id="L123"><span class="lineNum"> 123</span> : }</span>
|
|
<span id="L124"><span class="lineNum"> 124</span> <span class="tlaGNC"> 390 : std::vector<std::vector<double>> Classifier::predict_proba(std::vector<std::vector<int>>& X)</span></span>
|
|
<span id="L125"><span class="lineNum"> 125</span> : {</span>
|
|
<span id="L126"><span class="lineNum"> 126</span> <span class="tlaGNC"> 390 : if (!fitted) {</span></span>
|
|
<span id="L127"><span class="lineNum"> 127</span> <span class="tlaGNC"> 12 : throw std::logic_error(CLASSIFIER_NOT_FITTED);</span></span>
|
|
<span id="L128"><span class="lineNum"> 128</span> : }</span>
|
|
<span id="L129"><span class="lineNum"> 129</span> <span class="tlaGNC"> 378 : auto m_ = X[0].size();</span></span>
|
|
<span id="L130"><span class="lineNum"> 130</span> <span class="tlaGNC"> 378 : auto n_ = X.size();</span></span>
|
|
<span id="L131"><span class="lineNum"> 131</span> <span class="tlaGNC"> 378 : std::vector<std::vector<int>> Xd(n_, std::vector<int>(m_, 0));</span></span>
|
|
<span id="L132"><span class="lineNum"> 132</span> : // Convert to nxm vector</span>
|
|
<span id="L133"><span class="lineNum"> 133</span> <span class="tlaGNC"> 3240 : for (auto i = 0; i < n_; i++) {</span></span>
|
|
<span id="L134"><span class="lineNum"> 134</span> <span class="tlaGNC"> 5724 : Xd[i] = std::vector<int>(X[i].begin(), X[i].end());</span></span>
|
|
<span id="L135"><span class="lineNum"> 135</span> : }</span>
|
|
<span id="L136"><span class="lineNum"> 136</span> <span class="tlaGNC"> 378 : auto yp = model.predict_proba(Xd);</span></span>
|
|
<span id="L137"><span class="lineNum"> 137</span> <span class="tlaGNC"> 756 : return yp;</span></span>
|
|
<span id="L138"><span class="lineNum"> 138</span> <span class="tlaGNC"> 378 : }</span></span>
|
|
<span id="L139"><span class="lineNum"> 139</span> <span class="tlaGNC"> 168 : float Classifier::score(torch::Tensor& X, torch::Tensor& y)</span></span>
|
|
<span id="L140"><span class="lineNum"> 140</span> : {</span>
|
|
<span id="L141"><span class="lineNum"> 141</span> <span class="tlaGNC"> 168 : torch::Tensor y_pred = predict(X);</span></span>
|
|
<span id="L142"><span class="lineNum"> 142</span> <span class="tlaGNC"> 312 : return (y_pred == y).sum().item<float>() / y.size(0);</span></span>
|
|
<span id="L143"><span class="lineNum"> 143</span> <span class="tlaGNC"> 156 : }</span></span>
|
|
<span id="L144"><span class="lineNum"> 144</span> <span class="tlaGNC"> 24 : float Classifier::score(std::vector<std::vector<int>>& X, std::vector<int>& y)</span></span>
|
|
<span id="L145"><span class="lineNum"> 145</span> : {</span>
|
|
<span id="L146"><span class="lineNum"> 146</span> <span class="tlaGNC"> 24 : if (!fitted) {</span></span>
|
|
<span id="L147"><span class="lineNum"> 147</span> <span class="tlaGNC"> 12 : throw std::logic_error(CLASSIFIER_NOT_FITTED);</span></span>
|
|
<span id="L148"><span class="lineNum"> 148</span> : }</span>
|
|
<span id="L149"><span class="lineNum"> 149</span> <span class="tlaGNC"> 12 : return model.score(X, y);</span></span>
|
|
<span id="L150"><span class="lineNum"> 150</span> : }</span>
|
|
<span id="L151"><span class="lineNum"> 151</span> <span class="tlaGNC"> 36 : std::vector<std::string> Classifier::show() const</span></span>
|
|
<span id="L152"><span class="lineNum"> 152</span> : {</span>
|
|
<span id="L153"><span class="lineNum"> 153</span> <span class="tlaGNC"> 36 : return model.show();</span></span>
|
|
<span id="L154"><span class="lineNum"> 154</span> : }</span>
|
|
<span id="L155"><span class="lineNum"> 155</span> <span class="tlaGNC"> 1680 : void Classifier::addNodes()</span></span>
|
|
<span id="L156"><span class="lineNum"> 156</span> : {</span>
|
|
<span id="L157"><span class="lineNum"> 157</span> : // Add all nodes to the network</span>
|
|
<span id="L158"><span class="lineNum"> 158</span> <span class="tlaGNC"> 39648 : for (const auto& feature : features) {</span></span>
|
|
<span id="L159"><span class="lineNum"> 159</span> <span class="tlaGNC"> 37968 : model.addNode(feature);</span></span>
|
|
<span id="L160"><span class="lineNum"> 160</span> : }</span>
|
|
<span id="L161"><span class="lineNum"> 161</span> <span class="tlaGNC"> 1680 : model.addNode(className);</span></span>
|
|
<span id="L162"><span class="lineNum"> 162</span> <span class="tlaGNC"> 1680 : }</span></span>
|
|
<span id="L163"><span class="lineNum"> 163</span> <span class="tlaGNC"> 282 : int Classifier::getNumberOfNodes() const</span></span>
|
|
<span id="L164"><span class="lineNum"> 164</span> : {</span>
|
|
<span id="L165"><span class="lineNum"> 165</span> : // Features does not include class</span>
|
|
<span id="L166"><span class="lineNum"> 166</span> <span class="tlaGNC"> 282 : return fitted ? model.getFeatures().size() : 0;</span></span>
|
|
<span id="L167"><span class="lineNum"> 167</span> : }</span>
|
|
<span id="L168"><span class="lineNum"> 168</span> <span class="tlaGNC"> 282 : int Classifier::getNumberOfEdges() const</span></span>
|
|
<span id="L169"><span class="lineNum"> 169</span> : {</span>
|
|
<span id="L170"><span class="lineNum"> 170</span> <span class="tlaGNC"> 282 : return fitted ? model.getNumEdges() : 0;</span></span>
|
|
<span id="L171"><span class="lineNum"> 171</span> : }</span>
|
|
<span id="L172"><span class="lineNum"> 172</span> <span class="tlaGNC"> 36 : int Classifier::getNumberOfStates() const</span></span>
|
|
<span id="L173"><span class="lineNum"> 173</span> : {</span>
|
|
<span id="L174"><span class="lineNum"> 174</span> <span class="tlaGNC"> 36 : return fitted ? model.getStates() : 0;</span></span>
|
|
<span id="L175"><span class="lineNum"> 175</span> : }</span>
|
|
<span id="L176"><span class="lineNum"> 176</span> <span class="tlaGNC"> 510 : int Classifier::getClassNumStates() const</span></span>
|
|
<span id="L177"><span class="lineNum"> 177</span> : {</span>
|
|
<span id="L178"><span class="lineNum"> 178</span> <span class="tlaGNC"> 510 : return fitted ? model.getClassNumStates() : 0;</span></span>
|
|
<span id="L179"><span class="lineNum"> 179</span> : }</span>
|
|
<span id="L180"><span class="lineNum"> 180</span> <span class="tlaGNC"> 6 : std::vector<std::string> Classifier::topological_order()</span></span>
|
|
<span id="L181"><span class="lineNum"> 181</span> : {</span>
|
|
<span id="L182"><span class="lineNum"> 182</span> <span class="tlaGNC"> 6 : return model.topological_sort();</span></span>
|
|
<span id="L183"><span class="lineNum"> 183</span> : }</span>
|
|
<span id="L184"><span class="lineNum"> 184</span> <span class="tlaGNC"> 6 : std::string Classifier::dump_cpt() const</span></span>
|
|
<span id="L185"><span class="lineNum"> 185</span> : {</span>
|
|
<span id="L186"><span class="lineNum"> 186</span> <span class="tlaGNC"> 6 : return model.dump_cpt();</span></span>
|
|
<span id="L187"><span class="lineNum"> 187</span> : }</span>
|
|
<span id="L188"><span class="lineNum"> 188</span> <span class="tlaGNC"> 126 : void Classifier::setHyperparameters(const nlohmann::json& hyperparameters)</span></span>
|
|
<span id="L189"><span class="lineNum"> 189</span> : {</span>
|
|
<span id="L190"><span class="lineNum"> 190</span> <span class="tlaGNC"> 126 : if (!hyperparameters.empty()) {</span></span>
|
|
<span id="L191"><span class="lineNum"> 191</span> <span class="tlaGNC"> 12 : throw std::invalid_argument("Invalid hyperparameters" + hyperparameters.dump());</span></span>
|
|
<span id="L192"><span class="lineNum"> 192</span> : }</span>
|
|
<span id="L193"><span class="lineNum"> 193</span> <span class="tlaGNC"> 114 : }</span></span>
|
|
<span id="L194"><span class="lineNum"> 194</span> : }</span>
|
|
</pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<br>
|
|
|
|
<table width="100%" border=0 cellspacing=0 cellpadding=0>
|
|
<tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
|
|
<tr><td class="versionInfo">Generated by: <a href="https://github.com//linux-test-project/lcov" target="_parent">LCOV version 2.0-1</a></td></tr>
|
|
</table>
|
|
<br>
|
|
|
|
</body>
|
|
</html>
|