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 "TANLd.h"
8 :
9 : namespace bayesnet {
10 34 : TANLd::TANLd() : TAN(), Proposal(dataset, features, className) {}
11 10 : TANLd& TANLd::fit(torch::Tensor& X_, torch::Tensor& y_, const std::vector<std::string>& features_, const std::string& className_, map<std::string, std::vector<int>>& states_)
12 : {
13 10 : checkInput(X_, y_);
14 10 : features = features_;
15 10 : className = className_;
16 10 : Xf = X_;
17 10 : y = y_;
18 : // Fills std::vectors Xv & yv with the data from tensors X_ (discretized) & y
19 10 : states = fit_local_discretization(y);
20 : // We have discretized the input data
21 : // 1st we need to fit the model to build the normal TAN structure, TAN::fit initializes the base Bayesian network
22 10 : TAN::fit(dataset, features, className, states);
23 10 : states = localDiscretizationProposal(states, model);
24 10 : return *this;
25 :
26 : }
27 8 : torch::Tensor TANLd::predict(torch::Tensor& X)
28 : {
29 8 : auto Xt = prepareX(X);
30 16 : return TAN::predict(Xt);
31 8 : }
32 2 : std::vector<std::string> TANLd::graph(const std::string& name) const
33 : {
34 2 : return TAN::graph(name);
35 : }
36 : }
|