int AB_CSV_EditProfileDialog_HandleActivated(GWEN_DIALOG *dlg, const char *sender) { AB_CSV_EDIT_PROFILE_DIALOG *xdlg; assert(dlg); xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AB_CSV_EDIT_PROFILE_DIALOG, dlg); assert(xdlg); if (strcasecmp(sender, "okButton")==0) { GWEN_DB_NODE *db; int rv; db=GWEN_DB_Group_new("profile"); rv=AB_CSV_EditProfileDialog_fromGui(dlg, db); if (rv<0) { DBG_INFO(AQBANKING_LOGDOMAIN, "here (%d)", rv); GWEN_DB_Group_free(db); return GWEN_DialogEvent_ResultHandled; } GWEN_DB_ClearGroup(xdlg->dbProfile, NULL); GWEN_DB_AddGroupChildren(xdlg->dbProfile, db); GWEN_DB_Group_free(db); return GWEN_DialogEvent_ResultAccept; } else if (strcasecmp(sender, "abortButton")==0) return GWEN_DialogEvent_ResultReject; else if (strcasecmp(sender, "helpButton")==0) { } else if (strcasecmp(sender, "headerCheck")==0) { if (xdlg->testFileName) readTestData(dlg); return GWEN_DialogEvent_ResultHandled; } return GWEN_DialogEvent_ResultHandled; }
void DTest::run(const char* path) { std::ifstream in(path, std::ios_base::binary); SCOPE_ASSERT(in); Executor Exec; while (in.peek() != -1) { TestCase tcase; SCOPE_ASSERT(readTestData(in, tcase.patterns, tcase.text, tcase.expected)); Exec.submit(tcase); } }
int main(int argc, char** argv){ if( argc < 9 ){ cerr << "structTrain [data] [template] [test_data] [lambda] [modelFname] [0:SSG/1:BCFW] [kernel='G'/'L'] [gamma] (max_iter)" << endl; exit(0); } char* dataFname = argv[1]; char* tempFname = argv[2]; char* testFname = argv[3]; double lambda = atof(argv[4]); char* modelFname = argv[5]; int method = atoi(argv[6]); char kernel_type = argv[7][0]; double gamma = atof(argv[8]); int max_iter = 50; if( argc > 9 ) max_iter = atoi(argv[9]); Param* param = new Param(); readData(dataFname, tempFname, param); param->n_train = param->data->size(); readTestData(testFname, param); param->n_test = param->data->size() - param->n_train; param->featuremapFunc = chain_featuremap; param->oracleFunc = chain_oracle; param->loss = chain_loss; param->num_states = param->label_index_map.size(); param->gamma = gamma; param->lambda = lambda/param->n_train; param->modelFname = modelFname; param->kernel_type = kernel_type; //param->lambda = 0.01; cerr << "#train_samples=" << param->n_train << endl; cerr << "#test_samples=" << param->n_test << endl; cerr << "|Y_f|=" << param->num_states << endl; cerr << "lambda=" << param->lambda << endl; Option* option = new Option(NULL,NULL); option->num_pass = max_iter; Model* model; if( method == 0 ) model = solverSSG(param, option); else model = solverBCFW(param, option); //writeModel(modelFname, model); return 0; }
int AB_CSV_EditProfileDialog_HandleValueChanged(GWEN_DIALOG *dlg, const char *sender){ AB_CSV_EDIT_PROFILE_DIALOG *xdlg; assert(dlg); xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AB_CSV_EDIT_PROFILE_DIALOG, dlg); assert(xdlg); if (strcasecmp(sender, "ignoreLinesSpin")==0 || strcasecmp(sender, "delimiterCombo")==0 || strcasecmp(sender, "headerCheck")==0 || strcasecmp(sender, "quoteCheck")==0) { if (xdlg->testFileName) readTestData(dlg); } return GWEN_DialogEvent_ResultHandled; }
int main(int argc, char** argv) { loadConfig(CONFIG_FILE); if (!hasSimMatrix) { readData(&A, nMovies, nUsers, trainSet); #ifdef DEBUG readArr(A, nMovies, nUsers); #endif omp_set_num_threads(MAX_THREAD); /* CHUAN HOA */ printf("\n\nChuan hoa: "); #pragma omp parallel for for (int i=0; i<nMovies; i++) { float sum = 0; //Tong cac rating int t = 0; //So rating #pragma omp parallel for schedule(static, 3) reduction(+:sum) for (int j=0; j<nUsers; j++) { if (A[i][j] != 0) { sum += A[i][j]; t++; } } float rowMean = sum/t; #pragma omp parallel for schedule(static, 3) for (int j=0; j<nUsers; j++) { if (A[i][j] != 0) A[i][j] -= rowMean; } printf("\n%d/%d", i, nMovies); } #ifdef DEBUG puts(""); printf("\nSTANDARDIZED MARTRIX: \n"); readArr(A, nMovies, nUsers); puts(""); #endif /* TINH SIMILARY MATRIX */ printf("\n\nTinh sim: "); sim = calloc(nMovies, sizeof(float*)); for (int i=0; i<nMovies; i++) sim[i] = calloc(nMovies, sizeof(float*)); #pragma omp parallel for schedule(static, 3) for (int i=0; i<nMovies; i++) { #pragma omp parallel for schedule(static, 3) for (int j=i+1; j<nMovies; j++) { sim[i][j] = cosine(A[i], A[j], nUsers); } printf("\n%d/%d: ", i, nMovies); } for (int i=0; i<nMovies; i++) for (int j=0; j<=i; j++) { if (i == j) sim[i][j] = 1; else sim[i][j] = sim[j][i]; } writeDataToFile(sim, nMovies, nMovies, pathToSimMatrix); freeArr(A, nMovies); } else { int tmp; loadArrFromFile(&sim, &tmp, &tmp, pathToSimMatrix); } #ifdef DEBUG puts(""); printf("\nSIMILARY MATRIX: \n"); readArr(sim, nMovies, nMovies); puts(""); #endif /* TINH RATING */ Rating *B; int len; readTestData(&B, &len, testSet); readData(&A, nMovies, nUsers, trainSet); float *AVG; computeAvgRating(&AVG, A, nMovies, nUsers); #pragma omp parallel for schedule(static, 3) for (int i=0; i<len; i++) { ratePredict(&B[i], A, sim); //Neu khong the du doan thi dua ve gia tri trung binh if (B[i].P == 0) B[i].P = AVG[B[i].uID]; } writeResultToFile(B, len, "data/result.txt"); float T = 0; float temp; #pragma omp parallel for schedule(static, 3) reduction(+:T) private(temp) for (int i=0; i<len; i++) { temp = B[i].R - B[i].P; T += temp * temp; } printf("\n %f", sqrt(T/len)); #ifdef DEBUG puts(""); printf("RESULT: "); for (int i=0; i<len; i++) { printf("\nmID: %5d uID: %5d Real: %6.2fd Predict: %6.2f", B[i].mID, B[i].uID, B[i].R, B[i].P); usleep(1000000); } puts(""); #endif free(AVG); freeArr(sim, nMovies); free(B); freeArr(A, nMovies); puts(""); return 0; }
void AB_CSV_EditProfileDialog_Init(GWEN_DIALOG *dlg) { AB_CSV_EDIT_PROFILE_DIALOG *xdlg; int i; const char *s; GWEN_DB_NODE *dbPrefs; assert(dlg); xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, AB_CSV_EDIT_PROFILE_DIALOG, dlg); assert(xdlg); /* setup dialog size */ dbPrefs=GWEN_Dialog_GetPreferences(dlg); /* read width */ i=GWEN_DB_GetIntValue(dbPrefs, "dialog_width", 0, -1); if (i>=DIALOG_MINWIDTH) GWEN_Dialog_SetIntProperty(dlg, "", GWEN_DialogProperty_Width, 0, i, 0); /* read height */ i=GWEN_DB_GetIntValue(dbPrefs, "dialog_height", 0, -1); if (i>=DIALOG_MINHEIGHT) GWEN_Dialog_SetIntProperty(dlg, "", GWEN_DialogProperty_Height, 0, i, 0); GWEN_Dialog_SetCharProperty(dlg, "", GWEN_DialogProperty_Title, 0, I18N("Edit CSV Profile"), 0); /* setup dialog widgets */ s=GWEN_DB_GetCharValue(xdlg->dbProfile, "name", 0, NULL); if (s && *s) GWEN_Dialog_SetCharProperty(dlg, "nameEdit", GWEN_DialogProperty_Value, 0, s, 0); s=GWEN_DB_GetCharValue(xdlg->dbProfile, "version", 0, NULL); if (s && *s) GWEN_Dialog_SetCharProperty(dlg, "versionEdit", GWEN_DialogProperty_Value, 0, s, 0); s=GWEN_DB_GetCharValue(xdlg->dbProfile, "shortDescr", 0, NULL); if (s && *s) GWEN_Dialog_SetCharProperty(dlg, "shortDescrEdit", GWEN_DialogProperty_Value, 0, s, 0); s=GWEN_DB_GetCharValue(xdlg->dbProfile, "longDescr", 0, NULL); if (s && *s) GWEN_Dialog_SetCharProperty(dlg, "longDescrEdit", GWEN_DialogProperty_Value, 0, s, 0); i=GWEN_DB_GetIntValue(xdlg->dbProfile, "import", 0, 1); GWEN_Dialog_SetIntProperty(dlg, "importCheck", GWEN_DialogProperty_Value, 0, i?1:0, 0); i=GWEN_DB_GetIntValue(xdlg->dbProfile, "export", 0, 1); GWEN_Dialog_SetIntProperty(dlg, "exportCheck", GWEN_DialogProperty_Value, 0, i?1:0, 0); GWEN_Dialog_SetIntProperty(dlg, "ignoreLinesSpin", GWEN_DialogProperty_MinValue, 0, 0, 0); GWEN_Dialog_SetIntProperty(dlg, "ignoreLinesSpin", GWEN_DialogProperty_MaxValue, 0, 1000, 0); i=GWEN_DB_GetIntValue(xdlg->dbProfile, "params/ignoreLines", 0, 0); GWEN_Dialog_SetIntProperty(dlg, "ignoreLinesSpin", GWEN_DialogProperty_Value, 0, i, 0); i=GWEN_DB_GetIntValue(xdlg->dbProfile, "params/title", 0, 0); GWEN_Dialog_SetIntProperty(dlg, "headerCheck", GWEN_DialogProperty_Value, 0, i?1:0, 0); i=GWEN_DB_GetIntValue(xdlg->dbProfile, "params/quote", 0, 1); GWEN_Dialog_SetIntProperty(dlg, "quoteCheck", GWEN_DialogProperty_Value, 0, i?1:0, 0); /* setup delimiter combo box */ s=GWEN_DB_GetCharValue(xdlg->dbProfile, "params/delimiter", 0, NULL); setUpComboFromDoubleStrings(dlg, "delimiterCombo", csv_delimiters, s); /* setup subject combo box */ s=GWEN_DB_GetCharValue(xdlg->dbProfile, "subject", 0, NULL); setUpComboFromDoubleStrings(dlg, "subjectCombo", csv_subjects, s); /* setup date format combo box */ s=GWEN_DB_GetCharValue(xdlg->dbProfile, "dateFormat", 0, NULL); setUpComboFromSingleStrings(dlg, "dateFormatCombo", csv_dateFormats, s); /* setup amount format combo box */ s=GWEN_DB_GetCharValue(xdlg->dbProfile, "valueFormat", 0, NULL); setUpComboFromDoubleStrings(dlg, "amountFormatCombo", csv_amountFormats, s); /* setup columns page */ for (i=0; i<DIALOG_MAX_COLUMNS; i++) { char varName[32]; char comboName[32]; char editName[32]; snprintf(varName, sizeof(varName)-1, "params/columns/%d", i+1); snprintf(comboName, sizeof(comboName)-1, "col%dCombo", i+1); snprintf(editName, sizeof(editName)-1, "col%dDataEdit", i+1); s=GWEN_DB_GetCharValue(xdlg->dbProfile, varName, 0, NULL); setUpComboFromDoubleStrings(dlg, comboName, csv_columns, s); } if (xdlg->testFileName) readTestData(dlg); }