//////////////////////////// //Author: Brian Fehrman //Just the encapsulating run function //for the class which will call all of the //functions necessary to perform knn //classification on a data set. Uses the first //half of the given set for training and the second //half for testing //////////////////////////// int knn_classifier::run() { cout << endl << setw(50) <<"***RUNNING KNN CLASSIFIER***" << endl << endl; cout << setw(80) << setfill('^') << " "; cout << setfill(' ') << endl; cout << "Using " << num_neighbors << " neighbors" << endl << endl; //Read in file data and return error //if unsucceseful if( read_file_data() ) return -1; //Perform the classification of the data classify_data(); cout << endl << setw(50)<< "***FINISHED KNN CLASSIFIER***" << endl << endl; cout << setw(80) << setfill('-') << " "; cout << setfill(' ') << endl; return 0; }
//////////////////////////// //Author: Brian Fehrman //Just the encapsulating run function //for the class which will call all of the //functions necessary to perform mle //classification on a data set. Uses the first //half of the given set for training and the second //half for testing //////////////////////////// int mle_classifier::run() { cout << endl << setw(50) <<"***RUNNING MLE CLASSIFIER***" << endl << endl; cout << setw(80) << setfill('^') << " "; cout << setfill(' '); //Read in file data and return error //if unsucceseful if( read_file_data() ) return -1; //Calculate means, variances, etc. for each class determine_training_class_info(); //Perform the classification of the data classify_data(); cout << endl << setw(50) <<"***FINISHED MLE CLASSIFIER***" << endl << endl; cout << setw(80) << setfill('-') << " "; cout << setfill(' ') << endl; return 0; }
/** * cdk_keydb_search_start: * @db: key database handle * @type: specifies the search type * @desc: description which depends on the type * * Create a new keydb search object. **/ cdk_error_t cdk_keydb_search_start( cdk_keydb_hd_t db, int type, void * desc ) { cdk_dbsearch_t dbs; u32 * keyid; char * p, tmp[3]; int i; if( !db ) return CDK_Inv_Value; if( type != CDK_DBSEARCH_NEXT && !desc ) return CDK_Inv_Mode; dbs = cdk_calloc( 1, sizeof *dbs ); if( !dbs ) return CDK_Out_Of_Core; dbs->type = type; switch( type ) { case CDK_DBSEARCH_EXACT: case CDK_DBSEARCH_SUBSTR: cdk_free( dbs->u.pattern ); dbs->u.pattern = cdk_strdup( desc ); if( !dbs->u.pattern ) { cdk_free( dbs ); return CDK_Out_Of_Core; } break; case CDK_DBSEARCH_SHORT_KEYID: keyid = desc; dbs->u.keyid[1] = keyid[0]; break; case CDK_DBSEARCH_KEYID: keyid = desc; dbs->u.keyid[0] = keyid[0]; dbs->u.keyid[1] = keyid[1]; break; case CDK_DBSEARCH_FPR: memcpy( dbs->u.fpr, desc, 20 ); break; case CDK_DBSEARCH_NEXT: break; case CDK_DBSEARCH_AUTO: /* override the type with the actual db search type. */ dbs->type = classify_data( desc, strlen( desc ) ); switch( dbs->type ) { case CDK_DBSEARCH_SUBSTR: case CDK_DBSEARCH_EXACT: cdk_free( dbs->u.pattern ); p = dbs->u.pattern = cdk_strdup( desc ); if( !p ) { cdk_free( dbs ); return CDK_Out_Of_Core; } break; case CDK_DBSEARCH_SHORT_KEYID: case CDK_DBSEARCH_KEYID: p = desc; if( !strncmp( p, "0x", 2 ) ) p += 2; if( strlen( p ) == 8 ) { dbs->u.keyid[0] = 0; dbs->u.keyid[1] = strtoul( p, NULL, 16 ); } else if( strlen( p ) == 16 ) { dbs->u.keyid[0] = strtoul( p , NULL, 16 ); dbs->u.keyid[1] = strtoul( p + 8, NULL, 16 ); } else { /* should never happen */ cdk_free( dbs ); return CDK_Inv_Mode; } break; case CDK_DBSEARCH_FPR: p = desc; if( strlen( p ) != 40 ) { cdk_free( dbs ); return CDK_Inv_Mode; } for( i = 0; i < 20; i++ ) { tmp[0] = p[2*i]; tmp[1] = p[2*i+1]; tmp[2] = 0x00; dbs->u.fpr[i] = strtoul( tmp, NULL, 16 ); } break; } break; default: cdk_free( dbs ); return CDK_Inv_Mode; } keydb_search_free( db->dbs ); db->dbs = dbs; return 0; }