void Data::sampleRankedPairs( const std::string &rankedpairfile ) { cout << "Sampling ranked pairs." << endl; ofstream *outFile = new ofstream(); outFile->open( rankedpairfile.c_str() ); ostream *out = outFile; const unsigned int n_samplings = 5000; const unsigned int n_samples = 50; const float min_diff = 0.05; // loop over all sentences for(unsigned int S=0; S<featdata->size(); S++) { unsigned int n_translations = featdata->get(S).size(); // sample a fixed number of times vector< SampledPair* > samples; vector< float > scores; for(unsigned int i=0; i<n_samplings; i++) { unsigned int translation1 = rand() % n_translations; float bleu1 = sentenceLevelBleuPlusOne(scoredata->get(S,translation1)); unsigned int translation2 = rand() % n_translations; float bleu2 = sentenceLevelBleuPlusOne(scoredata->get(S,translation2)); if (abs(bleu1-bleu2) < min_diff) continue; samples.push_back( new SampledPair( translation1, translation2, bleu1-bleu2) ); scores.push_back( 1.0 - abs(bleu1-bleu2) ); } //cerr << "sampled " << samples.size() << " pairs\n"; float min_diff = -1.0; if (samples.size() > n_samples) { nth_element(scores.begin(), scores.begin()+(n_samples-1), scores.end()); min_diff = 0.99999-scores[n_samples-1]; //cerr << "min_diff = " << min_diff << endl; } unsigned int collected = 0; for(unsigned int i=0; i<samples.size() && collected < n_samples; i++) { if (samples[i]->getDiff() >= min_diff) { collected++; *out << "1"; outputSample( *out, featdata->get(S,samples[i]->getTranslation1()), featdata->get(S,samples[i]->getTranslation2()) ); *out << endl; *out << "0"; outputSample( *out, featdata->get(S,samples[i]->getTranslation2()), featdata->get(S,samples[i]->getTranslation1()) ); *out << endl; } delete samples[i]; } //cerr << "collected " << collected << endl; } out->flush(); outFile->close(); }
void hellDecoder::doDecode (DSPCOMPLEX z){ // as usual: first filter and shift z = bandpass -> Pass (z); z = z * localOscillator -> nextValue (hellIF); switch (hellMode) { case MODE_FSKHELL: case MODE_FSKH105: case MODE_HELL80: decodeFSK (z); break; default: decodeAM(z); break; } outputSample (real (z), imag (z)); }
void faxDecoder::doDecode (DSPCOMPLEX z) { int16_t sampleValue; // // for the sound: outputSample (real (z), imag (z)); // // When we are in autoContinue mode, we just wait at least for // 30 seconds after detecting the FAX_DONE before resetting if (faxState == FAX_DONE) { if (autoContinue && delayCounter ++ > theRate * 30) { reset (); // will a.o set the state delayCounter = 0; } else return; } z = z * localOscillator -> nextValue (carrier); z = faxLowPass -> Pass (z); sampleValue = myDemodulator -> demodulate (z); if (phaseInvers) sampleValue = 256 - sampleValue; if (faxColor == FAX_BLACKWHITE) sampleValue = isWhite (sampleValue) ? 255 : 0; fax_oldz = z; currentValue = sampleValue; // We count the number of times the decoded values // goes up from black to white. If in a period of half a second // (i.e. we had theRate / 2 samples), the number // of upCrossings is aptStartFreq / 2, we have a start // if the number is aptStopFreq and we are // not DONE or APT_START then we finish the transmission if (we_are_Black && realWhite (sampleValue)) { whiteSide = true; apt_upCrossings ++; } else if (whiteSide && realBlack (sampleValue)) whiteSide = false; // if we have samples for about half a second of samples, // check the frequency // to see whether we are ready for phasing or for exit if (++aptCount >= theRate / 2) { int16_t freq = 2 * apt_upCrossings; aptFreq -> display (freq); aptCount = 0; apt_upCrossings = 0; if ((faxState == APTSTART) && inRange (freq, aptStartFreq)) { faxState = FAX_PHASING; // carrier -= freq - aptStartFreq; initPhasing (); return; } if (((faxState & (FAX_PHASING | FAX_IMAGING)) != 0) && inRange (freq, aptStopFreq)) { rawData. resize (currentSampleIndex); faxState = FAX_DONE; showState -> setText (QString ("Done")); fax_displayImage (theImage -> getImage (), 0, faxColor == FAX_COLOR ? lastRow / 3 : lastRow); if (savingRequested || autoContinue) { fax_saveFile (theImage -> getImage (), autoContinue); set_savingRequested (false); } return; } // // otherwise: fall through } if (faxState == FAX_PHASING) addtoPhasing (sampleValue); if ((faxState == FAX_PHASING) || (faxState == FAX_IMAGING)) if (lpm > 0) // just a precaution addtoImage (sampleValue); }