bool Edgesort::IsValidEdge(const TopoDS_Edge& edge) { if ( edge.IsNull() ) return false; if ( BRep_Tool::Degenerated(edge) ) return false; BRepAdaptor_Curve bac(edge); Standard_Real fparam = bac.FirstParameter(); Standard_Real lparam = bac.LastParameter(); gp_Pnt fpoint = bac.Value(fparam); gp_Pnt lpoint = bac.Value(lparam); //do not test the distance first last in case of a full circle edge (fpoint == lastpoint) //if ( fpoint.IsEqual(lpoint,1e-5 ) ) // return false; gp_Pnt mpoint = bac.Value((fparam+lparam)*0.5); Standard_Real dist = mpoint.Distance(lpoint); if ( dist <= 1e-5 ) return false; dist = mpoint.Distance(fpoint); if ( dist <= 1e-5 ) return false; return true; }
void binary_class_predict(FILE *input, FILE *output){ int total = 0; int *labels; int max_nr_attr = 64; struct svm_node *x = Malloc(struct svm_node, max_nr_attr); dvec_t dec_values; ivec_t true_labels; int svm_type=svm_get_svm_type(model); if (svm_type==NU_SVR || svm_type==EPSILON_SVR){ fprintf(stderr, "wrong svm type."); exit(1); } labels = Malloc(int, svm_get_nr_class(model)); svm_get_labels(model, labels); max_line_len = 1024; line = (char *)malloc(max_line_len*sizeof(char)); while(readline(input) != NULL) { int i = 0; double target_label, predict_label; char *idx, *val, *label, *endptr; int inst_max_index = -1; // strtol gives 0 if wrong format, and precomputed kernel has <index> start from 0 label = strtok(line," \t"); target_label = strtod(label,&endptr); if(endptr == label) exit_input_error(total+1); while(1) { if(i>=max_nr_attr - 2) // need one more for index = -1 { max_nr_attr *= 2; x = (struct svm_node *) realloc(x,max_nr_attr*sizeof(struct svm_node)); } idx = strtok(NULL,":"); val = strtok(NULL," \t"); if(val == NULL) break; errno = 0; x[i].index = (int) strtol(idx,&endptr,10); if(endptr == idx || errno != 0 || *endptr != '\0' || x[i].index <= inst_max_index) exit_input_error(total+1); else inst_max_index = x[i].index; errno = 0; x[i].value = strtod(val,&endptr); if(endptr == val || errno != 0 || (*endptr != '\0' && !isspace(*endptr))) exit_input_error(total+1); ++i; } x[i].index = -1; predict_label = svm_predict(model,x); fprintf(output,"%g\n",predict_label); double dec_value; svm_predict_values(model, x, &dec_value); true_labels.push_back((target_label > 0)? 1: -1); if(labels[0] <= 0) dec_value *= -1; dec_values.push_back(dec_value); } // validation_function(dec_values, true_labels); accuracy(dec_values, true_labels); bac(dec_values, true_labels); free(labels); free(x); }