Fix some small mistakes

This commit is contained in:
2023-07-13 17:11:08 +02:00
parent 99083ceede
commit d1cafc230b
5 changed files with 13 additions and 12 deletions

View File

@@ -8,7 +8,7 @@ namespace bayesnet {
BaseClassifier& BaseClassifier::build(vector<string>& features, string className, map<string, vector<int>>& states) BaseClassifier& BaseClassifier::build(vector<string>& features, string className, map<string, vector<int>>& states)
{ {
dataset = torch::cat({ X, y.view({150, 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;
this->states = states; this->states = states;
@@ -86,8 +86,8 @@ namespace bayesnet {
Tensor y_pred = predict(X); Tensor y_pred = predict(X);
return (y_pred == y).sum().item<float>() / y.size(0); return (y_pred == y).sum().item<float>() / y.size(0);
} }
void BaseClassifier::show() vector<string> BaseClassifier::show()
{ {
model.show(); return model.show();
} }
} }

View File

@@ -28,9 +28,8 @@ namespace bayesnet {
BaseClassifier& fit(vector<vector<int>>& X, vector<int>& y, vector<string>& features, string className, map<string, vector<int>>& states); BaseClassifier& fit(vector<vector<int>>& X, vector<int>& y, vector<string>& features, string className, map<string, vector<int>>& states);
Tensor predict(Tensor& X); Tensor predict(Tensor& X);
float score(Tensor& X, Tensor& y); float score(Tensor& X, Tensor& y);
void show(); vector<string> show();
}; };
} }
#endif #endif

View File

@@ -10,9 +10,9 @@ namespace bayesnet {
float theta; float theta;
void add_m_edges(int idx, vector<int>& S, Tensor& weights); void add_m_edges(int idx, vector<int>& S, Tensor& weights);
protected: protected:
void train(); void train() override;
public: public:
KDB(int k, float theta=0.03); KDB(int k, float theta = 0.03);
}; };
} }
#endif #endif

View File

@@ -245,16 +245,18 @@ namespace bayesnet {
} }
return result; return result;
} }
void Network::show() vector<string> Network::show()
{ {
vector<string> result;
// Draw the network // Draw the network
for (auto node : nodes) { for (auto node : nodes) {
cout << node.first << " -> "; string line = node.first + " -> ";
for (auto child : node.second->getChildren()) { for (auto child : node.second->getChildren()) {
cout << child->getName() << ", "; line += child->getName() + ", ";
} }
cout << endl; result.push_back(line);
} }
return result;
} }
} }

View File

@@ -44,7 +44,7 @@ namespace bayesnet {
torch::Tensor conditionalEdgeWeight(); torch::Tensor conditionalEdgeWeight();
vector<vector<double>> predict_proba(const vector<vector<int>>&); vector<vector<double>> predict_proba(const vector<vector<int>>&);
double score(const vector<vector<int>>&, const vector<int>&); double score(const vector<vector<int>>&, const vector<int>&);
void show(); vector<string> show();
inline string version() { return "0.1.0"; } inline string version() { return "0.1.0"; }
}; };
} }