int main(void) { // List의 생성 및 초기화 //////////// List list; int data; ListInit(&list); SetSortRule(&list, WhoIsPrecede); // 5개의 데이터 저장 /////////////// LInsert(&list, 11); LInsert(&list, 11); LInsert(&list, 22); LInsert(&list, 22); LInsert(&list, 33); // 저장된 데이터의 전체 출력 //////////// printf("현재 데이터의 수: %d \n", LCount(&list)); if(LFirst(&list, &data)) { printf("%d ", data); while(LNext(&list, &data)) printf("%d ", data); } printf("\n\n"); // 숫자 22을 검색하여 모두 삭제 //////////// if(LFirst(&list, &data)) { if(data == 22) LRemove(&list); while(LNext(&list, &data)) { if(data == 22) LRemove(&list); } } // 삭제 후 저장된 데이터 전체 출력 //////////// printf("현재 데이터의 수: %d \n", LCount(&list)); if(LFirst(&list, &data)) { printf("%d ", data); while(LNext(&list, &data)) printf("%d ", data); } printf("\n\n"); return 0; }
int main(void){ //ArrayList Create and Init List list; int data; ListInit(&list); LInsert(&list, 11);LInsert(&list, 11); LInsert(&list, 22);LInsert(&list, 22); LInsert(&list, 33); //Saved data print printf("Present Data Count : %d\n",LCount(&list)); if(LFirst(&list, &data)){ printf("%d ", data); while(LNext(&list, &data)){ printf("%d ", data); } } printf("\n\n"); // Search 22 and Delete if(LFirst(&list, &data)){ if(data == 22) LRemove(&list); while(LNext(&list, &data)){ if(data == 22) LRemove(&list); } } //Presend Data Count printf("Present Data Count: %d\n",LCount(&list)); if(LFirst(&list, &data)){ printf("%d ", data); while(LNext(&list, &data)){ printf("%d ", data); } } printf("\n\n"); return 0; }
int main(){ List list; int data; ListInit(&list); LInsert(&list, 11);LInsert(&list, 11); LInsert(&list, 22);LInsert(&list, 22); LInsert(&list, 33); printf("Present Data Count : %d\n", LCount(&list)); if(LFirst(&list, &data)){ printf("%d ", data); while(LNext(&list, &data)) printf("%d ", data); } printf("\n\n"); if(LFirst(&list, &data)){ if(data == 22) LRemove(&list); while(LNext(&list, &data)){ if(data == 22) LRemove(&list); } } printf("Present Data Count : %d\n",LCount(&list)); if(LFirst(&list, &data)){ printf("%d ", data); while(LNext(&list, &data)) printf("%d ", data); } printf("\n\n"); return 0; }
int main() { /// 리스트의 생성 과 초기화 List list; int data; ListInit(&list); // 5개의 데이터를 저장한다. ListInsert(&list, 11); ListInsert(&list, 11); ListInsert(&list, 22); ListInsert(&list, 22); ListInsert(&list, 33); printf("현재 데이터의수 : %d \n", LCount(&list)); if(LFirst(&list, &data)) { printf("%d ", data); while(LNext(&list, &data)) { printf("%d ", data); } } printf("\n\n"); if(LFirst(&list, &data)) { if(data == 22) LRemove(&list); while(LNext(&list, &data)) { if(data == 22) LRemove(&list); } } // 삭제를 하고 남아 있는 데이터 수 printf("현재 데이터의수 : %d \n", LCount(&list)); if(LFirst(&list, &data)) { printf("%d ", data); while(LNext(&list, &data)) { printf("%d ", data); } } printf("\n\n"); return 0; }
int main(void) { List list; Point comPos; // 비교할 좌표값 Point * ppos; ListInit(&list); //4개의 데이터 저장 ppos = (Point*)malloc(sizeof(Point)); SetPointPos(ppos, 2, 1); LInsert(&list, ppos); ppos = (Point*)malloc(sizeof(Point)); SetPointPos(ppos, 2, 2); LInsert(&list, ppos); ppos = (Point*)malloc(sizeof(Point)); SetPointPos(ppos, 3, 1); LInsert(&list, ppos); ppos = (Point*)malloc(sizeof(Point)); SetPointPos(ppos, 3, 2); LInsert(&list, ppos); // 저장된 데이터 출력 printf("현재 데이터의 수 : %d\n", LCount(&list)); if(LFirst(&list, & ppos)) { ShowPointpos(ppos); while(LNext(&list, &ppos)) ShowPointpos(ppos); } printf("\n"); // xpos가 (2 , 0)인 데이터는 모두 삭제를 하자 comPos.xpos =2; comPos.ypos = 0; if(LFirst(&list, &ppos)) { if(PointComp(ppos, &comPos) == 1) { ppos = LRemove(&list); free(ppos); } while(LNext(&list, &ppos)) { if(PointComp(ppos, &comPos) ==1) { ppos = LRemove(&list); free(ppos); } } } // 삭제를 하고 남아있는 데이터 수 printf("현재 데이터의 수 : %d\n", LCount(&list)); if(LFirst(&list, & ppos)) { ShowPointpos(ppos); while(LNext(&list, &ppos)) ShowPointpos(ppos); } printf("\n"); return 0; }
int main(){ List list; NameCard* pcard; NameCard chPhone; ListInit(&list); pcard = MakeNameCard("Phantom", "010-1111-2222"); LInsert(&list, pcard); pcard = MakeNameCard("HeadFish", "010-2222-3333"); LInsert(&list, pcard); pcard = MakeNameCard("Mathboy", "010-3333-4444"); LInsert(&list, pcard); printf("Present Data Count : %d\n", LCount(&list)); if(LFirst(&list, &pcard)){ ShowNameCardInfo(pcard); while(LNext(&list, &pcard)) ShowNameCardInfo(pcard); } printf("\n\n"); strcpy(chPhone.name, "Mathboy"); strcpy(chPhone.phone, "010-3333-4444"); if(LFirst(&list, &pcard)){ if(NameCompare(pcard, "Mathboy")==1){ ChangePhoneNum(pcard, "010-7777-8888"); } while(LNext(&list, &pcard)){ if(NameCompare(pcard, "Mathboy")==1){ ChangePhoneNum(pcard, "010-7777-8888"); } } } printf("Present Data Count : %d\n", LCount(&list)); if(LFirst(&list, &pcard)){ ShowNameCardInfo(pcard); while(LNext(&list, &pcard)) ShowNameCardInfo(pcard); } printf("\n\n"); if(LFirst(&list, &pcard)){ if(NameCompare(pcard, "Mathboy")==1){ pcard = LRemove(&list); free(pcard); } while(LNext(&list, &pcard)){ if(NameCompare(pcard, "Mathboy")==1){ pcard = LRemove(&list); free(pcard); } } } if(LFirst(&list, &pcard)){ ShowNameCardInfo(pcard); while(LNext(&list, &pcard)) ShowNameCardInfo(pcard); } printf("\n\n"); printf("Present Data Count : %d\n", LCount(&list)); return 0; }
int main(){ List list; Point compPos; Point *ppos; ListInit(&list); ppos=(Point*)malloc(sizeof(Point)); SetPointPos(ppos, 2, 1); LInsert(&list,ppos); ppos=(Point*)malloc(sizeof(Point)); SetPointPos(ppos, 2, 2); LInsert(&list,ppos); ppos=(Point*)malloc(sizeof(Point)); SetPointPos(ppos, 3, 1); LInsert(&list,ppos); ppos=(Point*)malloc(sizeof(Point)); SetPointPos(ppos, 3, 2); LInsert(&list,ppos); printf("Present Data Count : %d\n",LCount(&list)); if(LFirst(&list,&ppos)){ ShowPointPos(ppos); while(LNext(&list,&ppos)) ShowPointPos(ppos); } printf("\n"); compPos.xpos=2; compPos.ypos=0; if(LFirst(&list,&ppos)){ if(PointComp(ppos, &compPos)==1){ ppos=LRemove(&list); free(ppos); } while(LNext(&list,&ppos)){ if(PointComp(ppos, &compPos)==1){ ppos=LRemove(&list); free(ppos); } } } printf("Present Data Count : %d\n",LCount(&list)); if(LFirst(&list,&ppos)){ ShowPointPos(ppos); while(LNext(&list,&ppos)) ShowPointPos(ppos); } printf("\n"); return 0; }
int main(void) { // ArrayList 의 생성 및 초기화 List list; int data; ListInit(&list); // 5개의 데이터 저장 LInsert(&list, 11); LInsert(&list, 11); LInsert(&list, 22); LInsert(&list, 22); LInsert(&list, 33); // 저장된 데이터의 전체 출력 printf("현재 데이터의 수:%d \n", LCount(&list)); if (LFirst(&list, &data)) // 첫 번째 데이터 조회 { printf("%d ", data); while(LNext(&list, &data)) // 두 번째 이후의 데이터 조회 { printf("%d ", data); } } printf("\n\n"); // 숫자 22를 탐색하여 모두 삭제 if (LFirst(&list, &data)) { if (data == 22) { LRemove(&list); } while (LNext(&list, &data)) { if (data == 22) { LRemove(&list); } } } // 삭제 후 남은 데이터 전체 출력 printf("현재 데이터의 수: %d \n", LCount(&list)); if (LFirst(&list, &data)) { printf("%d ", data); while (LNext(&list, &data)) { printf("%d ", data); } } printf("\n\n"); return 0; }
int main(void) { List list; Point compPos; Point * ppos; ListInit(&list); /*** 4개의 데이터 저장 ***/ ppos = (Point*)malloc(sizeof(Point)); SetPointPos(ppos, 2, 1); LInsert(&list, ppos); ppos = (Point*)malloc(sizeof(Point)); SetPointPos(ppos, 2, 2); LInsert(&list, ppos); ppos = (Point*)malloc(sizeof(Point)); SetPointPos(ppos, 3, 1); LInsert(&list, ppos); ppos = (Point*)malloc(sizeof(Point)); SetPointPos(ppos, 3, 2); LInsert(&list, ppos); /*** 저장된 데이터의 출력 ***/ printf("현재 데이터의 수: %d \n", LCount(&list)); if(LFirst(&list, &ppos)) { ShowPointPos(ppos); while(LNext(&list, &ppos)) ShowPointPos(ppos); } printf("\n"); /*** xpos가 2인 모든 데이터 삭제 ***/ compPos.xpos=2; compPos.ypos=0; if(LFirst(&list, &ppos)) { if(PointComp(ppos, &compPos)==1) { ppos=LRemove(&list); free(ppos); } while(LNext(&list, &ppos)) { if(PointComp(ppos, &compPos)==1) { ppos=LRemove(&list); free(ppos); } } } /*** 삭제 후 남은 데이터 전체 출력 ***/ printf("현재 데이터의 수: %d \n", LCount(&list)); if(LFirst(&list, &ppos)) { ShowPointPos(ppos); while(LNext(&list, &ppos)) ShowPointPos(ppos); } printf("\n"); return 0; }
bool SplitEvaluatorMLClass<Sample, TAppContext>::CalculateEntropyAndThreshold(DataSet<Sample, LabelMLClass>& dataset, std::vector<std::pair<double, int> > responses, std::pair<double, double>& score_and_threshold, int use_gini) { // In: samples, sorted responses, out: optimality-measure + threshold // Initialize the counters double DGini, LGini, RGini, LTotal = 0.0, RTotal = 0.0, bestThreshold = 0.0, bestDGini = 1e16; vector<double> LCount(m_appcontext->num_classes, 0.0), RCount(m_appcontext->num_classes, 0.0); bool found = false; // Calculate random thresholds and sort them double min_response = responses[0].first; double max_response = responses[responses.size()-1].first; double d = (max_response - min_response); vector<double> random_thresholds(m_appcontext->num_node_thresholds, 0.0); for (int i = 0; i < random_thresholds.size(); i++) { random_thresholds[i] = (randDouble() * d) + min_response; } sort(random_thresholds.begin(), random_thresholds.end()); // First, put everything in the right node for (int r = 0; r < responses.size(); r++) { int labelIdx = dataset[responses[r].second]->m_label.class_label; double sample_w = dataset[responses[r].second]->m_label.class_weight; RCount[labelIdx] += sample_w; RTotal += sample_w; } // Now, iterate all responses and calculate Gini indices at the cutoff points (thresholds) int th_idx = 0; bool stop_search = false; for (int r = 0; r < responses.size(); r++) { // if the current sample is smaller than the current threshold put it to the left side if (responses[r].first <= random_thresholds[th_idx]) { double cur_sample_weight = dataset[responses[r].second]->m_label.class_weight; RTotal -= cur_sample_weight; if (RTotal < 0.0) RTotal = 0.0; LTotal += cur_sample_weight; int labelIdx = dataset[responses[r].second]->m_label.class_label; RCount[labelIdx] -= cur_sample_weight; if (RCount[labelIdx] < 0.0) RCount[labelIdx] = 0.0; LCount[labelIdx] += cur_sample_weight; } else { // ok, now we found the first sample having higher response than the current threshold // now, we have to check the Gini index, this would be a valid split LGini = 0.0, RGini = 0.0; if (use_gini) { for (int c = 0; c < LCount.size(); c++) { double pL = LCount[c]/LTotal, pR = RCount[c]/RTotal; if (LCount[c] >= 1e-10) // F**K YOU rounding errors LGini += pL * (1.0 - pL); if (RCount[c] >= 1e-10) RGini += pR * (1.0 - pR); } } else { for (int c = 0; c < LCount.size(); c++) { double pL = LCount[c]/LTotal, pR = RCount[c]/RTotal; if (LCount[c] >= 1e-10) // F**K YOU rounding errors LGini -= pL * log(pL); if (RCount[c] >= 1e-10) RGini -= pR * log(pR); } } DGini = (LTotal*LGini + RTotal*RGini)/(LTotal + RTotal); if (DGini < bestDGini && LTotal > 0.0 && RTotal > 0.0) { bestDGini = DGini; bestThreshold = random_thresholds[th_idx]; found = true; } // next, we have to find the next random threshold that is larger than the current response // -> there might be several threshold within the gap between the last response and this one. while (responses[r].first > random_thresholds[th_idx]) { if (th_idx < (random_thresholds.size()-1)) { th_idx++; // CAUTION::: THIS HAS TO BE INCLUDED !!!!!!!!!!!?????? r--; // THIS IS IMPORTANT, WE HAVE TO CHECK THE CURRENT SAMPLE AGAIN!!! } else { stop_search = true; break; // all thresholds tested } } // now, we can go on with the next response ... } if (stop_search) break; } score_and_threshold.first = bestDGini; score_and_threshold.second = bestThreshold; return found; }
bool SplitEvaluatorMLClass<Sample, TAppContext>::CalculateEntropyAndThresholdOrdinal(DataSet<Sample, LabelMLClass>& dataset, std::vector<std::pair<double, int> > responses, std::pair<double, double>& score_and_threshold, int use_gini) { // In: samples, sorted responses, out: optimality-measure + threshold double bestDGini = 1e16, bestThreshold = 0.0; bool found = false; // iterate the ordinal "thresholds", i.e., the indices 0 ... K-1 for (int t = 0; t < m_appcontext->ordinal_split_k; t++) { // now, find all samples with responses[:].first == t, and the other ones vector<double> LCount(m_appcontext->num_classes, 0.0), RCount(m_appcontext->num_classes, 0.0); double LTotal = 0.0, RTotal = 0.0; for (size_t s = 0; s < responses.size(); s++) { // get the infos of the current sample int labelIdx = dataset[responses[s].second]->m_label.class_label; double sample_w = dataset[responses[s].second]->m_label.class_weight; // check "threshold" if ((int)responses[s].first == t) { LCount[labelIdx] += sample_w; LTotal += sample_w; } else { RCount[labelIdx] += sample_w; RTotal += sample_w; } } // calculate purity measure (entropy or Gini) double LGini = 0.0, RGini = 0.0; if (use_gini) { for (int c = 0; c < LCount.size(); c++) { double pL = LCount[c]/LTotal, pR = RCount[c]/RTotal; if (LCount[c] >= 1e-10) // F**K YOU rounding errors LGini += pL * (1.0 - pL); if (RCount[c] >= 1e-10) RGini += pR * (1.0 - pR); } } else { for (int c = 0; c < LCount.size(); c++) { double pL = LCount[c]/LTotal, pR = RCount[c]/RTotal; if (LCount[c] >= 1e-10) // F**K YOU rounding errors LGini -= pL * log(pL); if (RCount[c] >= 1e-10) RGini -= pR * log(pR); } } double DGini = (LTotal*LGini + RTotal*RGini)/(LTotal + RTotal); if (DGini < bestDGini && LTotal > 0.0 && RTotal > 0.0) { bestDGini = DGini; bestThreshold = (double)t; found = true; } } score_and_threshold.first = bestDGini; score_and_threshold.second = bestThreshold; return found; }