bool PrintFileList() { TCHAR cDIR[MAX_STR_LEN]; WIN32_FIND_DATA FindFileData; HANDLE hFind = INVALID_HANDLE_VALUE; TCHAR DirSpec[MAX_PATH]; GetCurrentDirectory(MAX_STR_LEN, cDIR); _stprintf(DirSpec, _T("%s%s"), cDIR, _T("\\*")); hFind = FindFirstFile(DirSpec, &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { _tprintf(_T("Invalid file handle \n")); return false; } printFileData(FindFileData); while (FindNextFile(hFind, &FindFileData) != 0) { printFileData(FindFileData); } FindClose(hFind); return true; }
void ViNoiseBatcher::process() { QObject::disconnect(mCurrentObject.data(), SIGNAL(decoded()), this, SLOT(process())); qint64 time; ViNoiseCreator creator; creator.createNoise(mCurrentObject->buffer(ViAudio::Target), mCurrentObject->buffer(ViAudio::Corrupted), mCurrentObject->buffer(ViAudio::CustomMask), mCurrentObject->buffer(ViAudio::Custom)); mCurrentObject->clearBuffer(ViAudio::Target); mCurrentObject->clearBuffer(ViAudio::CustomMask); ViClassificationErrorCollection errors; //do //{ mCurrentObject->clearBuffer(ViAudio::Noise); for(int i = 0; i < mParamsStart.size(); ++i) mDetector->setParameter(mParamsNames[i], mParamsCurrent[i]); if(mDetector->validParameters()) { mTime.restart(); mDetector->detect(mCurrentObject->buffer(ViAudio::Corrupted), mCurrentObject->buffer(ViAudio::Noise)); time = mTime.elapsed(); errors = mDetector->error(mCurrentObject->buffer(ViAudio::Noise), mCurrentObject->buffer(ViAudio::Custom), mThreshold); // Write /* QObject::connect(mCurrentObject.data(), SIGNAL(encoded()), this, SLOT(quit())); mCurrentObject->encode(ViAudio::Noise); return;*/ /*calculateThreshold(mCurrentObject->buffer(ViAudio::Noise), mCurrentObject->buffer(ViAudio::Custom), bestThreshold, bestErrors, bestMatthews, maxNoise); if(bestMatthews > maxMatthews) maxMatthews = bestMatthews; clearProgress();*/ // Write /*mDetector->mask(mCurrentObject->buffer(ViAudio::Noise), mCurrentObject->buffer(ViAudio::NoiseMask), 0.15, 8); QObject::connect(mCurrentObject.data(), SIGNAL(encoded()), this, SLOT(quit())); mCurrentObject->encode(ViAudio::NoiseMask); return;*/ } else { time = 0; } ++mDoneParamIterations; printFileData(errors, time); printTerminal(errors, time); //} //while(nextParam()); nextFile(); }
void ViStatistician::process() { QObject::disconnect(mCurrentObject.data(), SIGNAL(decoded()), this, SLOT(process())); ViAudioReadData data(mCurrentObject->buffer(ViAudio::Target)); data.setSampleCount(mWindowSize); qreal value = 0; qint64 count = 0; qreal top = 0, bottom1 = 0, bottom2 = 0; qreal valuePos = 0, valueNeg = 0; int countPos = 0, countNeg = 0; while(data.hasData()) { data.read(); ViSampleChunk &samples1 = data.splitSamples(0); ViSampleChunk &samples2 = data.splitSamples(1); if(mMode == Mean) { value += mean(samples1); value += mean(samples2); count += 2; } else if(mMode == StandardDeviation) { value += standardDeviation(samples1); value +standardDeviation(samples2); count += 2; } else if(mMode == Pearson) { qreal theTopA = 0, theBottom1A = 0, theBottom2A = 0; qreal theTopB = 0, theBottom1B = 0, theBottom2B = 0; qreal value1 = pearson(samples1, theTopA, theBottom1A, theBottom2A); qreal value2 = pearson(samples2, theTopB, theBottom1B, theBottom2B); /*if(value1 != 0) { top += theTopA; bottom1 += theBottom1A; bottom2 += theBottom2A; } if(value2 != 0) { top += theTopB; bottom1 += theBottom1B; bottom2 += theBottom2B; }*/ if(value1 > 0) { valuePos += value1; ++countPos; } else if(value1 < 0) { valueNeg += value1; ++countNeg; } if(value2 > 0) { valuePos += value2; ++countPos; } else if(value2 < 0) { valueNeg += value2; ++countNeg; } } } if(mMode == Pearson) { /*value = top / (qSqrt(bottom1) * qSqrt(bottom2)); mValue += value; mCount += 1; printFileData(value); printTerminal(value);*/ mValuePos += valuePos; mCountPos += countPos; mValueNeg += valueNeg; mCountNeg += countNeg; valuePos /= countPos; valueNeg /= countNeg; printFileDataPearson(valuePos, valueNeg); printTerminalPearson(valuePos, valueNeg); } else { mValue += value; mCount += count; value /= count; printFileData(value); printTerminal(value); } nextFile(); }
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(); }