UINT ClassLabelFilter::filter(UINT predictedClassLabel){
    
    if( !initialized ){
        errorLog << "filter(UINT predictedClassLabel) - The filter has not been initialized!" << endl;
        filteredClassLabel = 0;
        return 0;
    }
    
    //Add the current predictedClassLabel to the buffer
    buffer.push_back( predictedClassLabel );
    
    //Count the class values in the buffer, automatically start with the first value in the buffer
    vector< ClassTracker > classTracker( 1, ClassTracker( buffer[0], 1 ) );
    
    UINT maxCount = classTracker[0].counter;
    UINT maxClass = classTracker[0].classLabel;
    bool classLabelFound = false;
    
    for(UINT i=1; i<bufferSize; i++){
        classLabelFound = false;
        UINT currentCount = 0;
        UINT currentClassLabel = buffer[i];
        for(UINT k=0; k<classTracker.size(); k++){
            if( currentClassLabel == classTracker[k].classLabel ){
                classTracker[k].counter++;
                classLabelFound = true;
                currentCount = classTracker[k].counter;
                break;
            }
        }
        
        //If we have not found the class label then we need to add this class to the classTracker
        if( !classLabelFound ){
            classTracker.push_back( ClassTracker(currentClassLabel,1) );
            currentCount = 1;
        }
        
        //Check to see if we should update the max count and maxClass (ignoring class label 0)
        if( currentCount > maxCount && currentClassLabel != 0 ){
            maxCount = currentCount;
            maxClass = currentClassLabel;
        }
    }
    
    //printf("minimumCount: %i maxCount: %i maxClass: %i\n",minimumCount,maxCount,maxClass);
    
    if( maxCount >= minimumCount ){
        filteredClassLabel = maxClass;
    }else filteredClassLabel = 0;
    
    return filteredClassLabel;
}
bool TimeSeriesClassificationDataStream::relabelAllSamplesWithClassLabel(const UINT oldClassLabel,const UINT newClassLabel){
    bool oldClassLabelFound = false;
    bool newClassLabelAllReadyExists = false;
    UINT indexOfOldClassLabel = 0;
    UINT indexOfNewClassLabel = 0;
    
    //Find out how many training examples we need to relabel
    for(UINT i=0; i<classTracker.size(); i++){
        if( classTracker[i].classLabel == oldClassLabel ){
            indexOfOldClassLabel = i;
            oldClassLabelFound = true;
        }
        if( classTracker[i].classLabel == newClassLabel ){
            indexOfNewClassLabel = i;
            newClassLabelAllReadyExists = true;
        }
    }
    
    //If the old class label was not found then we can't do anything
    if( !oldClassLabelFound ){
        return false;
    }
    
    //Relabel the old class labels
    for(UINT i=0; i<totalNumSamples; i++){
        if( data[i].getClassLabel() == oldClassLabel ){
            data[i].set(newClassLabel, data[i].getSample());
        }
    }
    
    //Update the class label counters
    if( newClassLabelAllReadyExists ){
        //Add the old sample count to the new sample count
        classTracker[ indexOfNewClassLabel ].counter += classTracker[ indexOfOldClassLabel ].counter;
        
        //Erase the old class tracker
        classTracker.erase( classTracker.begin() + indexOfOldClassLabel );
    }else{
        //Create a new class tracker
        classTracker.push_back( ClassTracker(newClassLabel,classTracker[ indexOfOldClassLabel ].counter,classTracker[ indexOfOldClassLabel ].className) );
    }
    
    //Update the timeseries position tracker
    for(UINT i=0; i<timeSeriesPositionTracker.size(); i++){
        if( timeSeriesPositionTracker[i].getClassLabel() == oldClassLabel ){
            timeSeriesPositionTracker[i].setClassLabel( newClassLabel );
        }
    }
    
    return true;
}
bool ClassificationData::addClass(const UINT classLabel,const std::string className){
    
    //Check to make sure the class label does not exist
    for(UINT i=0; i<classTracker.size(); i++){
        if( classTracker[i].classLabel == classLabel ){
            return false;
        }
    }
    
    //Add the class label to the class tracker
    classTracker.push_back( ClassTracker(classLabel,0,className) );
    
    //Sort the class labels
    sortClassLabels();
    
    return true;
}
Beispiel #4
0
bool ClassificationData::addClass(const UINT classLabel,const std::string className){
    
    //Check to make sure the class label does not exist
    for(size_t i=0; i<classTracker.getSize(); i++){
        if( classTracker[i].classLabel == classLabel ){
            warningLog << "addClass(const UINT classLabel,const std::string className) - Failed to add class, it already exists! Class label: " << classLabel << std::endl;
            return false;
        }
    }
    
    //Add the class label to the class tracker
    classTracker.push_back( ClassTracker(classLabel,0,className) );
    
    //Sort the class labels
    sortClassLabels();
    
    return true;
}