Refactor constructor
This commit is contained in:
parent
a60b06e2f2
commit
5793c31bc4
@ -231,6 +231,7 @@ int main(int argc, char** argv)
|
||||
cout << "BayesNet version: " << network.version() << endl;
|
||||
unsigned int nthreads = std::thread::hardware_concurrency();
|
||||
cout << "Computer has " << nthreads << " cores." << endl;
|
||||
cout << "****************** First ******************" << endl;
|
||||
auto metrics = bayesnet::Metrics(network.getSamples(), features, className, network.getClassNumStates());
|
||||
cout << "conditionalEdgeWeight " << endl;
|
||||
auto conditional = metrics.conditionalEdgeWeights();
|
||||
@ -238,5 +239,13 @@ int main(int argc, char** argv)
|
||||
long m = features.size() + 1;
|
||||
auto matrix = torch::from_blob(conditional.data(), { m, m });
|
||||
cout << matrix << endl;
|
||||
cout << "****************** Second ******************" << endl;
|
||||
auto metrics2 = bayesnet::Metrics(Xd, y, features, className, network.getClassNumStates());
|
||||
cout << "conditionalEdgeWeight " << endl;
|
||||
auto conditional2 = metrics2.conditionalEdgeWeights();
|
||||
cout << conditional2 << endl;
|
||||
long m2 = features.size() + 1;
|
||||
auto matrix2 = torch::from_blob(conditional2.data(), { m, m });
|
||||
cout << matrix2 << endl;
|
||||
return 0;
|
||||
}
|
@ -1,30 +1,23 @@
|
||||
#include "Metrics.hpp"
|
||||
using namespace std;
|
||||
namespace bayesnet {
|
||||
vector<int> linearize(const vector<vector<int>>& vec_vec)
|
||||
{
|
||||
vector<int> vec;
|
||||
for (const auto& v : vec_vec) {
|
||||
for (auto d : v) {
|
||||
vec.push_back(d);
|
||||
}
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
Metrics::Metrics(torch::Tensor& samples, vector<string>& features, string& className, int classNumStates)
|
||||
: samples(samples)
|
||||
, features(features)
|
||||
, className(className)
|
||||
, classNumStates(classNumStates)
|
||||
{
|
||||
|
||||
}
|
||||
Metrics::Metrics(vector<vector<int>>& vsamples, int m, int n, vector<string>& features, string& className, int classNumStates)
|
||||
Metrics::Metrics(vector<vector<int>>& vsamples, vector<int>& labels, vector<string>& features, string& className, int classNumStates)
|
||||
: features(features)
|
||||
, className(className)
|
||||
, classNumStates(classNumStates)
|
||||
{
|
||||
samples = torch::from_blob(linearize(vsamples).data(), { m, n });
|
||||
samples = torch::zeros({ static_cast<int64_t>(vsamples[0].size()), static_cast<int64_t>(vsamples.size() + 1) }, torch::kInt64);
|
||||
for (int i = 0; i < vsamples.size(); ++i) {
|
||||
samples.index_put_({ "...", i }, torch::tensor(vsamples[i], torch::kInt64));
|
||||
}
|
||||
samples.index_put_({ "...", -1 }, torch::tensor(labels, torch::kInt64));
|
||||
}
|
||||
vector<pair<string, string>> Metrics::doCombinations(const vector<string>& source)
|
||||
{
|
||||
|
@ -17,7 +17,7 @@ namespace bayesnet {
|
||||
double mutualInformation(torch::Tensor&, torch::Tensor&);
|
||||
public:
|
||||
Metrics(torch::Tensor&, vector<string>&, string&, int);
|
||||
Metrics(vector<vector<int>>&, int, int, vector<string>&, string&, int);
|
||||
Metrics(vector<vector<int>>&, vector<int>&, vector<string>&, string&, int);
|
||||
vector<float> conditionalEdgeWeights();
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user