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-15 14:16:04 +00:00
|
|
|
#ifndef BOOSTAODE_H
|
|
|
|
#define BOOSTAODE_H
|
2023-10-11 09:33:29 +00:00
|
|
|
#include <map>
|
2024-03-08 21:20:54 +00:00
|
|
|
#include "bayesnet/classifiers/SPODE.h"
|
|
|
|
#include "bayesnet/feature_selection/FeatureSelect.h"
|
|
|
|
#include "Ensemble.h"
|
2023-08-15 14:16:04 +00:00
|
|
|
namespace bayesnet {
|
2024-04-02 07:52:40 +00:00
|
|
|
struct {
|
|
|
|
std::string CFS = "CFS";
|
|
|
|
std::string FCBF = "FCBF";
|
|
|
|
std::string IWSS = "IWSS";
|
|
|
|
}SelectFeatures;
|
|
|
|
struct {
|
|
|
|
std::string ASC = "asc";
|
|
|
|
std::string DESC = "desc";
|
|
|
|
std::string RAND = "rand";
|
|
|
|
}Orders;
|
2023-08-15 14:16:04 +00:00
|
|
|
class BoostAODE : public Ensemble {
|
|
|
|
public:
|
2024-03-11 23:26:28 +00:00
|
|
|
BoostAODE(bool predict_voting = false);
|
2023-11-18 10:56:10 +00:00
|
|
|
virtual ~BoostAODE() = default;
|
2023-11-08 17:45:35 +00:00
|
|
|
std::vector<std::string> graph(const std::string& title = "BoostAODE") const override;
|
2024-04-07 22:55:30 +00:00
|
|
|
void setHyperparameters(const nlohmann::json& hyperparameters_) override;
|
2023-08-20 15:57:38 +00:00
|
|
|
protected:
|
|
|
|
void buildModel(const torch::Tensor& weights) override;
|
|
|
|
void trainModel(const torch::Tensor& weights) override;
|
|
|
|
private:
|
2024-04-09 22:55:36 +00:00
|
|
|
std::tuple<torch::Tensor&, double, bool> update_weights_block(int k, torch::Tensor& ytrain, torch::Tensor& weights);
|
2024-03-20 22:33:02 +00:00
|
|
|
std::vector<int> initializeModels();
|
2023-09-06 08:51:07 +00:00
|
|
|
torch::Tensor X_train, y_train, X_test, y_test;
|
2023-10-10 09:52:39 +00:00
|
|
|
// Hyperparameters
|
2024-04-08 21:36:05 +00:00
|
|
|
bool bisection = true; // if true, use bisection stratety to add k models at once to the ensemble
|
|
|
|
int maxTolerance = 3;
|
2024-02-26 16:07:57 +00:00
|
|
|
std::string order_algorithm; // order to process the KBest features asc, desc, rand
|
2024-04-08 21:36:05 +00:00
|
|
|
bool convergence = true; //if true, stop when the model does not improve
|
2023-10-14 11:12:04 +00:00
|
|
|
bool selectFeatures = false; // if true, use feature selection
|
2024-04-02 07:52:40 +00:00
|
|
|
std::string select_features_algorithm = Orders.DESC; // Selected feature selection algorithm
|
2023-10-14 11:12:04 +00:00
|
|
|
FeatureSelect* featureSelector = nullptr;
|
|
|
|
double threshold = -1;
|
2024-04-09 22:55:36 +00:00
|
|
|
bool block_update = false;
|
2023-08-15 14:16:04 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|