예제 #1
0
/// Return a map containing all metrics.
StringMapDouble CoverMetrics::all() const {
    StringMapDouble m;
    m["tp"] = tp();
    m["fp"] = fp();
    m["tn"] = tn();
    m["fn"] = fn();
    m["precision"]   = precision();
    m["recall"]      = recall();
    m["f1score"]     = f1score();
    m["accuracy"]    = accuracy();
    m["fprate"]      = fprate();
    m["specificity"] = specificity();
    m["fnrate"]      = fnrate();
    m["matthews"]    = matthews();
    return m;
}
예제 #2
0
void ViBenchMarker3::process2()
{
	int time = mTime.elapsed();
	QObject::disconnect(mCurrentObject.data(), SIGNAL(noiseGenerated()), this, SLOT(process2()));

	/*QObject::connect(mCurrentObject.data(), SIGNAL(encoded()), this, SLOT(quit()));
	mCurrentObject->encode(ViAudio::Noise);
	return;*/

	qreal maxMAT = 0;
	qint64 maxTP = 0, maxTN = 0, maxFP = 0, maxFN = 0;
	qint64 i, lengthIndex, offset1 = 0, offset2 = 0;
	int noChange = 0;

	ViAudioReadData corrupted(mCurrentObject->buffer(ViAudio::Noise));
	ViAudioReadData realMask(mCurrentObject->buffer(ViAudio::CustomMask));
	ViAudioReadData length(mCurrentObject->buffer(ViAudio::Custom));
	corrupted.setSampleCount(WINDOW_SIZE);
	realMask.setSampleCount(WINDOW_SIZE);
	length.setSampleCount(WINDOW_SIZE);

	ViSampleChunk *nData1 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nData2 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nMask1 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nMask2 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nRealMask1 = new ViSampleChunk(realMask.bufferSamples() / 2);
	ViSampleChunk *nRealMask2 = new ViSampleChunk(realMask.bufferSamples() / 2);
	ViSampleChunk *nLength1 = new ViSampleChunk(corrupted.bufferSamples() / 2);
	ViSampleChunk *nLength2 = new ViSampleChunk(corrupted.bufferSamples() / 2);

	while(corrupted.hasData() && realMask.hasData())
	{
		corrupted.read();
		ViSampleChunk &corrupted1 = corrupted.splitSamples(0);
		ViSampleChunk &corrupted2 = corrupted.splitSamples(1);

		realMask.read();
		ViSampleChunk &realMask1 = realMask.splitSamples(0);
		ViSampleChunk &realMask2 = realMask.splitSamples(1);

		length.read();
		ViSampleChunk &length1 = length.splitSamples(0);
		ViSampleChunk &length2 = length.splitSamples(1);

		for(i = 0; i < corrupted1.size(); ++i)
		{
			(*nData1)[i + offset1] = corrupted1[i];
			(*nRealMask1)[i + offset1] = realMask1[i];
			(*nLength1)[i + offset1] = length1[i];
		}
		offset1 += corrupted1.size();
		for(i = 0; i < corrupted2.size(); ++i)
		{
			(*nData2)[i + offset2] = corrupted2[i];
			(*nRealMask2)[i + offset2] = realMask2[i];
			(*nLength2)[i + offset2] = length2[i];
		}
		offset2 += corrupted2.size();
	}

	mCurrentObject->clearBuffer(ViAudio::Target);
	mCurrentObject->clearBuffer(ViAudio::Noise);
	mCurrentObject->clearBuffer(ViAudio::NoiseMask);

	ViNoise noise1(nData1, nMask1, mCurrentThreshold);
	ViNoise noise2(nData2, nMask2, mCurrentThreshold);

	QVector<qreal> lengthTP(ViNoiseCreator::noiseSizeCount());
	QVector<qreal> lengthFN(ViNoiseCreator::noiseSizeCount());
	lengthTP.fill(0);
	lengthFN.fill(0);
	QVector<qreal> maxLengthTP, maxLengthFN;

	for(mCurrentThreshold = MASK_START; mCurrentThreshold <= MASK_END; mCurrentThreshold += MASK_INTERVAL)
	{
		noise1.setThreshold(mCurrentThreshold);
		noise1.generateMask(ViNoise::NOISE_TYPE);
		noise2.setThreshold(mCurrentThreshold);
		noise2.generateMask(ViNoise::NOISE_TYPE);

		qint64 truePositives = 0, falsePositives = 0, trueNegatives = 0, falseNegatives = 0;

		for(i = 0; i < nRealMask1->size(); ++i)
		{
			if((*nRealMask1)[i] == 1)
			{
				lengthIndex = ViNoiseCreator::fromSizeMask((*nLength1)[i]) - 1;
				if((*nMask1)[i] == 1)
				{
					++truePositives;
					lengthTP[lengthIndex] += 1;
				}
				else
				{
					++falseNegatives;
					lengthFN[lengthIndex] += 1;
				}
			}
			else if((*nRealMask1)[i] == 0)
			{
				if((*nMask1)[i] == 1) ++falsePositives;
				else ++trueNegatives;
			}
		}

		for(i = 0; i < nRealMask2->size(); ++i)
		{
			if((*nRealMask2)[i] == 1)
			{
				lengthIndex = ViNoiseCreator::fromSizeMask((*nLength2)[i]) - 1;
				if((*nMask2)[i] == 1)
				{
					++truePositives;
					lengthTP[lengthIndex] += 1;
				}
				else
				{
					++falseNegatives;
					lengthFN[lengthIndex] += 1;
				}
			}
			else if((*nRealMask2)[i] == 0)
			{
				if((*nMask2)[i] == 1) ++falsePositives;
				else ++trueNegatives;
			}
		}

		qreal math = matthews(truePositives, trueNegatives, falsePositives, falseNegatives);
		if(math > maxMAT)
		{
			maxMAT = math;
			maxTP = truePositives;
			maxTN = trueNegatives;
			maxFP = falsePositives;
			maxFN = falseNegatives;
			maxLengthTP = lengthTP;
			maxLengthFN = lengthFN;
			noChange = 0;
		}
		++noChange;
		if(noChange > NO_CHANGE) break;
	}

	delete nRealMask1;
	delete nRealMask2;
	delete nLength1;
	delete nLength2;

	++mDoneParamIterations;
	if(maxMAT > mBestMatthews) mBestMatthews = maxMAT;
	printFileData(time, maxTP, maxTN, maxFP, maxFN, maxLengthTP, maxLengthFN);
	printTerminal(time, maxTP, maxTN, maxFP, maxFN, mBestMatthews);

	if(nextParam()) process1(false);
	else nextFile();
}