ClassificationData ClassificationData::getBootstrappedDataset(UINT numSamples) const{ Random rand; ClassificationData newDataset; newDataset.setNumDimensions( getNumDimensions() ); newDataset.setAllowNullGestureClass( allowNullGestureClass ); newDataset.setExternalRanges( externalRanges, useExternalRanges ); if( numSamples == 0 ) numSamples = totalNumSamples; newDataset.reserve( numSamples ); //Add all the class labels to the new dataset to ensure the dataset has a list of all the labels for(UINT k=0; k<getNumClasses(); k++){ newDataset.addClass( classTracker[k].classLabel ); } //Randomly select the training samples to add to the new data set UINT randomIndex; for(UINT i=0; i<numSamples; i++){ randomIndex = rand.getRandomNumberInt(0, totalNumSamples); newDataset.addSample(data[randomIndex].getClassLabel(), data[randomIndex].getSample()); } //Sort the class labels so they are in order newDataset.sortClassLabels(); return newDataset; }
TimeSeriesClassificationDataStream TimeSeriesClassificationDataStream::getSubset(const UINT startIndex,const UINT endIndex) const { TimeSeriesClassificationDataStream subset; if( endIndex >= totalNumSamples ){ warningLog << "getSubset(const UINT startIndex,const UINT endIndex) - The endIndex is greater than or equal to the number of samples in the current dataset!" << endl; return subset; } if( startIndex >= endIndex ){ warningLog << "getSubset(const UINT startIndex,const UINT endIndex) - The startIndex is greater than or equal to the endIndex!" << endl; return subset; } //Set the header info subset.setNumDimensions( getNumDimensions() ); subset.setDatasetName( getDatasetName() ); subset.setInfoText( getInfoText() ); //Add the data for(UINT i=startIndex; i<=endIndex; i++){ subset.addSample(data[i].getClassLabel(), data[i].getSample()); } return subset; }
ClassificationData ClassificationData::getBootstrappedDataset(UINT numSamples,bool balanceDataset) const{ Random rand; ClassificationData newDataset; newDataset.setNumDimensions( getNumDimensions() ); newDataset.setAllowNullGestureClass( allowNullGestureClass ); newDataset.setExternalRanges( externalRanges, useExternalRanges ); if( numSamples == 0 ) numSamples = totalNumSamples; newDataset.reserve( numSamples ); const UINT K = getNumClasses(); //Add all the class labels to the new dataset to ensure the dataset has a list of all the labels for(UINT k=0; k<K; k++){ newDataset.addClass( classTracker[k].classLabel ); } if( balanceDataset ){ //Group the class indexs Vector< Vector< UINT > > classIndexs( K ); for(UINT i=0; i<totalNumSamples; i++){ classIndexs[ getClassLabelIndexValue( data[i].getClassLabel() ) ].push_back( i ); } //Get the class with the minimum number of examples UINT numSamplesPerClass = (UINT)floor( numSamples / Float(K) ); //Randomly select the training samples from each class UINT classIndex = 0; UINT classCounter = 0; UINT randomIndex = 0; for(UINT i=0; i<numSamples; i++){ randomIndex = rand.getRandomNumberInt(0, (UINT)classIndexs[ classIndex ].size() ); randomIndex = classIndexs[ classIndex ][ randomIndex ]; newDataset.addSample(data[ randomIndex ].getClassLabel(), data[ randomIndex ].getSample()); if( classCounter++ >= numSamplesPerClass && classIndex+1 < K ){ classCounter = 0; classIndex++; } } }else{ //Randomly select the training samples to add to the new data set UINT randomIndex; for(UINT i=0; i<numSamples; i++){ randomIndex = rand.getRandomNumberInt(0, totalNumSamples); newDataset.addSample( data[randomIndex].getClassLabel(), data[randomIndex].getSample() ); } } //Sort the class labels so they are in order newDataset.sortClassLabels(); return newDataset; }
void TransFunc::setUniform(tgt::Shader* shader, const std::string& uniform, const GLint texUnit) { tgtAssert(shader, "Null pointer passed"); bool oldIgnoreError = shader->getIgnoreUniformLocationError(); shader->setIgnoreUniformLocationError(true); shader->setUniform(uniform + ".texture_", texUnit); if(getNumDimensions() == 1) { shader->setUniform(uniform + ".domainLower_", getDomain(0).x); shader->setUniform(uniform + ".domainUpper_", getDomain(0).y); } else if(getNumDimensions() == 2) { shader->setUniform(uniform + ".domainLower_", tgt::vec2(getDomain(0).x, getDomain(1).x)); shader->setUniform(uniform + ".domainUpper_", tgt::vec2(getDomain(0).y, getDomain(1).y)); } else { LERROR("Unhandled dimensionality in glsl TransFunc object"); } shader->setIgnoreUniformLocationError(oldIgnoreError); }
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; }
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; }
LabelledClassificationData LabelledClassificationData::getBootstrappedDataset(UINT numSamples){ Random rand; LabelledClassificationData newDataset; newDataset.setNumDimensions( getNumDimensions() ); newDataset.setAllowNullGestureClass( allowNullGestureClass ); if( numSamples == 0 ) numSamples = totalNumSamples; for(UINT i=0; i<numSamples; i++){ UINT randomIndex = rand.getRandomNumberInt(0, totalNumSamples); newDataset.addSample(data[randomIndex].getClassLabel(), data[randomIndex].getSample()); } return newDataset; }
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; }
TimeSeriesClassificationData TimeSeriesClassificationDataStream::getTimeSeriesClassificationData( const bool includeNullGestures ) const { TimeSeriesClassificationData tsData; tsData.setNumDimensions( getNumDimensions() ); tsData.setAllowNullGestureClass( includeNullGestures ); bool addSample = false; const UINT numTimeseries = (UINT)timeSeriesPositionTracker.size(); for(UINT i=0; i<numTimeseries; i++){ addSample = includeNullGestures ? true : timeSeriesPositionTracker[i].getClassLabel() != GRT_DEFAULT_NULL_CLASS_LABEL; if( addSample ){ tsData.addSample(timeSeriesPositionTracker[i].getClassLabel(), getTimeSeriesData( timeSeriesPositionTracker[i] ) ); } } return tsData; }
MatrixDouble TimeSeriesClassificationDataStream::getTimeSeriesData( const TimeSeriesPositionTracker &trackerInfo ) const { if( trackerInfo.getStartIndex() >= totalNumSamples || trackerInfo.getEndIndex() > totalNumSamples ){ warningLog << "getTimeSeriesData(TimeSeriesPositionTracker trackerInfo) - Invalid tracker indexs!" << endl; return MatrixDouble(); } UINT startIndex = trackerInfo.getStartIndex(); UINT endIndex = trackerInfo.getEndIndex(); UINT M = endIndex > 0 ? trackerInfo.getLength() : totalNumSamples - startIndex; UINT N = getNumDimensions(); MatrixDouble tsData(M,N); for(UINT i=0; i<M; i++){ for(UINT j=0; j<N; j++){ tsData[i][j] = data[ i+startIndex ][j]; } } return tsData; }
ClassificationData TimeSeriesClassificationDataStream::getClassificationData( const bool includeNullGestures ) const { ClassificationData classificationData; classificationData.setNumDimensions( getNumDimensions() ); classificationData.setAllowNullGestureClass( includeNullGestures ); bool addSample = false; for(UINT i=0; i<timeSeriesPositionTracker.size(); i++){ addSample = includeNullGestures ? true : timeSeriesPositionTracker[i].getClassLabel() != GRT_DEFAULT_NULL_CLASS_LABEL; if( addSample ){ MatrixDouble dataSegment = getTimeSeriesData( timeSeriesPositionTracker[i] ); for(UINT j=0; j<dataSegment.getNumRows(); j++){ classificationData.addSample(timeSeriesPositionTracker[i].getClassLabel(), dataSegment.getRowVector(j) ); } } } return classificationData; }