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