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 "AODELd.h"
8 :
9 : namespace bayesnet {
10 17 : AODELd::AODELd(bool predict_voting) : Ensemble(predict_voting), Proposal(dataset, features, className)
11 : {
12 17 : }
13 5 : AODELd& AODELd::fit(torch::Tensor& X_, torch::Tensor& y_, const std::vector<std::string>& features_, const std::string& className_, map<std::string, std::vector<int>>& states_)
14 : {
15 5 : checkInput(X_, y_);
16 5 : features = features_;
17 5 : className = className_;
18 5 : Xf = X_;
19 5 : y = y_;
20 : // Fills std::vectors Xv & yv with the data from tensors X_ (discretized) & y
21 5 : states = fit_local_discretization(y);
22 : // We have discretized the input data
23 : // 1st we need to fit the model to build the normal TAN structure, TAN::fit initializes the base Bayesian network
24 5 : Ensemble::fit(dataset, features, className, states);
25 5 : return *this;
26 :
27 : }
28 5 : void AODELd::buildModel(const torch::Tensor& weights)
29 : {
30 5 : models.clear();
31 42 : for (int i = 0; i < features.size(); ++i) {
32 37 : models.push_back(std::make_unique<SPODELd>(i));
33 : }
34 5 : n_models = models.size();
35 5 : significanceModels = std::vector<double>(n_models, 1.0);
36 5 : }
37 5 : void AODELd::trainModel(const torch::Tensor& weights)
38 : {
39 42 : for (const auto& model : models) {
40 37 : model->fit(Xf, y, features, className, states);
41 : }
42 5 : }
43 1 : std::vector<std::string> AODELd::graph(const std::string& name) const
44 : {
45 1 : return Ensemble::graph(name);
46 : }
47 : }
|