bool ParticleClassifier::train_(TimeSeriesClassificationData &trainingData){
    
    clear();
    
    numClasses = trainingData.getNumClasses();
    numInputDimensions = trainingData.getNumDimensions();
    ranges = trainingData.getRanges();
    
    //Scale the training data if needed
    if( useScaling ){
        trainingData.scale(0, 1);
    }
    
    //Train the particle filter
    particleFilter.train( numParticles, trainingData, sensorNoise, transitionSigma, phaseSigma, velocitySigma );
    
    classLabels.resize(numClasses);
    classLikelihoods.resize(numClasses,0);
    classDistances.resize(numClasses,0);
    
    for(unsigned int i=0; i<numClasses; i++){
        classLabels[i] = trainingData.getClassTracker()[i].classLabel;
    }
    
    trained = true;
  
    return trained;
}
Exemplo n.º 2
0
bool HMM::train_continuous(TimeSeriesClassificationData &trainingData){
    
    clear();
    
    if( trainingData.getNumSamples() == 0 ){
        errorLog << "train_continuous(TimeSeriesClassificationData &trainingData) - There are no training samples to train the CHMM classifer!" << endl;
        return false;
    }
    
    //Reset the CHMM
    numInputDimensions = trainingData.getNumDimensions();
    numClasses = trainingData.getNumClasses();
    classLabels.resize( numClasses );
    for(UINT k=0; k<numClasses; k++){
        classLabels[k] = trainingData.getClassTracker()[k].classLabel;
    }
    
    //Scale the training data if needed
    ranges = trainingData.getRanges();
    if( useScaling ){
        trainingData.scale(0, 1);
    }
    
    //Setup the models, there will be 1 model for each training sample
    const UINT numTrainingSamples = trainingData.getNumSamples();
    continuousModels.resize( numTrainingSamples );
    
    //Train each of the models
    for(UINT k=0; k<numTrainingSamples; k++){
        
        //Init the model
        continuousModels[k].setDownsampleFactor( downsampleFactor );
        continuousModels[k].setModelType( modelType );
        continuousModels[k].setDelta( delta );
        continuousModels[k].setSigma( sigma );
        continuousModels[k].setAutoEstimateSigma( autoEstimateSigma );
        continuousModels[k].enableScaling( false ); //Scaling should always off for the models as we do any scaling in the CHMM
        
        //Train the model
        if( !continuousModels[k].train_( trainingData[k] ) ){
            errorLog << "train_continuous(TimeSeriesClassificationData &trainingData) - Failed to train CHMM for sample " << k << endl;
            return false;
        }
    }
    
    if( committeeSize > trainingData.getNumSamples() ){
        committeeSize = trainingData.getNumSamples();
        warningLog << "train_continuous(TimeSeriesClassificationData &trainingData) - The committeeSize is larger than the number of training sample. Setting committeeSize to number of training samples: " << trainingData.getNumSamples() << endl;
    }
    
    //Flag that the model has been trained
    trained = true;
    
    //Compute any null rejection thresholds if needed
    if( useNullRejection ){
        //Compute the rejection thresholds
        nullRejectionThresholds.resize(numClasses);
    }
    
    return true;
}