/* * This method iterates over the sample vectors in a given file and * performs the required operations according the the perceptron algorithm, * writing the result into an output file. * @param input_file - The file containing the sample vectors. * @param output_file - The file to write the results into. */ void perceptron(FILE* input_file, FILE* output_file) { int vector_size = getSampleVectorsSize(input_file); double cur_separator[MAX_DIMENSION]; double cur_sample[MAX_DIMENSION]; char cur_sample_tag; char cur_calc_tag; initSeparator(cur_separator,vector_size); writeSeparatorToFile(output_file,cur_separator,vector_size);//initial write while((cur_sample_tag = getSampleVectorFromFile(input_file, cur_sample,vector_size))!= END_FILE) //if cur_sample_tag gets -2, it means the samples file had ended { //casting to the matching ascii code to get P/N cur_calc_tag = tagNewDataPoint(cur_sample,cur_separator,vector_size) + TAG_ASCII_DIFFERENCE; if(cur_calc_tag != cur_sample_tag) { //casting tag back to -1/1 updateSeparator(cur_separator,cur_sample, cur_sample_tag - TAG_ASCII_DIFFERENCE,vector_size); } writeSeparatorToFile(output_file,cur_separator,vector_size); } }
void Toolbar::changed( unsigned int& index, ItemPtr item ) { static const unsigned int MAX_MENU_TEXT = 1024; char txtBuf[ MAX_MENU_TEXT + 1 ]; for( unsigned int i = 0; i < item->num(); ++i, ++index ) { TBBUTTONINFO info; memset( &info, 0, sizeof( info ) ); info.cbSize = sizeof( info ); info.dwMask = TBIF_BYINDEX | TBIF_COMMAND | TBIF_IMAGE | TBIF_LPARAM | TBIF_SIZE | TBIF_STATE | TBIF_STYLE | TBIF_TEXT; info.pszText = txtBuf; txtBuf[0] = 0; info.cchText = MAX_MENU_TEXT; sendMessage( TB_GETBUTTONINFO, index, (LPARAM)&info ); ItemPtr subItem = ( *item )[ i ]; if( subItem->type() == "SEPARATOR" ) updateSeparator( index, subItem, info ); else if( subItem->type() == "GROUP" ) updateGroup( index, subItem, info ); else if( subItem->type() == "ACTION" ) updateAction( index, subItem, info ); else if( subItem->type() == "TOGGLE" ) updateToggle( index, subItem, info ); else if( subItem->type() == "CHOICE" ) updateChoice( index, subItem, info ); else if( subItem->type() == "EXPANDED_CHOICE" ) updateExpandedChoice( index, subItem, info ); } --index; }
void Menu::changed( HMENU hmenu, ItemPtr item ) { static const unsigned int MAX_MENU_TEXT = 1024; char txtBuf[ MAX_MENU_TEXT + 1 ]; int i = 0; unsigned int j = 0; while( i < GetMenuItemCount( hmenu ) ) { MENUITEMINFO info = { sizeof( info ), MIIM_BITMAP | MIIM_CHECKMARKS | MIIM_DATA | MIIM_FTYPE | MIIM_ID | MIIM_STATE | MIIM_STRING | MIIM_SUBMENU }; info.cch = MAX_MENU_TEXT; info.dwTypeData = txtBuf; GetMenuItemInfo( hmenu, i, TRUE, &info ); if( j < item->num() ) { ItemPtr sub = ( *item )[ j ]; if( ( Item* )info.dwItemData != sub ) { insertMenuItem( hmenu, i, sub ); ZeroMemory( &info, sizeof( info ) ); info.cbSize = sizeof( info ); info.fMask = MIIM_BITMAP | MIIM_CHECKMARKS | MIIM_DATA | MIIM_FTYPE | MIIM_ID | MIIM_STATE | MIIM_STRING | MIIM_SUBMENU; info.cch = MAX_MENU_TEXT; info.dwTypeData = txtBuf; GetMenuItemInfo( hmenu, i, TRUE, &info ); } if( sub->type() == "SEPARATOR" ) updateSeparator( hmenu, i, sub, info ); else if( sub->type() == "GROUP" ) updateGroup( hmenu, i, sub, info ); else if( sub->type() == "ACTION" ) updateAction( hmenu, i, sub, info ); else if( sub->type() == "TOGGLE" ) updateToggle( hmenu, i, sub, info ); else if( sub->type() == "CHOICE" ) updateChoice( hmenu, i, sub, info ); else if( sub->type() == "EXPANDED_CHOICE" ) updateExpandedChoice( hmenu, i, sub, info ); else updateUnknownItem( hmenu, i, sub, info ); GetMenuItemInfo( hmenu, i, TRUE, &info ); ++i; ++j; } else DeleteMenu( hmenu, i, MF_BYPOSITION ); } for(; j< item->num(); ++j ) { ItemPtr sub = ( *item )[ j ]; insertMenuItem( hmenu, i, sub ); MENUITEMINFO info = { sizeof( info ), MIIM_BITMAP | MIIM_CHECKMARKS | MIIM_DATA | MIIM_FTYPE | MIIM_ID | MIIM_STATE | MIIM_STRING | MIIM_SUBMENU }; info.cch = MAX_MENU_TEXT; info.dwTypeData = txtBuf; GetMenuItemInfo( hmenu, i, TRUE, &info ); if( sub->type() == "SEPARATOR" ) updateSeparator( hmenu, i, sub, info ); else if( sub->type() == "GROUP" ) updateGroup( hmenu, i, sub, info ); else if( sub->type() == "ACTION" ) updateAction( hmenu, i, sub, info ); else if( sub->type() == "TOGGLE" ) updateToggle( hmenu, i, sub, info ); else if( sub->type() == "CHOICE" ) updateChoice( hmenu, i, sub, info ); else if( sub->type() == "EXPANDED_CHOICE" ) updateExpandedChoice( hmenu, i, sub, info ); else updateUnknownItem( hmenu, i, sub, info ); GetMenuItemInfo( hmenu, i, TRUE, &info ); ++i; } }