You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.6 KiB
C++

/*!
* \file TestResult.h
* \date 2019/11/27
*
* \author Lin, Chi
* Contact: lin.chi@hzleaper.com
*
*
* \note
*/
#ifndef __TestResult_h_
#define __TestResult_h_
#include "CVUtils.h"
#include "CyclopsLock.h"
#include "StdUtils.h"
struct TestResult
{
int id = -1;
int expected = -1; // expected result of this test
int result = -1; // predicted result of this test
int64 time = 0; // test execution time (tick)
bool isGood() const {
return expected == result;
}
};
class TestResults : public AsyncResult
{
public:
typedef std::shared_ptr<TestResults> Ptr;
TestResults(AsyncFunc func, int expectCount, int idCount)
: AsyncResult(func), mExpectCount(expectCount), mIDCount(idCount)
{}
virtual int count() {
CyclopsSharedLockGuard shared_gaurd(&mLock);
return mResults.size();
}
TestResult get(int idx) {
CyclopsSharedLockGuard shared_gaurd(&mLock);
if (idx < 0 || idx >= mResults.size()) return TestResult();
return mResults[idx];
}
virtual Mat getconfuseMat(int id);
virtual float getAccuracy(int id);
virtual float getAccuracy(int id, int expect);
virtual float getF1Score(int id, int expect);
virtual float getPrecision(int id, int expect);
virtual float getRecall(int id, int expect);
virtual float getSpecificity(int id, int expect);
virtual float getTestTime(int id);
protected:
friend class LLClassifier;
void setTotal(int num) {
CyclopsLockGuard write_gaurd(&mLock);
mTotal = num;
mResults.reserve(num);
}
virtual void setSucceed(int val);
void add(const TestResult& r) {
CyclopsLockGuard write_gaurd(&mLock);
mResults.push_back(r);
}
int getTP(const Mat& confuseMat, int expect); // true positive (same id as expect)
int getFP(const Mat& confuseMat, int expect); // false positive (different id as expect)
int getTN(const Mat& confuseMat, int expect); // true negative
int getFN(const Mat& confuseMat, int expect); // false negative
int getPExpectTotal(const Mat& confuseMat, int expect); // total number of expected positive
int getNExpectTotal(const Mat& confuseMat, int expect); // total number of expected negative
int getPResultTotal(const Mat& confuseMat, int expect); // total number of result positive
int getNResultTotal(const Mat& confuseMat, int expect); // total number of result negative
private:
int mIDCount; // total groups of test
int mExpectCount; // total number of different expected value
std::vector<TestResult> mResults; // actual finished results
std::map<int, Mat> mConfuseMats; // confuseion matrix, grouped by TestResult::id
std::map<int, float> mTestTimes; // average time per test, grouped by TestResult::id
};
#endif // TestResult_h_