BayesNet/bayesnet/classifiers/TANLd.cc

36 lines
1.3 KiB
C++
Raw Normal View History

2024-04-11 16:02:49 +00:00
// ***************************************************************
// SPDX-FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
// SPDX-FileType: SOURCE
// SPDX-License-Identifier: MIT
// ***************************************************************
#include "TANLd.h"
2023-07-31 17:53:55 +00:00
namespace bayesnet {
TANLd::TANLd() : TAN(), Proposal(dataset, features, className) {}
2023-11-08 17:45:35 +00:00
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_)
2023-07-31 17:53:55 +00:00
{
2023-08-24 10:09:35 +00:00
checkInput(X_, y_);
2023-08-05 12:40:42 +00:00
features = features_;
className = className_;
2023-08-03 23:35:45 +00:00
Xf = X_;
y = y_;
2023-11-08 17:45:35 +00:00
// Fills std::vectors Xv & yv with the data from tensors X_ (discretized) & y
2023-08-12 09:49:18 +00:00
states = fit_local_discretization(y);
2023-08-04 17:42:18 +00:00
// We have discretized the input data
// 1st we need to fit the model to build the normal TAN structure, TAN::fit initializes the base Bayesian network
TAN::fit(dataset, features, className, states);
states = localDiscretizationProposal(states, model);
2023-07-31 17:53:55 +00:00
return *this;
2023-08-07 23:53:41 +00:00
2023-07-31 17:53:55 +00:00
}
2023-11-08 17:45:35 +00:00
torch::Tensor TANLd::predict(torch::Tensor& X)
{
auto Xt = prepareX(X);
return TAN::predict(Xt);
}
2023-11-08 17:45:35 +00:00
std::vector<std::string> TANLd::graph(const std::string& name) const
2023-07-31 17:53:55 +00:00
{
return TAN::graph(name);
}
}