Files
BayesNet/docs/manual/_s_pn_d_e_8cc_source.html

10 KiB

<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="dynsections.js"></script> <script type="text/javascript" src="clipboard.js"></script> <script type="text/javascript" src="navtreedata.js"></script> <script type="text/javascript" src="navtree.js"></script> <script type="text/javascript" src="resize.js"></script> <script type="text/javascript" src="cookie.js"></script> <script type="text/javascript" src="search/searchdata.js"></script> <script type="text/javascript" src="search/search.js"></script> </head>
BayesNet 1.0.5
Bayesian Network Classifiers using libtorch from scratch
<script type="text/javascript"> /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */ var searchBox = new SearchBox("searchBox", "search/",'.html'); /* @license-end */ </script> <script type="text/javascript"> /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */ $(function() { codefold.init(0); }); /* @license-end */ </script> <script type="text/javascript" src="menudata.js"></script> <script type="text/javascript" src="menu.js"></script> <script type="text/javascript"> /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */ $(function() { initMenu('',true,false,'search.php','Search',true); $(function() { init_search(); }); }); /* @license-end */ </script>
<script type="text/javascript"> /* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */ $(function(){initNavTree('_s_pn_d_e_8cc_source.html',''); initResizable(true); }); /* @license-end */ </script>
Loading...
Searching...
No Matches
SPnDE.cc
1// ***************************************************************
2// SPDX-FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
3// SPDX-FileType: SOURCE
4// SPDX-License-Identifier: MIT
5// ***************************************************************
6
7#include "SPnDE.h"
8
9namespace bayesnet {
10
11 SPnDE::SPnDE(std::vector<int> parents) : Classifier(Network()), parents(parents) {}
12
13 void SPnDE::buildModel(const torch::Tensor& weights)
14 {
15 // 0. Add all nodes to the model
16 addNodes();
17 std::vector<int> attributes;
18 for (int i = 0; i < static_cast<int>(features.size()); ++i) {
19 if (std::find(parents.begin(), parents.end(), i) == parents.end()) {
20 attributes.push_back(i);
21 }
22 }
23 // 1. Add edges from the class node to all other nodes
24 // 2. Add edges from the parents nodes to all other nodes
25 for (const auto& attribute : attributes) {
26 model.addEdge(className, features[attribute]);
27 for (const auto& root : parents) {
28
29 model.addEdge(features[root], features[attribute]);
30 }
31 }
32 }
33 std::vector<std::string> SPnDE::graph(const std::string& name) const
34 {
35 return model.graph(name);
36 }
37
38}
</html>