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 "SPODE.h"
8 :
9 : namespace bayesnet {
10 :
11 2962 : SPODE::SPODE(int root) : Classifier(Network()), root(root) {}
12 :
13 2665 : void SPODE::buildModel(const torch::Tensor& weights)
14 : {
15 : // 0. Add all nodes to the model
16 2665 : addNodes();
17 : // 1. Add edges from the class node to all other nodes
18 : // 2. Add edges from the root node to all other nodes
19 113941 : for (int i = 0; i < static_cast<int>(features.size()); ++i) {
20 111276 : model.addEdge(className, features[i]);
21 111276 : if (i != root) {
22 108611 : model.addEdge(features[root], features[i]);
23 : }
24 : }
25 2665 : }
26 187 : std::vector<std::string> SPODE::graph(const std::string& name) const
27 : {
28 187 : return model.graph(name);
29 : }
30 :
31 : }
|