First compilation
This commit is contained in:
@@ -22,22 +22,21 @@ namespace platform {
|
|||||||
throw std::invalid_argument("Invalid hyperparameters" + hyperparameters.dump());
|
throw std::invalid_argument("Invalid hyperparameters" + hyperparameters.dump());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void XA1DE::fit(std::vector<std::vector<int>> X, std::vector<int> y, std::vector<double> weights)
|
XA1DE& XA1DE::fit(std::vector<std::vector<int>>& X, std::vector<int>& y, const std::vector<std::string>& features, const std::string& className, std::map<std::string, std::vector<int>>& states, const bayesnet::Smoothing_t smoothing)
|
||||||
{
|
{
|
||||||
Timer timer, timert;
|
Timer timer, timert;
|
||||||
timer.start();
|
timer.start();
|
||||||
timert.start();
|
timert.start();
|
||||||
weights_ = weights;
|
|
||||||
std::vector<std::vector<int>> instances = X;
|
std::vector<std::vector<int>> instances = X;
|
||||||
instances.push_back(y);
|
instances.push_back(y);
|
||||||
int num_instances = instances[0].size();
|
int num_instances = instances[0].size();
|
||||||
int num_attributes = instances.size();
|
int num_attributes = instances.size();
|
||||||
normalize_weights(num_instances);
|
normalize_weights(num_instances);
|
||||||
std::vector<int> states;
|
std::vector<int> statesv;
|
||||||
for (int i = 0; i < num_attributes; i++) {
|
for (int i = 0; i < num_attributes; i++) {
|
||||||
states.push_back(*max_element(instances[i].begin(), instances[i].end()) + 1);
|
statesv.push_back(*max_element(instances[i].begin(), instances[i].end()) + 1);
|
||||||
}
|
}
|
||||||
aode_.init(states);
|
aode_.init(statesv);
|
||||||
aode_.duration_first += timer.getDuration(); timer.start();
|
aode_.duration_first += timer.getDuration(); timer.start();
|
||||||
std::vector<int> instance;
|
std::vector<int> instance;
|
||||||
for (int n_instance = 0; n_instance < num_instances; n_instance++) {
|
for (int n_instance = 0; n_instance < num_instances; n_instance++) {
|
||||||
@@ -62,6 +61,7 @@ namespace platform {
|
|||||||
std::cout << "* Time to build the model: " << timert.getDuration() << " seconds" << std::endl;
|
std::cout << "* Time to build the model: " << timert.getDuration() << " seconds" << std::endl;
|
||||||
// exit(1);
|
// exit(1);
|
||||||
}
|
}
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
std::vector<std::vector<double>> XA1DE::predict_proba(std::vector<std::vector<int>>& test_data)
|
std::vector<std::vector<double>> XA1DE::predict_proba(std::vector<std::vector<int>>& test_data)
|
||||||
{
|
{
|
||||||
|
@@ -21,34 +21,34 @@ namespace platform {
|
|||||||
public:
|
public:
|
||||||
XA1DE();
|
XA1DE();
|
||||||
virtual ~XA1DE() = default;
|
virtual ~XA1DE() = default;
|
||||||
void setDebug(bool debug) { this->debug = debug; }
|
|
||||||
std::vector<std::vector<double>> predict_proba_threads(const std::vector<std::vector<int>>& test_data);
|
|
||||||
|
|
||||||
|
std::vector<std::vector<double>> predict_proba_threads(const std::vector<std::vector<int>>& test_data);
|
||||||
|
std::vector<std::vector<double>> predict_proba(std::vector<std::vector<int>>& X) override;
|
||||||
|
float score(std::vector<std::vector<int>>& X, std::vector<int>& y) override;
|
||||||
XA1DE& fit(std::vector<std::vector<int>>& X, std::vector<int>& y, const std::vector<std::string>& features, const std::string& className, std::map<std::string, std::vector<int>>& states, const bayesnet::Smoothing_t smoothing) override;
|
XA1DE& fit(std::vector<std::vector<int>>& X, std::vector<int>& y, const std::vector<std::string>& features, const std::string& className, std::map<std::string, std::vector<int>>& states, const bayesnet::Smoothing_t smoothing) override;
|
||||||
XA1DE& fit(torch::Tensor& X, torch::Tensor& y, const std::vector<std::string>& features, const std::string& className, std::map<std::string, std::vector<int>>& states, const bayesnet::Smoothing_t smoothing) override;
|
XA1DE& fit(torch::Tensor& X, torch::Tensor& y, const std::vector<std::string>& features, const std::string& className, std::map<std::string, std::vector<int>>& states, const bayesnet::Smoothing_t smoothing) override { return *this; };
|
||||||
XA1DE& fit(torch::Tensor& dataset, const std::vector<std::string>& features, const std::string& className, std::map<std::string, std::vector<int>>& states, const bayesnet::Smoothing_t smoothing) override;
|
XA1DE& fit(torch::Tensor& dataset, const std::vector<std::string>& features, const std::string& className, std::map<std::string, std::vector<int>>& states, const bayesnet::Smoothing_t smoothing) override { return *this; };
|
||||||
XA1DE& fit(torch::Tensor& dataset, const std::vector<std::string>& features, const std::string& className, std::map<std::string, std::vector<int>>& states, const torch::Tensor& weights, const bayesnet::Smoothing_t smoothing) override;
|
XA1DE& fit(torch::Tensor& dataset, const std::vector<std::string>& features, const std::string& className, std::map<std::string, std::vector<int>>& states, const torch::Tensor& weights, const bayesnet::Smoothing_t smoothing) override { return *this; };
|
||||||
|
torch::Tensor predict(torch::Tensor& X) override { return torch::zeros(0); };
|
||||||
|
std::vector<int> predict(std::vector<std::vector<int>>& X) override;
|
||||||
|
torch::Tensor predict_proba(torch::Tensor& X) override { return torch::zeros(0); };
|
||||||
|
|
||||||
int getNumberOfNodes() const override { return 0; };
|
int getNumberOfNodes() const override { return 0; };
|
||||||
int getNumberOfEdges() const override { return 0; };
|
int getNumberOfEdges() const override { return 0; };
|
||||||
int getNumberOfStates() const override { return 0; };
|
int getNumberOfStates() const override { return 0; };
|
||||||
int getClassNumStates() const override { return 0; };
|
int getClassNumStates() const override { return 0; };
|
||||||
torch::Tensor predict(torch::Tensor& X) override { return torch::zeros(0); };
|
|
||||||
std::vector<int> predict(std::vector<std::vector<int>>& X) override;
|
|
||||||
torch::Tensor predict_proba(torch::Tensor& X) override { return torch::zeros(0); };
|
|
||||||
std::vector<std::vector<double>> predict_proba(std::vector<std::vector<int>>& X) override;
|
|
||||||
bayesnet::status_t getStatus() const override { return status; }
|
bayesnet::status_t getStatus() const override { return status; }
|
||||||
std::string getVersion() override { return { project_version.begin(), project_version.end() }; };
|
std::string getVersion() override { return version; };
|
||||||
float score(torch::Tensor& X, torch::Tensor& y) override { return 0; };
|
float score(torch::Tensor& X, torch::Tensor& y) override { return 0; };
|
||||||
float score(std::vector<std::vector<int>>& X, std::vector<int>& y) override;
|
|
||||||
std::vector<std::string> show() const override { return {}; }
|
std::vector<std::string> show() const override { return {}; }
|
||||||
std::vector<std::string> topological_order() override { return {}; }
|
std::vector<std::string> topological_order() override { return {}; }
|
||||||
std::vector<std::string> getNotes() const override { return notes; }
|
std::vector<std::string> getNotes() const override { return notes; }
|
||||||
std::string dump_cpt() const override { return ""; }
|
std::string dump_cpt() const override { return ""; }
|
||||||
void setHyperparameters(const nlohmann::json& hyperparameters) override;
|
void setHyperparameters(const nlohmann::json& hyperparameters) override;
|
||||||
|
|
||||||
std::vector<std::string>& getValidHyperparameters() { return validHyperparameters; }
|
std::vector<std::string>& getValidHyperparameters() { return validHyperparameters; }
|
||||||
|
void setDebug(bool debug) { this->debug = debug; }
|
||||||
protected:
|
protected:
|
||||||
void trainModel(const torch::Tensor& weights, const bayesnet::Smoothing_t smoothing) override;
|
void trainModel(const torch::Tensor& weights, const bayesnet::Smoothing_t smoothing) override {};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline void normalize_weights(int num_instances)
|
inline void normalize_weights(int num_instances)
|
||||||
@@ -61,7 +61,6 @@ namespace platform {
|
|||||||
w = w * num_instances / sum;
|
w = w * num_instances / sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// The instances of the dataset
|
|
||||||
Xaode aode_;
|
Xaode aode_;
|
||||||
std::vector<double> weights_;
|
std::vector<double> weights_;
|
||||||
CountingSemaphore& semaphore_;
|
CountingSemaphore& semaphore_;
|
||||||
@@ -69,6 +68,7 @@ namespace platform {
|
|||||||
bayesnet::status_t status = bayesnet::NORMAL;
|
bayesnet::status_t status = bayesnet::NORMAL;
|
||||||
std::vector<std::string> notes;
|
std::vector<std::string> notes;
|
||||||
bool use_threads = false;
|
bool use_threads = false;
|
||||||
|
std::string version = "0.9.7";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // XA1DE_H
|
#endif // XA1DE_H
|
Reference in New Issue
Block a user