void Timing::print(std::ostream & out) { map_t & tagMap = instance().m_tagMap; //list_t & timers = instance().m_timers; out << "SM Timing\n"; out << "-----------\n"; map_t::iterator t = tagMap.begin(); for( ; t != tagMap.end(); t++) { size_t i = t->second; out.width((std::streamsize)instance().m_maxTagLength); out.setf(std::ios::left,std::ios::adjustfield); out << t->first << "\t"; out.width(7); out.setf(std::ios::right,std::ios::adjustfield); out << getNumSamples(i) << "\t"; if(getNumSamples(i) > 0) { out << secondsToTimeString(getTotalSeconds(i)) << "\t"; double meansec = getMeanSeconds(i); double stddev = sqrt(getVarianceSeconds(i)); out << "(" << secondsToTimeString(meansec) << " +- "; out << secondsToTimeString(stddev) << ")\t"; double minsec = getMinSeconds(i); double maxsec = getMaxSeconds(i); // The min or max are out of bounds. out << "[" << secondsToTimeString(minsec) << "," << secondsToTimeString(maxsec) << "]"; } out << std::endl; } }
SVMProblem(WindowFile &trainA, WindowFile &trainB) { l = countWins(trainA) + countWins(trainB); const qint32 samples = getNumSamples(trainA); assert(getNumSamples(trainB) == samples); y = new double[l]; x = new svm_node*[l]; x[0] = new svm_node[l*(samples+1)]; for(int i = 1; i < l; i++) { x[i] = &x[i-1][samples+1]; } float *buf = new float[samples]; int cur = 0; while(trainA.nextChannel()) { assert(trainA.getEventSamples() == samples); trainA.read((char*)buf, samples*sizeof(float)); fillNodes(x[cur], buf, samples); y[cur++] = 1.; } while(trainB.nextChannel()) { assert(trainB.getEventSamples() == samples); trainB.read((char*)buf, samples*sizeof(float)); fillNodes(x[cur], buf, samples); y[cur++] = -1.; } delete[] buf; assert(cur == l); }
void Jansen::sample() { int k = m_InputData->getNumCols(); /* number of input factors */ int N = getNumSamples(); /* total number of samples to be generated */ /* Generates the first sample */ double* curRow = m_InputData->getRow(0); m_RNG.rand(curRow, k); /* starts with the second column in winding stars design. * NOTE:the number of input factors must be greater than one * */ int col = 1; for (int iSample=1; iSample<N; ++iSample) { /* Copies the previous row */ m_InputData->fillRow(iSample, curRow); /* Moves to the next row */ curRow = m_InputData->getRow(iSample); /* Alters the value of 'col' column of the current row */ curRow[col] = m_RNG.rand(); /* Moves 'col' to the next column */ col++; /* If 'col' passes the last column, go back to the first column */ if (col >=k) col = 0; } /* Convert samples from the (0,1) uniform distribution to their target distributions */ m_RNG.convert(*m_InputData, m_InputList); }
ClassificationData ClassificationData::getTrainingFoldData(const UINT foldIndex) const{ ClassificationData trainingData; trainingData.setNumDimensions( numDimensions ); trainingData.setAllowNullGestureClass( allowNullGestureClass ); if( !crossValidationSetup ){ errorLog << "getTrainingFoldData(const UINT foldIndex) - Cross Validation has not been setup! You need to call the spiltDataIntoKFolds(UINT K,bool useStratifiedSampling) function first before calling this function!" << endl; return trainingData; } if( foldIndex >= kFoldValue ) return trainingData; //Add the class labels to make sure they all exist for(UINT k=0; k<getNumSamples(); k++){ trainingData.addClass( classTracker[k].classLabel, classTracker[k].className ); } //Add the data to the training set, this will consist of all the data that is NOT in the foldIndex UINT index = 0; for(UINT k=0; k<kFoldValue; k++){ if( k != foldIndex ){ for(UINT i=0; i<crossValidationIndexs[k].size(); i++){ index = crossValidationIndexs[k][i]; trainingData.addSample( data[ index ].getClassLabel(), data[ index ].getSample() ); } } } //Sort the class labels trainingData.sortClassLabels(); return trainingData; }
/* * Get table of samples x-values, * i.e. table[i][j] is the value of variable i at sample j */ std::vector< std::vector<double> > DataTable::getTableX() const { gridCompleteGuard(); // Initialize table std::vector<std::vector<double>> table; for (unsigned int i = 0; i < numVariables; i++) { std::vector<double> xi(getNumSamples(), 0.0); table.push_back(xi); } // Fill table with values int i = 0; for (auto &sample : samples) { std::vector<double> x = sample.getX(); for (unsigned int j = 0; j < numVariables; j++) { table.at(j).at(i) = x.at(j); } i++; } return table; }
ClassificationData ClassificationData::getTestFoldData(const UINT foldIndex) const{ ClassificationData testData; testData.setNumDimensions( numDimensions ); testData.setAllowNullGestureClass( allowNullGestureClass ); if( !crossValidationSetup ) return testData; if( foldIndex >= kFoldValue ) return testData; //Add the class labels to make sure they all exist for(UINT k=0; k<getNumSamples(); k++){ testData.addClass( classTracker[k].classLabel, classTracker[k].className ); } testData.reserve( (UINT)crossValidationIndexs[ foldIndex ].size() ); //Add the data to the test fold UINT index = 0; for(UINT i=0; i<crossValidationIndexs[ foldIndex ].size(); i++){ index = crossValidationIndexs[ foldIndex ][i]; testData.addSample( data[ index ].getClassLabel(), data[ index ].getSample() ); } //Sort the class labels testData.sortClassLabels(); return testData; }
static void cmd_test_list(svm_model *model, WindowFile &testFile) { const QString fmt("%1: prob { %2 , %3 } @ %4 ch %5\n"); const qint32 samples = getNumSamples(testFile); float *buf = new float[samples]; SVMNodeList nodelist(samples); double probEstim[2]; while(testFile.nextChannel()) { assert(testFile.getEventSamples() == samples); testFile.read((char*)buf, samples*sizeof(float)); nodelist.fill(buf); const char subj = (svm_predict_probability(model, nodelist, probEstim) > 0) ? 'A' : 'B'; const double t = (testFile.getEventOffset() / BytesPerSample)/ (double)SamplingRate; fputs(fmt.arg(subj) .arg(probEstim[0], 0, 'f', 4) .arg(probEstim[1], 0, 'f', 4) .arg(t, 0, 'f', 6) .arg(testFile.getChannelId()) .toAscii(), stdout); } delete[] buf; }
void DataTable::addSample(const DataPoint &sample) { if (getNumSamples() == 0) { numVariables = sample.getDimX(); initDataStructures(); } if(sample.getDimX() != numVariables) { throw Exception("Datatable::addSample: Dimension of new sample is inconsistent with previous samples!"); } // Check if the sample has been added already if (samples.count(sample) > 0) { if (!allowDuplicates) { #ifndef NDEBUG std::cout << "Discarding duplicate sample because allowDuplicates is false!" << std::endl; std::cout << "Initialise with DataTable(true) to set it to true." << std::endl; #endif // NDEBUG return; } numDuplicates++; } samples.insert(sample); recordGridPoint(sample); }
bool ClassificationData::merge(const ClassificationData &otherData){ if( otherData.getNumDimensions() != numDimensions ){ errorLog << "merge(const ClassificationData &labelledData) - The number of dimensions in the labelledData (" << otherData.getNumDimensions() << ") does not match the number of dimensions of this dataset (" << numDimensions << ")" << std::endl; return false; } //The dataset has changed so flag that any previous cross validation setup will now not work crossValidationSetup = false; crossValidationIndexs.clear(); const UINT M = otherData.getNumSamples(); //Reserve the memory reserve( getNumSamples() + M ); //Add the data from the labelledData to this instance for(UINT i=0; i<M; i++){ addSample(otherData[i].getClassLabel(), otherData[i].getSample()); } //Set the class names from the dataset Vector< ClassTracker > classTracker = otherData.getClassTracker(); for(UINT i=0; i<classTracker.getSize(); i++){ setClassNameForCorrespondingClassLabel(classTracker[i].className, classTracker[i].classLabel); } //Sort the class labels sortClassLabels(); return true; }
int FunctionSpace::getTagFromDataPointNo(DataTypes::dim_t dataPointNo) const { // // Get the number of samples and data-points per sample int numSamples = getNumSamples(); int numDataPointsPerSample = getNumDPPSample(); int numDataPoints = numSamples * numDataPointsPerSample; if (numDataPointsPerSample==0) { throw DataException("FunctionSpace::getTagFromDataPointNo error: no data-points associated with this object."); } if (dataPointNo<0 || dataPointNo>=numDataPoints) { throw DataException("FunctionSpace::getTagFromDataPointNo error: invalid data-point number supplied."); } // // Determine the sample number which corresponds to this data-point number int sampleNo = dataPointNo / numDataPointsPerSample; // // Determine the tag number which corresponds to this sample number int tagNo = getTagFromSampleNo(sampleNo); // // return the tag number return(tagNo); }
/*! * Display the menu serial message with the maximum, minimum and current values */ static void dispSetValueMessage(void) { int num = 0; Direction dir; sendROM("\t"); sendROM(m_currentMenu.serialMessage); sendNewLine(1); // Enter a value between x and y sendROM("\t"); sendROM(inputNumRangeStr); transmit(intToAscii(m_currentMenu.minVal)); sendROM(and); transmit(intToAscii(m_currentMenu.maxVal)); sendNewLine(1); // The current value is: sendROM("\t"); sendROM(currentValueStr); switch (m_currentMenu.menuID) { case AZ_GOTO: dir = getDir(); num = (int) dir.azimuth; break; case EL_GOTO: dir = getDir(); num = (int) dir.elevation; break; case AZ_MIN: num = getMinAzimuthAngle(); break; case AZ_MAX: num = getMaxAzimuthAngle(); break; case EL_MIN: num = getMaxAzimuthAngle(); break; case EL_MAX: num = getMaxAzimuthAngle(); break; case RANGE_MIN: num = getMinRange(); break; case RANGE_MAX: num = getMaxRange(); break; case US_SAMPLE_RATE: num = getUsSampleRate(); break; case US_SAMPLE_AVG: num = getNumSamples(); break; } transmit(intToAscii(num)); sendNewLine(1); }
void ChannelMappingNode::process(AudioSampleBuffer& buffer, MidiBuffer& midiMessages) { int j=0; int i=0; int realChan; // use copy constructor to set the data to refer to channelBuffer = buffer; // buffer.clear(); while (j < settings.numOutputs) { realChan = channelArray[i]; if ((realChan < channelBuffer.getNumChannels()) && (enabledChannelArray[realChan])) { // copy it back into the buffer according to the channel mapping buffer.copyFrom(j, // destChannel 0, // destStartSample channelBuffer.getReadPointer(realChan), // source getNumSamples(j), // numSamples 1.0f // gain to apply to source (positive for original signal) ); // now do the referencing if ((referenceArray[realChan] > -1) && (referenceChannels[referenceArray[realChan]] > -1) && (referenceChannels[referenceArray[realChan]] < channelBuffer.getNumChannels())) { buffer.addFrom(j, // destChannel 0, // destStartSample channelBuffer, // source channels[referenceChannels[referenceArray[realChan]]]->index-1, // sourceChannel 0, // sourceStartSample getNumSamples(j), // numSamples -1.0f // gain to apply to source (negative for reference) ); } j++; } i++; } }
void ChannelRenderArea::wheelEvent(QWheelEvent *event) { uint64_t sampleStartNew, sampleEndNew; float zoomFactorNew; /* FIXME: Make this constant user-configurable. */ zoomFactorNew = getZoomFactor() + 0.01 * (event->delta() / WHEEL_DELTA); if (zoomFactorNew < 0) zoomFactorNew = 0; if (zoomFactorNew > 2) zoomFactorNew = 2; /* FIXME: Don't hardcode. */ setZoomFactor(zoomFactorNew); sampleStartNew = 0; /* FIXME */ sampleEndNew = getNumSamples() * zoomFactorNew; if (sampleEndNew > getNumSamples()) sampleEndNew = getNumSamples(); setSampleStart(sampleStartNew); setSampleEnd(sampleEndNew); #if 0 uint64_t sampleStartNew, sampleEndNew; sampleStartNew = getSampleStart() + event->delta() / WHEEL_DELTA; sampleEndNew = getSampleEnd() + event->delta() / WHEEL_DELTA; /* TODO: More checks. */ #if 1 if (sampleStartNew < 0 || sampleEndNew < 0) return; if (sampleStartNew > 512 * 1000 || sampleEndNew > 512 * 1000 /* FIXME */) return; #endif setSampleStart(sampleStartNew); setSampleEnd(sampleEndNew); /* FIXME: Use len? */ #endif repaint(); }
Vector< UINT > ClassificationData::getNumSamplesPerClass() const{ Vector< UINT > classSampleCounts( getNumClasses(), 0 ); if( getNumSamples() == 0 ) return classSampleCounts; for(UINT i=0; i<getNumClasses(); i++){ classSampleCounts[i] = classTracker[i].counter; } return classSampleCounts; }
MatrixDouble TimeSeriesClassificationDataStream::getDataAsMatrixDouble() const { UINT M = getNumSamples(); UINT N = getNumDimensions(); MatrixDouble matrixData(M,N); for(UINT i=0; i<M; i++){ for(UINT j=0; j<N; j++){ matrixData[i][j] = data[i][j]; } } return matrixData; }
void GenericProcessor::processBlock (AudioSampleBuffer &buffer, MidiBuffer &eventBuffer) { int nSamples = getNumSamples(eventBuffer); // removes first value from midimessages process(buffer, eventBuffer, nSamples); setNumSamples(eventBuffer, nSamples); // adds it back, // even if it's unchanged }
const tcu::ConstPixelBufferAccess MultisampleConstPixelBufferAccess::toSinglesampleAccess (void) const { DE_ASSERT(getNumSamples() == 1); return tcu::ConstPixelBufferAccess(m_access.getFormat(), m_access.getHeight(), m_access.getDepth(), 1, m_access.getSlicePitch(), m_access.getSlicePitch() * m_access.getDepth(), m_access.getDataPtr()); }
void LfpDisplayNode::process(AudioSampleBuffer& buffer, MidiBuffer& events) { // 1. place any new samples into the displayBuffer //std::cout << "Display node sample count: " << nSamples << std::endl; ///buffer.getNumSamples() << std::endl; initializeEventChannels(); checkForEvents(events); // see if we got any TTL events ScopedLock displayLock(displayMutex); for (int chan = 0; chan < buffer.getNumChannels(); chan++) { int samplesLeft = displayBuffer->getNumSamples() - displayBufferIndex[chan]; int nSamples = getNumSamples(chan); if (nSamples < samplesLeft) { displayBuffer->copyFrom(chan, // destChannel displayBufferIndex[chan], // destStartSample buffer, // source chan, // source channel 0, // source start sample nSamples); // numSamples displayBufferIndex.set(chan, displayBufferIndex[chan] + nSamples); } else { int extraSamples = nSamples - samplesLeft; displayBuffer->copyFrom(chan, // destChannel displayBufferIndex[chan], // destStartSample buffer, // source chan, // source channel 0, // source start sample samplesLeft); // numSamples displayBuffer->copyFrom(chan, 0, buffer, chan, samplesLeft, extraSamples); displayBufferIndex.set(chan, extraSamples); } } }
MatrixFloat ClassificationData::getDataAsMatrixFloat() const { const UINT M = getNumSamples(); const UINT N = getNumDimensions(); MatrixFloat d(M,N); for(UINT i=0; i<M; i++){ for(UINT j=0; j<N; j++){ d[i][j] = data[i][j]; } } return d; }
MatrixDouble LabelledClassificationData::getDataAsMatrixDouble(){ const UINT M = getNumSamples(); const UINT N = getNumDimensions(); MatrixDouble d(M,N); for(UINT i=0; i<M; i++){ for(UINT j=0; j<N; j++){ d[i][j] = data[i][j]; } } return d; }
void aiPoints::updateSummary() { auto points = m_schema.getPositionsProperty(); auto velocities = m_schema.getVelocitiesProperty(); auto ids = m_schema.getIdsProperty(); m_summary.has_points = points.valid() && points.getNumSamples() > 0; if (m_summary.has_points) m_summary.constant_points = points.isConstant(); m_summary.has_velocities = velocities.valid() && velocities.getNumSamples() > 0; if (m_summary.has_velocities) m_summary.constant_velocities = velocities.isConstant(); m_summary.has_ids = ids.valid() && ids.getNumSamples() > 0; if (m_summary.has_ids) { m_summary.constant_ids = ids.isConstant(); if (m_summary.constant_ids && getConfig().interpolate_samples && !m_summary.constant_points) { m_summary.interpolate_points = true; m_summary.has_velocities = true; m_summary.compute_velocities = true; } } }
typename dsp::AudioBlock<SampleType> Oversampling<SampleType>::processSamplesUp (const dsp::AudioBlock<SampleType>& inputBlock) noexcept { jassert (! stages.isEmpty()); if (! isReady) return {}; auto audioBlock = inputBlock; for (auto* stage : stages) { stage->processSamplesUp (audioBlock); audioBlock = stage->getProcessedSamples (audioBlock.getNumSamples() * stage->factor); } return audioBlock; }
MatrixFloat ClassificationData::getClassHistogramData(UINT classLabel,UINT numBins) const{ const UINT M = getNumSamples(); const UINT N = getNumDimensions(); Vector< MinMax > ranges = getRanges(); VectorFloat binRange(N); for(UINT i=0; i<ranges.size(); i++){ binRange[i] = (ranges[i].maxValue-ranges[i].minValue)/Float(numBins); } MatrixFloat histData(N,numBins); histData.setAllValues(0); Float norm = 0; for(UINT i=0; i<M; i++){ if( data[i].getClassLabel() == classLabel ){ for(UINT j=0; j<N; j++){ UINT binIndex = 0; bool binFound = false; for(UINT k=0; k<numBins-1; k++){ if( data[i][j] >= ranges[i].minValue + (binRange[j]*k) && data[i][j] >= ranges[i].minValue + (binRange[j]*(k+1)) ){ binIndex = k; binFound = true; break; } } if( !binFound ) binIndex = numBins-1; histData[j][binIndex]++; } norm++; } } if( norm == 0 ) return histData; //Is this the best way to normalize a multidimensional histogram??? for(UINT i=0; i<histData.getNumRows(); i++){ for(UINT j=0; j<histData.getNumCols(); j++){ histData[i][j] /= norm; } } return histData; }
DataTypes::dim_t FunctionSpace::getReferenceIDFromDataPointNo(DataTypes::dim_t dataPointNo) const { // // Get the number of samples and data-points per sample DataTypes::dim_t numSamples = getNumSamples(); int numDataPointsPerSample = getNumDPPSample(); const DataTypes::dim_t* referenceIDs= borrowSampleReferenceIDs(); DataTypes::dim_t numDataPoints = numSamples * numDataPointsPerSample; if (numDataPointsPerSample==0) { throw DataException("FunctionSpace::getReferenceIDFromDataPointNo error: no data-points associated with this object."); } if (dataPointNo<0 || dataPointNo>numDataPoints) { throw DataException("FunctionSpace::getReferenceIDFromDataPointNo error: invalid data-point number supplied."); } DataTypes::dim_t sampleNo = dataPointNo / numDataPointsPerSample; return referenceIDs[sampleNo]; }
int VcfRecord::getAlleleCount(unsigned int index, VcfSubsetSamples* sampleSubset) { unsigned int numAlts = getNumAlts(); if(index > numAlts) { // Index out of range. // Throw an exception. throw(std::runtime_error("VcfRecord::getAlleles called with an index that is greater than the number of alternates.")); return(-1); } if(myAlleleCount.size() == 0) { unsigned int gt = 0; myAlleleCount.resize(numAlts+1, 0); // Loop through the samples, counting the number of each allele. for(int sampleNum = 0; sampleNum < getNumSamples(); sampleNum++) { if((sampleSubset != NULL) && !(sampleSubset->keep(sampleNum))) { // Skip this sample. continue; } for(int gtNum = 0; gtNum < getNumGTs(sampleNum); gtNum++) { gt = getGT(sampleNum, gtNum); if((gt < 0) || (gt > numAlts)) { // Out of range GT, so continue to the next gt continue; } // Increment the minor allele count ++myAlleleCount[gt]; } } } // Alternate allele, so return the alternate. return(myAlleleCount[index]); }
static void populateDecisionLabelPairs(svm_model *model, QList<DecisionLabel> &list, WindowFile &file, int label) { const qint32 samples = getNumSamples(file); float *buf = new float[samples]; SVMNodeList nodelist(samples); double decision = 0.; while(file.nextChannel()) { assert(file.getEventSamples() == samples); file.read((char*)buf, samples*sizeof(float)); nodelist.fill(buf); svm_predict_values(model, nodelist, &decision); list.append(DecisionLabel(-decision, label)); } delete[] buf; file.rewind(); }
void MainWindow::on_action_Save_as_triggered() { QString fileName = QFileDialog::getSaveFileName(this, tr("Save sample file"), ".", tr("Raw sample files (*.raw *.bin);;All files (*)")); if (fileName == NULL) return; QFile file(fileName); file.open(QIODevice::WriteOnly); QDataStream out(&file); /* TODO: Implement support for saving to different output formats. */ out.writeRawData((const char *)sample_buffer, getNumSamples() * (getNumChannels() / 8)); file.close(); }
static void predictAndCount(svm_model *model, WindowFile &file, int &nA, int &nB) { const qint32 samples = getNumSamples(file); float *buf = new float[samples]; SVMNodeList nodelist(samples); nA = nB = 0; while(file.nextChannel()) { assert(file.getEventSamples() == samples); file.read((char*)buf, samples*sizeof(float)); nodelist.fill(buf); if(svm_predict(model, nodelist) > 0) ++nA; else ++nB; } delete[] buf; file.rewind(); }
Vector< UINT > ClassificationData::getClassDataIndexes(UINT classLabel) const{ const UINT M = getNumSamples(); const UINT K = getNumClasses(); UINT N = 0; //Get the number of samples in the class for(UINT k=0; k<K; k++){ if( classTracker[k].classLabel == classLabel){ N = classTracker[k].counter; break; } } UINT index = 0; Vector< UINT > classIndexes(N); for(UINT i=0; i<M; i++){ if( data[i].getClassLabel() == classLabel ){ classIndexes[index++] = i; } } return classIndexes; }
size_t Timing::getNumSamples(std::string const & tag) { return getNumSamples(getHandle(tag)); }