Fix some mistakes
This commit is contained in:
parent
099b4bea09
commit
4a54bd42a2
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@ -13,11 +13,9 @@
|
|||||||
"TAN",
|
"TAN",
|
||||||
"-p",
|
"-p",
|
||||||
"../../data/",
|
"../../data/",
|
||||||
"--stratified",
|
|
||||||
"--tensors"
|
"--tensors"
|
||||||
],
|
],
|
||||||
"cwd": "${workspaceFolder}/build/sample/",
|
"cwd": "${workspaceFolder}/build/sample/",
|
||||||
"preLaunchTask": "CMake: build"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "lldb",
|
"type": "lldb",
|
||||||
|
@ -228,8 +228,7 @@ int main(int argc, char** argv)
|
|||||||
total_score += score_test;
|
total_score += score_test;
|
||||||
cout << "Score Train: " << score_train << endl;
|
cout << "Score Train: " << score_train << endl;
|
||||||
cout << "Score Test : " << score_test << endl;
|
cout << "Score Test : " << score_test << endl;
|
||||||
// cout << "-------------------------------------------------------------------------------" << endl;
|
cout << "-------------------------------------------------------------------------------" << endl;
|
||||||
// total_score += score_value;
|
|
||||||
}
|
}
|
||||||
cout << "**********************************************************************************" << endl;
|
cout << "**********************************************************************************" << endl;
|
||||||
cout << "Average Score Train: " << total_score_train / nFolds << endl;
|
cout << "Average Score Train: " << total_score_train / nFolds << endl;
|
||||||
|
@ -7,6 +7,11 @@ namespace bayesnet {
|
|||||||
Classifier::Classifier(Network model) : model(model), m(0), n(0), metrics(Metrics()), fitted(false) {}
|
Classifier::Classifier(Network model) : model(model), m(0), n(0), metrics(Metrics()), fitted(false) {}
|
||||||
Classifier& Classifier::build(vector<string>& features, string className, map<string, vector<int>>& states)
|
Classifier& Classifier::build(vector<string>& features, string className, map<string, vector<int>>& states)
|
||||||
{
|
{
|
||||||
|
cout << "Building classifier..." << endl;
|
||||||
|
cout << "X sizes = " << X.sizes() << endl;
|
||||||
|
cout << "y sizes = " << y.sizes() << endl;
|
||||||
|
cout << "Xv size = " << Xv.size() << endl;
|
||||||
|
cout << "yv size = " << yv.size() << endl;
|
||||||
dataset = torch::cat({ X, y.view({y.size(0), 1}) }, 1);
|
dataset = torch::cat({ X, y.view({y.size(0), 1}) }, 1);
|
||||||
this->features = features;
|
this->features = features;
|
||||||
this->className = className;
|
this->className = className;
|
||||||
@ -28,6 +33,10 @@ namespace bayesnet {
|
|||||||
this->X = torch::transpose(X, 0, 1);
|
this->X = torch::transpose(X, 0, 1);
|
||||||
this->y = y;
|
this->y = y;
|
||||||
Xv = vector<vector<int>>();
|
Xv = vector<vector<int>>();
|
||||||
|
for (int i = 0; i < X.size(1); ++i) {
|
||||||
|
auto temp = X.index({ "...", i });
|
||||||
|
Xv.push_back(vector<int>(temp.data_ptr<int>(), temp.data_ptr<int>() + temp.numel()));
|
||||||
|
}
|
||||||
yv = vector<int>(y.data_ptr<int>(), y.data_ptr<int>() + y.size(0));
|
yv = vector<int>(y.data_ptr<int>(), y.data_ptr<int>() + y.size(0));
|
||||||
return build(features, className, states);
|
return build(features, className, states);
|
||||||
}
|
}
|
||||||
@ -71,10 +80,11 @@ namespace bayesnet {
|
|||||||
}
|
}
|
||||||
auto m_ = X.size(0);
|
auto m_ = X.size(0);
|
||||||
auto n_ = X.size(1);
|
auto n_ = X.size(1);
|
||||||
|
//auto Xt = torch::transpose(X, 0, 1);
|
||||||
vector<vector<int>> Xd(n_, vector<int>(m_, 0));
|
vector<vector<int>> Xd(n_, vector<int>(m_, 0));
|
||||||
for (auto i = 0; i < n_; i++) {
|
for (auto i = 0; i < n_; i++) {
|
||||||
auto temp = X.index({ "...", i });
|
auto temp = X.index({ "...", i });
|
||||||
Xd[i] = vector<int>(temp.data_ptr<int>(), temp.data_ptr<int>() + m_);
|
Xd[i] = vector<int>(temp.data_ptr<int>(), temp.data_ptr<int>() + temp.numel());
|
||||||
}
|
}
|
||||||
auto yp = model.predict(Xd);
|
auto yp = model.predict(Xd);
|
||||||
auto ypred = torch::tensor(yp, torch::kInt32);
|
auto ypred = torch::tensor(yp, torch::kInt32);
|
||||||
|
@ -145,7 +145,6 @@ int main(int argc, char** argv)
|
|||||||
fold = new StratifiedKFold(n_folds, y, -1);
|
fold = new StratifiedKFold(n_folds, y, -1);
|
||||||
else
|
else
|
||||||
fold = new KFold(n_folds, y.numel(), -1);
|
fold = new KFold(n_folds, y.numel(), -1);
|
||||||
|
|
||||||
auto experiment = Experiment();
|
auto experiment = Experiment();
|
||||||
experiment.setDiscretized(discretize_dataset).setModel(model_name).setPlatform("cpp");
|
experiment.setDiscretized(discretize_dataset).setModel(model_name).setPlatform("cpp");
|
||||||
experiment.setStratified(stratified).setNFolds(5).addRandomSeed(271).setScoreName("accuracy");
|
experiment.setStratified(stratified).setNFolds(5).addRandomSeed(271).setScoreName("accuracy");
|
||||||
|
@ -48,7 +48,6 @@ void StratifiedKFold::build()
|
|||||||
{
|
{
|
||||||
stratified_indices = vector<vector<int>>(k);
|
stratified_indices = vector<vector<int>>(k);
|
||||||
int fold_size = n / k;
|
int fold_size = n / k;
|
||||||
int remainder = n % k;
|
|
||||||
// Compute class counts and indices
|
// Compute class counts and indices
|
||||||
auto class_indices = map<int, vector<int>>();
|
auto class_indices = map<int, vector<int>>();
|
||||||
vector<int> class_counts(*max_element(y.begin(), y.end()) + 1, 0);
|
vector<int> class_counts(*max_element(y.begin(), y.end()) + 1, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user