BayesNet/bayesnet/classifiers/KDBLd.cc

35 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 "KDBLd.h"
2023-08-05 12:40:42 +00:00
namespace bayesnet {
KDBLd::KDBLd(int k) : KDB(k), Proposal(dataset, features, className) {}
2023-11-08 17:45:35 +00:00
KDBLd& KDBLd::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-08-05 12:40:42 +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_;
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-05 12:40:42 +00:00
// We have discretized the input data
// 1st we need to fit the model to build the normal KDB structure, KDB::fit initializes the base Bayesian network
KDB::fit(dataset, features, className, states);
states = localDiscretizationProposal(states, model);
2023-08-05 12:40:42 +00:00
return *this;
}
2023-11-08 17:45:35 +00:00
torch::Tensor KDBLd::predict(torch::Tensor& X)
2023-08-05 12:40:42 +00:00
{
auto Xt = prepareX(X);
return KDB::predict(Xt);
2023-08-05 12:40:42 +00:00
}
2023-11-08 17:45:35 +00:00
std::vector<std::string> KDBLd::graph(const std::string& name) const
2023-08-05 12:40:42 +00:00
{
return KDB::graph(name);
}
}