Matrix<unsigned> TestingAnalysis::calculate_confusion_binary_classification(const Matrix<double>& actual_data, const Matrix<double>& predicted_data) const { const unsigned rows_number = actual_data.get_rows_number(); Matrix<unsigned> confusion(2, 2, 0); unsigned actual_index = 0; unsigned predicted_index = 0; for(unsigned i = 0; i < rows_number; i++) { if(actual_data[i][0] < 0.5) { actual_index = 0; } else { actual_index = 1; } if(predicted_data[i][0] < 0.5) { predicted_index = 0; } else { predicted_index = 1; } confusion[actual_index][predicted_index]++; } return(confusion); }
ptr tex::prune_page_top(ptr p) { mcell m; ptr prev_p; ptr q, s, t; t = (ptr)&m; prev_p = t; link(t) = p; while (p != null) { switch (type(p)) { case HLIST_NODE: case VLIST_NODE: case RULE_NODE: q = new_skip_param(SPLIT_TOP_SKIP_CODE); link(prev_p) = q; link(q) = p; s = glue_ptr(q); if (glue_width(s) > box_height(p)) { glue_width(s) -= box_height(p); } else { glue_width(s) = 0; } p = null; break; case WHATSIT_NODE: case MARK_NODE: case INS_NODE: prev_p = p; p = link(p); break; case GLUE_NODE: case KERN_NODE: case PENALTY_NODE: q = p; p = link(p); link(q) = null; link(prev_p) = p; flush_node_list(q); break; default: confusion("pruning"); break; } } return (link(t)); }
void tex::resume_after_display () { if (cur_group != MATH_SHIFT_GROUP) confusion("display"); unsave(); prev_graf += 3; push_nest(); mode = HMODE; space_factor = 1000; clang = 0; scan_optional_space(); if (nest_ptr == nest + 1) build_page(); }
void tex::change_if_limit(int l, ptr p) { ptr q; if (p == cond_ptr) { if_limit = l; } else { q = cond_ptr; loop { if (q == null) confusion("if"); if (link(q) == p) { type(q) = l; return; } q = link(q); } } }
Matrix<unsigned> TestingAnalysis::calculate_confusion_multiple_classification(const Matrix<double>& actual_data, const Matrix<double>& predicted_data) const { const unsigned rows_number = actual_data.get_rows_number(); const unsigned columns_number = actual_data.get_columns_number(); Matrix<unsigned> confusion(columns_number, columns_number, 0); unsigned actual_index = 0; unsigned predicted_index = 0; for(unsigned i = 0; i < rows_number; i++) { actual_index = actual_data.arrange_row(i).calculate_maximal_index(); predicted_index = predicted_data.arrange_row(i).calculate_maximal_index(); confusion[actual_index][predicted_index]++; } return(confusion); }
void #line 268 "./cwebdir/ctang-w2c.ch" output_defs P1H(void) #line 608 "./cwebdir/ctangle.w" { sixteen_bits a; push_level(NULL); for(cur_text= text_info+1;cur_text<text_ptr;cur_text++) if(cur_text->text_link==0){ cur_byte= cur_text->tok_start; cur_end= (cur_text+1)->tok_start; C_printf("%s","#define "); out_state= normal; protect= 1; while(cur_byte<cur_end){ a= *cur_byte++; if(cur_byte==cur_end&&a=='\n')break; if(out_state==verbatim&&a!=string&&a!=constant&&a!='\n') C_putc(a); else if(a<0200)out_char(a); else{ a= (a-0200)*0400+*cur_byte++; if(a<024000){ cur_val= a;out_char(identifier); } else if(a<050000){confusion("macro defs have strange char");} else{ cur_val= a-050000;cur_section= cur_val;out_char(section_number); } } } protect= 0; flush_buffer(); } pop_level(0); }
ptr tex::fin_mlist(ptr p) { ptr q; if (incompleat_noad != null) { math_type(denominator(incompleat_noad)) = SUB_MLIST; math_link(denominator(incompleat_noad)) = link(head); if (p == null) { q = incompleat_noad; } else { q = info(numerator(incompleat_noad)); if (type(q) != LEFT_NOAD) confusion("right"); math_link(numerator(incompleat_noad)) = link(q); link(q) = incompleat_noad; link(incompleat_noad) = p; } } else { link(tail) = p; q = link(head); } pop_nest(); return q; }
void do_extension(int immediate) { halfword p; if(cur_cmd==extension_cmd){ switch(cur_chr){ case open_code: p= tail; new_write_whatsit(open_node_size,1); scan_optional_equals(); scan_file_name(); open_name(tail)= cur_name; open_area(tail)= cur_area; open_ext(tail)= cur_ext; if(immediate){ out_what(static_pdf,tail); flush_node_list(tail); tail= p; vlink(p)= null; } break; case write_code: p= tail; new_write_whatsit(write_node_size,0); cur_cs= write_stream(tail); scan_toks(false,false); write_tokens(tail)= def_ref; if(immediate){ out_what(static_pdf,tail); flush_node_list(tail); tail= p; vlink(p)= null; } break; case close_code: p= tail; new_write_whatsit(close_node_size,1); write_tokens(tail)= null; if(immediate){ out_what(static_pdf,tail); flush_node_list(tail); tail= p; vlink(p)= null; } break; case special_code: new_whatsit(special_node); write_stream(tail)= null; p= scan_toks(false,true); write_tokens(tail)= def_ref; break; case immediate_code: get_x_token(); do_extension(1); break; case use_box_resource_code: case use_image_resource_code: case save_box_resource_code: case save_image_resource_code: switch(get_o_mode()){ case OMODE_DVI: do_resource_dvi(immediate,cur_chr); break; case OMODE_PDF: do_resource_pdf(immediate,cur_chr); break; default: break; } break; case dvi_extension_code: if(get_o_mode()==OMODE_DVI) do_extension_dvi(immediate); break; case pdf_extension_code: if(get_o_mode()==OMODE_PDF) do_extension_pdf(immediate); break; default: if(immediate){ back_input(); }else{ confusion("invalid extension"); } break; } }else{ back_input(); } }
void pdf_vlist_out (void) { scaled left_edge; scaled top_edge; scaled save_h, save_v; pointer this_box; // glue_ord g_order; int g_order; // char g_sign; int g_sign; pointer p; integer save_loc; pointer leader_box; scaled leader_ht; scaled lx; boolean outer_doing_leaders; scaled edge; real glue_temp; real cur_glue; scaled cur_g; cur_g = 0; cur_glue = 0.0; this_box = temp_ptr; g_order = glue_order(this_box); g_sign = glue_sign(this_box); p = list_ptr(this_box); incr(cur_s); if (cur_s > max_push) max_push = cur_s; save_loc = dvi_offset + dvi_ptr; left_edge = cur_h; cur_v = cur_v - height(this_box); top_edge = cur_v; while (p != 0) { if (is_char_node(p)) { confusion("vlistout"); return; } else { switch (type(p)) { case hlist_node: case vlist_node: if (list_ptr(p) == 0) cur_v = cur_v + height(p) + depth(p); else { cur_v = cur_v + height(p); pdf_synch_v(); save_h = dvi_h; save_v = dvi_v; cur_h = left_edge + shift_amount(p); temp_ptr = p; if (type(p) == vlist_node) pdf_vlist_out(); else pdf_hlist_out(); dvi_h = save_h; dvi_v = save_v; cur_v = save_v + depth(p); cur_h = left_edge; } break; case rule_node: { rule_ht = height(p); rule_dp = depth(p); rule_wd = width(p); goto fin_rule; } break; case whatsit_node: out_what(p); break; case glue_node: { g = glue_ptr(p); rule_ht = width(g) - cur_g; if (g_sign != normal) { if (g_sign == stretching) { if (stretch_order(g) == g_order) { cur_glue = cur_glue + stretch(g); vet_glue(glue_set(this_box) * cur_glue); cur_g = round(glue_temp); } } else if (shrink_order(g) == g_order) /* BUG FIX !!! */ { cur_glue = cur_glue - shrink(g); vet_glue(glue_set(this_box) * cur_glue); cur_g = round(glue_temp); } } rule_ht = rule_ht + cur_g; if (subtype(p) >= a_leaders) { leader_box = leader_ptr(p); if (type(leader_box) == rule_node) { rule_wd = width(leader_box); rule_dp = 0; goto fin_rule; } leader_ht = height(leader_box) + depth(leader_box); if ((leader_ht > 0) && (rule_ht > 0)) { rule_ht = rule_ht + 10; edge = cur_v + rule_ht; lx = 0; if (subtype(p) == a_leaders) { save_v = cur_v; cur_v = top_edge + leader_ht * ((cur_v - top_edge) / leader_ht); if (cur_v < save_v) cur_v = cur_v + leader_ht; } else { lq = rule_ht / leader_ht; lr = rule_ht % leader_ht; if (subtype(p) == c_leaders) cur_v = cur_v + (lr / 2); else { lx = (2 * lr + lq + 1) / (2 * lq + 2); cur_v = cur_v + ((lr - (lq - 1) * lx) / 2); } } while (cur_v + leader_ht <= edge) { cur_h = left_edge + shift_amount(leader_box); pdf_synch_h(); save_h = dvi_h; cur_v = cur_v + height(leader_box); pdf_synch_v(); save_v = dvi_v; temp_ptr = leader_box; outer_doing_leaders = doing_leaders; doing_leaders = true; if (type(leader_box) == vlist_node) pdf_vlist_out(); else pdf_hlist_out(); doing_leaders = outer_doing_leaders; dvi_v = save_v; dvi_h = save_h; cur_h = left_edge; cur_v = save_v - height(leader_box) + leader_ht + lx; } cur_v = edge - 10; goto next_p; } } goto move_past; } break; case kern_node: cur_v = cur_v + width(p); break; default: break; } goto next_p; fin_rule: if (is_running(rule_wd)) rule_wd = width(this_box); rule_ht = rule_ht + rule_dp; cur_v = cur_v + rule_ht; if ((rule_ht > 0) && (rule_wd > 0)) { pdf_synch_h(); pdf_synch_v(); pdf_dev_set_rule(dvi_h, -dvi_v, rule_wd, rule_ht); } goto next_p; move_past: cur_v = cur_v + rule_ht; } next_p: p = link(p); } prune_movements(save_loc); decr(cur_s); }
void tex::build_page () { int pi=0, b, c; ptr p, q, r; #define INF_SHRINK_PAGE "Infinite glue shrinkage found on current page" if (link(contrib_head) == null || output_active) return; do { p = link(contrib_head); if (last_glue != null) delete_glue_ref(last_glue); last_penalty = 0; last_kern = 0; if (type(p) == GLUE_NODE) { last_glue = glue_ptr(p); add_glue_ref(last_glue); } else { last_glue = null; if (type(p) == PENALTY_NODE) { last_penalty = penalty(p); } else if (type(p) == KERN_NODE) { last_kern = kern_width(p); } } switch (type(p)) { case HLIST_NODE: case VLIST_NODE: case RULE_NODE: if (page_contents < BOX_THERE) { if (page_contents == EMPTY) { freeze_page_specs(BOX_THERE); } else { page_contents = BOX_THERE; } q = new_skip_param(TOP_SKIP_CODE); link(q) = p; link(contrib_head) = q; r = glue_ptr(q); if (glue_width(r) > box_height(p)) { glue_width(r) -= box_height(p); } else { glue_width(r) = 0; } continue; } else { page_total += page_depth + box_height(p); page_depth = box_depth(p); goto contribute; } case GLUE_NODE: if (page_contents < BOX_THERE) { goto done; } else if (precedes_break(page_tail)) { pi = 0; } else { goto update_heights; } break; case KERN_NODE: if (page_contents < BOX_THERE) { goto done; } else if (link(p) == null) { return; } else if (type(link(p)) == GLUE_NODE) { pi = 0; } else { goto update_heights; } break; case PENALTY_NODE: if (page_contents < BOX_THERE) { goto done; } else { pi = penalty(p); } break; case WHATSIT_NODE: goto contribute; case MARK_NODE: goto contribute; case INS_NODE: insert_page(p); goto contribute; default: confusion("page"); break; } if (pi < INF_PENALTY) { b = page_badness(); if (b < AWFUL_BAD) { if (pi <= EJECT_PENALTY) { c = pi; } else if (b < INF_BAD) { c = b + pi + insert_penalties; } else { c = DEPLORABLE; } } else { c = b; } if (insert_penalties >= 10000) c = AWFUL_BAD; if (tracing_pages > 0) show_page_stats(b, pi, c); if (c <= least_page_cost) { best_page_break = p; best_size = page_goal; least_page_cost = c; r = link(page_ins_head); while (r != page_ins_head) { best_ins_ptr(r) = last_ins_ptr(r); r = link(r); } } if (c == AWFUL_BAD || pi <= EJECT_PENALTY) { fire_up(p); if (output_active) return; continue; } } if (type(p) < GLUE_NODE || type(p) > KERN_NODE) { goto contribute; } update_heights: if (type(p) == KERN_NODE) { page_total += page_depth + kern_width(p); } else { q = glue_ptr(p); page_so_far[2 + stretch_order(q)] += stretch(q); page_shrink += shrink(q); if (shrink_order(q) != NORMAL && shrink(q) != 0) { print_err(INF_SHRINK_PAGE); help_inf_shrink_page(); error(); r = new_spec(q); shrink_order(r) = NORMAL; delete_glue_ref(q); q = glue_ptr(p) = r; } page_total += page_depth + glue_width(q); } page_depth = 0; contribute: if (page_depth > page_max_depth) { page_total = page_total + page_depth - page_max_depth; page_depth = page_max_depth; } page_tail = link(page_tail) = p; link(contrib_head) = link(p); link(p) = null; continue; done: link(contrib_head) = link(p); link(p) = null; flush_node_list(p); } while (link(contrib_head) != null); if (nest_ptr == nest) { tail = contrib_head; } else { contrib_tail = contrib_head; } }
ptr tex::vert_break(ptr p, scal h, scal d) { int b; ptr q; ptr r; int t; int pi=0; ptr prev_p; scal prev_dp; ptr best_place=0; int least_cost; #define INF_SHRINK_BOX "Infinite glue shrinkage found in box being split" prev_p = p; least_cost = AWFUL_BAD; do_all_six(set_height_zero); prev_dp = 0; loop { if (p == null) { pi = EJECT_PENALTY; } else { switch (type(p)) { case HLIST_NODE: case VLIST_NODE: case RULE_NODE: cur_height += prev_dp + box_height(p); prev_dp = box_depth(p); goto not_found; case WHATSIT_NODE: goto not_found; case GLUE_NODE: if (precedes_break(prev_p)) { pi = 0; } else { goto update_heights; } break; case KERN_NODE: if (link(p) == null) { t = PENALTY_NODE; } else { t = type(link(p)); } if (t == GLUE_NODE) { pi = 0; } else { goto update_heights; } break; case PENALTY_NODE: pi = penalty(p); break; case MARK_NODE: case INS_NODE: goto not_found; default: confusion("vertbreak"); } } if (pi < INF_PENALTY) { b = vert_badness(h); if (b < AWFUL_BAD) { if (pi <= EJECT_PENALTY) { b = pi; } else if (b < INF_BAD) { b += pi; } else { b = DEPLORABLE; } } if (b <= least_cost) { best_place = p; least_cost = b; best_height_plus_depth = cur_height + prev_dp; } if (b == AWFUL_BAD || pi <= EJECT_PENALTY) { return best_place; } } if (type(p) < GLUE_NODE || type(p) > KERN_NODE) { goto not_found; } update_heights: if (type(p) == KERN_NODE) { cur_height += prev_dp + kern_width(p); } else { q = glue_ptr(p); active_height[2 + stretch_order(q)] += stretch(q); active_height[6] += shrink(q); if (shrink_order(q) != NORMAL && shrink(q) != 0) { print_err(INF_SHRINK_BOX); help_inf_shrink_box(); error(); r = new_spec(q); delete_glue_ref(q); shrink_order(r) = NORMAL; glue_ptr(p) = r; } cur_height += prev_dp + glue_width(q); } prev_dp = 0; not_found: if (prev_dp > d) { cur_height = cur_height + prev_dp - d; prev_dp = d; } prev_p = p; p = link(prev_p); } }
void tex::handle_right_brace () { scal d; int f; ptr p; ptr q; switch (cur_group) { case SIMPLE_GROUP: unsave(); break; case BOTTOM_LEVEL: print_err("Too many }'s"); help_close_group(); error(); break; case SEMI_SIMPLE_GROUP: case MATH_SHIFT_GROUP: case MATH_LEFT_GROUP: extra_right_brace(); break; case HBOX_GROUP: package(0); break; case ADJUSTED_HBOX_GROUP: tex::adjust_tail = tex::adjust_head; package(0); break; case VBOX_GROUP: end_graf(); package(0); break; case VTOP_GROUP: end_graf(); package(VTOP_CODE); break; case INSERT_GROUP: end_graf(); q = split_top_skip; add_glue_ref(q); d = split_max_depth; f = floating_penalty; unsave(); decr(save_ptr); p = vpack(link(head), 0, ADDITIONAL); pop_nest(); if (saved(0) < 255) { tail_append(new_node(INS_NODE_SIZE)); type(tail) = INS_NODE; subtype(tail) = saved(0); ins_height(tail) = box_height(p) + box_depth(p); ins_ptr(tail) = list_ptr(p); split_top_ptr(tail) = q; ins_depth(tail) = d; float_cost(tail) = f; } else { tail_append(new_node(SMALL_NODE_SIZE)); type(tail) = ADJUST_NODE; subtype(tail) = 0; adjust_ptr(tail) = list_ptr(p); delete_glue_ref(q); } free_node(p, BOX_NODE_SIZE); if (nest_ptr == nest) build_page(); break; case OUTPUT_GROUP: if (loc != null || (token_type != OUTPUT_TEXT && token_type != BACKED_UP)) { print_err("Unbalanced output routine"); help_output_balance(); error(); do get_token(); while (loc != null); } end_token_list(); end_graf(); unsave(); output_active = FALSE; insert_penalties = 0; if (box(255) != null) { print_err("Output routine didn't use all of "); print_esc("box255"); help_output(); box_error(255); } if (tail != head) { link(page_tail) = link(head); page_tail = tail; } if (link(page_head) != null) { if (link(contrib_head) == null) contrib_tail = page_tail; link(page_tail) = link(contrib_head); link(contrib_head) = link(page_head); link(page_head) = null; page_tail = page_head; } pop_nest(); build_page(); break; case DISC_GROUP: build_discretionary(); break; case ALIGN_GROUP: back_input(); cur_tok = sym2tok(FROZEN_CR); print_err("Missing "); print_esc("cr"); print(" inserted"); help_align_cr(); ins_error(); break; case NO_ALIGN_GROUP: end_graf(); unsave(); align_peek(); break; case VCENTER_GROUP: end_graf(); unsave(); save_ptr -= 2; p = vpackage(link(head), saved(1), saved(0), MAX_DIMEN); pop_nest(); tail_append(new_noad()); type(tail) = VCENTER_NOAD; math_type(nucleus(tail)) = SUB_BOX; info(nucleus(tail)) = p; break; case MATH_CHOICE_GROUP: build_choices(); break; case MATH_GROUP: unsave(); decr(save_ptr); math_type(saved(0)) = SUB_MLIST; p = fin_mlist(null); math_link(saved(0)) = p; if (p != null) { if (link(p) == null) { if (type(p) == ORD_NOAD) { if (math_type(subscr(p)) == EMPTY && math_type(supscr(p)) == EMPTY) { mcopy(saved(0), nucleus(p)); free_node(p, NOAD_SIZE); } } else if (type(p) == ACCENT_NOAD && saved(0) == nucleus(tail) && type(tail) == ORD_NOAD) { q = head; while (link(q) != tail) q = link(q); link(q) = p; free_node(tail, NOAD_SIZE); tail = p; } } } break; default: confusion("rightbrace"); break; } }
int main(int argc, char **argv) { verbose = false; int insts; // Opening and reading config file. FILE *cfgfile = fopen(argv[1], "r"); if(!cfgfile) { printf("Error: could not open config file.\n"); return 1; } fscanf(cfgfile, "%d", &objc); if(objc <= 0) { printf("Error: objc <= 0.\n"); return 2; } int labels[objc]; // reading labels int classc; fscanf(cfgfile, "%d", &classc); size_t i; for(i = 0; i < objc; ++i) { fscanf(cfgfile, "%d", &labels[i]); } // reading labels end fscanf(cfgfile, "%d", &dmatrixc); if(dmatrixc <= 0) { printf("Error: dmatrixc <= 0.\n"); return 2; } char dmtx_file_name[dmatrixc][BUFF_SIZE]; size_t j; for(j = 0; j < dmatrixc; ++j) { fscanf(cfgfile, "%s", dmtx_file_name[j]); } char out_file_name[BUFF_SIZE]; fscanf(cfgfile, "%s", out_file_name); fscanf(cfgfile, "%d", &clustc); if(clustc <= 0) { printf("Error: clustc <= 0.\n"); return 2; } fscanf(cfgfile, "%d", &medoids_card); if(medoids_card <= 0) { printf("Error: medoids_card <= 0.\n"); return 2; } fscanf(cfgfile, "%d", &insts); if(insts <= 0) { printf("Error: insts <= 0.\n"); return 2; } fscanf(cfgfile, "%lf", &theta); if(dlt(theta, 0.0)) { printf("Error: theta < 0.\n"); return 2; } fscanf(cfgfile, "%d", &max_iter); fscanf(cfgfile, "%lf", &epsilon); if(dlt(epsilon, 0.0)) { printf("Error: epsilon < 0.\n"); return 2; } fscanf(cfgfile, "%lf", &mfuz); if(!dgt(mfuz, 0.0)) { printf("Error: mfuz <= 0.\n"); return 2; } fclose(cfgfile); // Done reading config file. freopen(out_file_name, "w", stdout); mfuzval = 1.0 / (mfuz - 1.0); printf("######Config summary:######\n"); printf("Number of clusters: %d.\n", clustc); printf("Medoids cardinality: %d.\n", medoids_card); printf("Number of iterations: %d.\n", max_iter); printf("Epsilon: %.15lf.\n", epsilon); printf("Theta: %.15lf.\n", theta); printf("Parameter m: %.15lf.\n", mfuz); printf("Number of instances: %d.\n", insts); printf("###########################\n"); size_t k; // Allocating memory start parc_cluster_adeq = malloc(sizeof(double) * clustc); parc_obj_adeq = malloc(sizeof(double) * objc); dmatrix = malloc(sizeof(double **) * dmatrixc); for(j = 0; j < dmatrixc; ++j) { dmatrix[j] = malloc(sizeof(double *) * objc); for(i = 0; i < objc; ++i) { dmatrix[j][i] = malloc(sizeof(double) * objc); } } medoids = malloc(sizeof(size_t **) * clustc); size_t ***best_medoids = malloc(sizeof(size_t **) * clustc); for(k = 0; k < clustc; ++k) { medoids[k] = malloc(sizeof(size_t *) * dmatrixc); best_medoids[k] = malloc(sizeof(size_t *) * dmatrixc); for(j = 0; j < dmatrixc; ++j) { medoids[k][j] = malloc(sizeof(size_t) * medoids_card); best_medoids[k][j] = malloc(sizeof(size_t) * medoids_card); } } weights = malloc(sizeof(double *) * clustc); double **best_weights = malloc(sizeof(double *) * clustc); for(k = 0; k < clustc; ++k) { weights[k] = malloc(sizeof(double) * dmatrixc); best_weights[k] = malloc(sizeof(double) * dmatrixc); } memb = malloc(sizeof(double *) * objc); double **best_memb = malloc(sizeof(double *) * objc); for(i = 0; i < objc; ++i) { memb[i] = malloc(sizeof(double) * clustc); best_memb[i] = malloc(sizeof(double) * clustc); } // Allocating memory end for(j = 0; j < dmatrixc; ++j) { if(!load_data(dmtx_file_name[j], dmatrix[j], objc, objc)) { printf("Error: could not load %s.\n", dmtx_file_name[j]); goto END; } } size_t best_inst; double best_inst_adeq; double cur_inst_adeq; srand(time(NULL)); // Random seed. // Start main program loop. for(i = 1; i <= insts; ++i) { printf("Instance %u:\n", i); cur_inst_adeq = run(); if(i == 1 || cur_inst_adeq < best_inst_adeq) { // Saves the best configuration based on the adequacy. mtxcpy_d(best_memb, memb, objc, clustc); mtxcpy_d(best_weights, weights, clustc, dmatrixc); for(k = 0; k < clustc; ++k) { mtxcpy_size_t(best_medoids[k], medoids[k], dmatrixc, medoids_card); } best_inst_adeq = cur_inst_adeq; best_inst = i; } } // Print the best configuration, confusion matrix and the CR // index. printf("\n"); printf("Best adequacy %.15lf on instance %d.\n", best_inst_adeq, best_inst); printf("\n"); print_medoids(best_medoids); printf("\n"); print_memb(best_memb); printf("\n"); print_weights(best_weights); printf("\n"); global_energy(); printf("\n"); int *pred = defuz(memb, objc, clustc); print_groups(pred, objc, clustc); double **confmtx = confusion(pred, labels, objc); printf("\nConfusion matrix (class x predicted):\n"); print_mtx_d(confmtx, classc, classc, 0); ++classc; for(i = 0; i < classc; ++i) { free(confmtx[i]); } free(confmtx); printf("Corrected Rand: %.7lf\n", corand(pred, labels, objc)); free(pred); // Freeing memory. END: fclose(stdout); for(i = 0; i < dmatrixc; ++i) { for(j = 0; j < objc; ++j) { free(dmatrix[i][j]); } free(dmatrix[i]); } free(dmatrix); for(k = 0; k < clustc; ++k) { for(j = 0; j < dmatrixc; ++j) { free(medoids[k][j]); free(best_medoids[k][j]); } free(medoids[k]); free(best_medoids[k]); free(weights[k]); free(best_weights[k]); } free(medoids); free(best_medoids); free(weights); free(best_weights); for(i = 0; i < objc; ++i) { free(memb[i]); free(best_memb[i]); } free(memb); free(best_memb); free(parc_cluster_adeq); free(parc_obj_adeq); return 0; }
ptr tex::copy_node_list(ptr p) { ptr h; ptr q; ptr r=0; h = q = new_avail(); while (p != null) { if (is_char_node(p)) { r = new_avail(); font(r) = font(p); character(r) = character(p); } else { switch (type(p)) { case HLIST_NODE: case VLIST_NODE: case UNSET_NODE: r = tex::new_node(BOX_NODE_SIZE); memcpy((void *)r, (void *)p, BOX_NODE_SIZE); list_ptr(r) = copy_node_list(list_ptr(p)); break; case RULE_NODE: r = tex::new_node(RULE_NODE_SIZE); memcpy((void *)r, (void *)p, RULE_NODE_SIZE); break; case INS_NODE: r = tex::new_node(INS_NODE_SIZE); memcpy((void *)r, (void *)p, INS_NODE_SIZE); add_glue_ref(split_top_ptr(p)); ins_ptr(r) = copy_node_list(ins_ptr(p)); break; case WHATSIT_NODE: r = copy_whatsit(p); break; case GLUE_NODE: r = tex::new_node(SMALL_NODE_SIZE); memcpy((void *)r, (void *)p, SMALL_NODE_SIZE); add_glue_ref(glue_ptr(p)); glue_ptr(r) = glue_ptr(p); leader_ptr(r) = copy_node_list(leader_ptr(p)); break; case KERN_NODE: case MATH_NODE: case PENALTY_NODE: r = tex::new_node(SMALL_NODE_SIZE); memcpy((void *)r, (void *)p, SMALL_NODE_SIZE); break; case LIGATURE_NODE: r = tex::new_node(SMALL_NODE_SIZE); memcpy((void *)r, (void *)p, SMALL_NODE_SIZE); lig_ptr(r) = copy_node_list(lig_ptr(p)); break; case DISC_NODE: r = tex::new_node(SMALL_NODE_SIZE); memcpy((void *)r, (void *)p, SMALL_NODE_SIZE); pre_break(r) = copy_node_list(pre_break(p)); post_break(r) = copy_node_list(post_break(p)); break; case MARK_NODE: r = tex::new_node(SMALL_NODE_SIZE); memcpy((void *)r, (void *)p, SMALL_NODE_SIZE); add_token_ref(mark_ptr(p)); break; case ADJUST_NODE: r = tex::new_node(SMALL_NODE_SIZE); memcpy((void *)r, (void *)p, SMALL_NODE_SIZE); adjust_ptr(r) = copy_node_list(adjust_ptr(p)); break; default: confusion("copying"); break; } } q = link(q) = r; p = link(p); } link(q) = null; q = link(h); free_avail(h); return q; }
void tex::flush_node_list(ptr p) { ptr q; while (p != null) { q = link(p); if (is_char_node(p)) { free_avail(p); } else { switch (type(p)) { case HLIST_NODE: case VLIST_NODE: case UNSET_NODE: flush_node_list(list_ptr(p)); free_node(p, BOX_NODE_SIZE); goto done; case RULE_NODE: free_node(p, RULE_NODE_SIZE); goto done; case INS_NODE: flush_node_list(ins_ptr(p)); delete_glue_ref(split_top_ptr(p)); free_node(p, INS_NODE_SIZE); goto done; case WHATSIT_NODE: free_whatsit(p); goto done; case GLUE_NODE: fast_delete_glue_ref(glue_ptr(p)); if (leader_ptr(p) != null) flush_node_list(leader_ptr(p)); break; case KERN_NODE: case MATH_NODE: case PENALTY_NODE: break; case LIGATURE_NODE: flush_node_list(lig_ptr(p)); break; case MARK_NODE: delete_token_ref(mark_ptr(p)); break; case DISC_NODE: flush_node_list(pre_break(p)); flush_node_list(post_break(p)); break; case ADJUST_NODE: flush_node_list(adjust_ptr(p)); break; case STYLE_NODE: free_node(p, STYLE_NODE_SIZE); goto done; case CHOICE_NODE: flush_node_list(display_mlist(p)); flush_node_list(text_mlist(p)); flush_node_list(script_mlist(p)); flush_node_list(script_script_mlist(p)); free_node(p, STYLE_NODE_SIZE); goto done; case ORD_NOAD: case OP_NOAD: case BIN_NOAD: case REL_NOAD: case OPEN_NOAD: case CLOSE_NOAD: case PUNCT_NOAD: case INNER_NOAD: case RADICAL_NOAD: case OVER_NOAD: case UNDER_NOAD: case VCENTER_NOAD: case ACCENT_NOAD: if (math_type(nucleus(p)) >= SUB_BOX) flush_node_list(math_link(nucleus(p))); if (math_type(supscr(p)) >= SUB_BOX) flush_node_list(math_link(supscr(p))); if (math_type(subscr(p)) >= SUB_BOX) flush_node_list(math_link(subscr(p))); if (type(p) == RADICAL_NOAD) free_node(p, RADICAL_NOAD_SIZE); else if (type(p) == ACCENT_NOAD) free_node(p, ACCENT_NOAD_SIZE); else free_node(p, NOAD_SIZE); goto done; case LEFT_NOAD: case RIGHT_NOAD: free_node(p, NOAD_SIZE); goto done; case FRACTION_NOAD: flush_node_list(math_link(numerator(p))); flush_node_list(math_link(denominator(p))); free_node(p, FRACTION_NOAD_SIZE); goto done; default: confusion("flushing"); break; } free_node(p, SMALL_NODE_SIZE); done:; } p = q; } }