2024-04-11 16:02:49 +00:00
|
|
|
// ***************************************************************
|
|
|
|
// SPDX-FileCopyrightText: Copyright 2024 Ricardo Montañana Gómez
|
|
|
|
// SPDX-FileType: SOURCE
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
// ***************************************************************
|
|
|
|
|
2023-08-05 21:23:31 +00:00
|
|
|
#include "TANLd.h"
|
2023-07-31 17:53:55 +00:00
|
|
|
|
|
|
|
namespace bayesnet {
|
2023-08-07 10:49:37 +00:00
|
|
|
TANLd::TANLd() : TAN(), Proposal(dataset, features, className) {}
|
2024-06-11 09:40:45 +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_, const Smoothing_t smoothing)
|
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
|
2024-06-11 09:40:45 +00:00
|
|
|
TAN::fit(dataset, features, className, states, smoothing);
|
2023-08-12 14:16:17 +00:00
|
|
|
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)
|
2023-08-01 11:17:12 +00:00
|
|
|
{
|
2023-08-05 16:39:48 +00:00
|
|
|
auto Xt = prepareX(X);
|
|
|
|
return TAN::predict(Xt);
|
2023-08-01 11:17:12 +00:00
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
}
|