bool SVM::predict_(VectorDouble &inputVector){
    
    if( !trained ){
        errorLog << "predict_(VectorDouble &inputVector) - The SVM model has not been trained!" << endl;
        return false;
    }
    
    if( inputVector.size() != numInputDimensions ){
        errorLog << "predict_(VectorDouble &inputVector) - The size of the input vector (" << inputVector.size() << ") does not match the number of features of the model (" << numInputDimensions << ")" << endl;
        return false;
    }
    
    if( param.probability == 1 ){
        if( !predictSVM( inputVector, maxLikelihood, classLikelihoods ) ){
            errorLog << "predict(VectorDouble inputVector) - Prediction Failed!" << endl;
            return false;
        }
    }else{
        if( !predictSVM( inputVector ) ){
            errorLog << "predict(VectorDouble inputVector) - Prediction Failed!" << endl;
            return false;
        }
    }
    
    return true;
}
示例#2
0
int main(int argc, char** argv)
{
    /////////////////////////////////////////////////////
    ///usage:
    ///AnormalyDetection -t [0 1] [ [-f] or [-d [0 1 2 3...] [-l lable] location] ]
    //AnormalyDetection -t [0 1] -f
    //AnormalyDetection -t [0 1] -d [0 1 2 3...] [-l lable] location
    ///////////////////////////////////////////////////////

    /*printf("argc = %d\n", argc);
    for(int i  = 1; i < argc; i ++)
        printf("%d %s\n", i, argv[i]);*/

    char **output = new char*[4];
    for(int i = 0; i < 4; i ++)
    {
        output[i] = new char[MaxStringLength];
        memcpy(output[i], "\0", MaxStringLength);
    }
    int n = 0;
    if(!options(argc, argv, output, n))
    {
        printf("error usage!\n");
        printf("usage:program options location\n");
        printf("options:-t, -f, -d , -l\n");
        return 1;
    }
    /*for(int i = 0; i < 4; i ++)
    {
        printf("%d: %s\n", i+1, output[i]);
    }*/
    int type = atoi(output[0]);
    if(n == 1)
    {
        if(type == 0)
		{
            trainSVMModel();
		}
		if(type == 1)
		{
		    //printf("entering detection...\n");
            predictSVM();
		}
        return 0;
    }
    
    
    int dataset = atoi(output[1]);
    switch(dataset)
    {
            case 1://UMN
                frameWidth = 320;
    			frameHeight = 240;
    			break;
            case 2://BEHAVE
                frameWidth = 640;
                frameHeight = 480;
    			break;
            case 3://UCSD_PED1
                frameWidth = 238;
                frameHeight = 158;
    			break;
            case 4://UCSD_PED2
                frameWidth = 238;
                frameHeight = 158;
                break;
    		default:
    			break;
    }
    
    char* location = output[2];
	vector<string> files;
    readDataset(location, files);
    
    if(type == 0)
    {
        trainSVMModel(files);
    }
    if(type == 1)
    {
        //printf("entering detection...\n");
        vector<int> labels;
        readLabels(output[3], labels);
        predictSVM(files, labels);
    }

    return 0;
}