diff --git a/src/BayesNet/Classifier.cc b/src/BayesNet/Classifier.cc index d77c2c8..545525e 100644 --- a/src/BayesNet/Classifier.cc +++ b/src/BayesNet/Classifier.cc @@ -125,7 +125,6 @@ namespace bayesnet { } void Classifier::addNodes() { - auto test = model.getEdges(); // Add all nodes to the network for (auto feature : features) { model.addNode(feature, states[feature].size()); diff --git a/src/BayesNet/Ensemble.cc b/src/BayesNet/Ensemble.cc index 8aa2518..dce0d3d 100644 --- a/src/BayesNet/Ensemble.cc +++ b/src/BayesNet/Ensemble.cc @@ -148,10 +148,10 @@ namespace bayesnet { } int Ensemble::getNumberOfStates() { - int states = 0; + int nstates = 0; for (auto i = 0; i < n_models; ++i) { - states += models[i]->getNumberOfStates(); + nstates += models[i]->getNumberOfStates(); } - return states; + return nstates; } } \ No newline at end of file diff --git a/src/BayesNet/Mst.cc b/src/BayesNet/Mst.cc index 5e94dc3..3a48d05 100644 --- a/src/BayesNet/Mst.cc +++ b/src/BayesNet/Mst.cc @@ -7,9 +7,8 @@ namespace bayesnet { using namespace std; - Graph::Graph(int V) : V(V) + Graph::Graph(int V) : V(V), parent(vector(V)) { - parent = vector(V); for (int i = 0; i < V; i++) parent[i] = i; G.clear(); diff --git a/src/BayesNet/Network.cc b/src/BayesNet/Network.cc index 1c8abeb..35b3cc5 100644 --- a/src/BayesNet/Network.cc +++ b/src/BayesNet/Network.cc @@ -8,7 +8,7 @@ namespace bayesnet { Network::Network(float maxT, int smoothing) : laplaceSmoothing(smoothing), features(vector()), className(""), classNumStates(0), maxThreads(maxT), fitted(false) {} Network::Network(Network& other) : laplaceSmoothing(other.laplaceSmoothing), features(other.features), className(other.className), classNumStates(other.getClassNumStates()), maxThreads(other.getmaxThreads()), fitted(other.fitted) { - for (auto& pair : other.nodes) { + for (const auto& pair : other.nodes) { nodes[pair.first] = std::make_unique(*pair.second); } } @@ -145,9 +145,6 @@ namespace bayesnet { while (nextNodeIndex < nodes.size()) { unique_lock lock(mtx); cv.wait(lock, [&activeThreads, &maxThreadsRunning]() { return activeThreads < maxThreadsRunning; }); - if (nextNodeIndex >= nodes.size()) { - break; // No more work remaining - } threads.emplace_back([this, &nextNodeIndex, &mtx, &cv, &activeThreads]() { while (true) { unique_lock lock(mtx); @@ -262,9 +259,7 @@ namespace bayesnet { // Normalize result double sum = accumulate(result.begin(), result.end(), 0.0); - for (double& value : result) { - value /= sum; - } + transform(result.begin(), result.end(), result.begin(), [sum](double& value) { return value / sum; }); return result; } vector Network::show()