Commit ccd16151 authored by Alessio Netti's avatar Alessio Netti
Browse files

Analytics: added "covs" Clustering plugin REST API action

- Allows to print the covariance matrices of the gaussian mixture model
parent fda96140
......@@ -885,6 +885,7 @@ However, it supports the following additional REST API actions:
|:----- |:----------- |
| train | Triggers a new training phase for the gaussian mixture model. At the next computation interval, the feature vectors of all units of the operator are combined to perform training, after which predicted labels are given as output.
| means | Returns the means of the generated gaussian components in the trained mixture model.
| covs | Returns the covariance matrices of the generated gaussian components in the trained mixture model.
## Tester Plugin <a name="testerPlugin"></a>
The _Tester_ plugin can be used to test the functionality and performance of the query engine, as well as of the Unit System. It will perform a specified number of queries over the set of input sensors for each unit, and then output as a sensor the total number of retrieved readings. The following are the configuration parameters for operators in the _Tester_ plugin:
......@@ -68,6 +68,8 @@ restResponse_t ClusteringOperator::REST(const string& action, const unordered_ma
this->_trainingPending = true;
} else if(action=="means") {
resp.response = printMeans();
} else if(action=="covs") {
resp.response = printCovs();
} else
throw invalid_argument("Unknown plugin action " + action + " requested!");
return resp;
......@@ -209,7 +211,20 @@ std::string ClusteringOperator::printMeans() {
out << "Model is uninitialized or not trained.\n";
else {
for(size_t idx=0; idx<(size_t)_gmm->getMeans().size().height; idx++)
out << "Component " << idx << " :" << _gmm->getMeans().row(idx) << "\n";
out << "Component " << idx << ":\n" << _gmm->getMeans().row(idx) << "\n";
return out.str();
std::string ClusteringOperator::printCovs() {
std::ostringstream out;
if(_gmm.empty() || !_gmm->isTrained())
out << "Model is uninitialized or not trained.\n";
else {
std::vector<cv::Mat> covs;
for(size_t idx=0; idx<(size_t)covs.size(); idx++)
out << "Component " << idx << ":\n" << covs[idx] << "\n";
return out.str();
......@@ -83,6 +83,7 @@ protected:
void computeFeatureVector(U_Ptr unit, uint64_t offset=0);
bool isOutlier(cv::Mat vec1, cv::Mat vec2, cv::Mat cov);
std::string printMeans();
std::string printCovs();
std::string _modelOut;
std::string _modelIn;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment