void undo(void) { /* turn off Compose key LED */ setCompLED(0); switch (last_action) { case F_ADD: undo_add(); break; case F_DELETE: undo_delete(); break; case F_MOVE: undo_move(); break; case F_EDIT: undo_change(); break; case F_GLUE: undo_glue(); break; case F_BREAK: undo_break(); break; case F_LOAD: undo_load(); break; case F_SCALE: undo_scale(); break; case F_ADD_POINT: undo_addpoint(); break; case F_DELETE_POINT: undo_deletepoint(); break; case F_ADD_ARROW_HEAD: undo_add_arrowhead(); break; case F_DELETE_ARROW_HEAD: undo_delete_arrowhead(); break; case F_CONVERT: undo_convert(); break; case F_OPEN_CLOSE: undo_open_close(); break; case F_JOIN: case F_SPLIT: undo_join_split(); break; default: put_msg("Nothing to UNDO"); return; } put_msg("Undo complete"); }
void do_eigen_projections(int nev, float *M, float **models, float *mean, int num_models, eigen_t *eigen, int dim) { int i, m; struct { float *proj; float best_dot; float best_dot_index; char symbol; } proj_model[2]; assert(models != NULL); assert(mean != NULL); assert(eigen != NULL); assert(dim > 0); assert(num_models > 0); assert(0 < nev && nev <= dim); proj_model[0].proj = (float *)malloc(dim * sizeof(float)); proj_model[1].proj = (float *)malloc(dim * sizeof(float)); proj_model[0].symbol = '+'; proj_model[1].symbol = '-'; if (!opt_multi_out) fprintf(out, "#BEGIN ENSEM\n"); for (i=0; i < nev; i++) { /*================================================================ * Find the models that have the largest and smallest projections * onto the current eigenvector. *==============================================================*/ proj_model[0].best_dot = 0; proj_model[0].best_dot_index = -1; proj_model[1].best_dot = 0; proj_model[1].best_dot_index = -1; for (m=0; m < num_models; m++) { float dot = vecdot(models[m], eigen[i].rvec, dim); if (dot >= 0 && dot >= proj_model[0].best_dot) { proj_model[0].best_dot = dot; proj_model[0].best_dot_index = m; vecmul(eigen[i].rvec, dot, dim, proj_model[0].proj); } if (dot <= 0 && dot <= proj_model[1].best_dot) { proj_model[1].best_dot = dot; proj_model[1].best_dot_index = m; vecmul(eigen[i].rvec, dot, dim, proj_model[1].proj); } } if (opt_interp_proj) { if (proj_model[0].best_dot_index != -1 && proj_model[1].best_dot_index != -1) { int j; float *newp = (float *)malloc(dim * sizeof(float)); float *step = (float *)malloc(dim * sizeof(float)); #define NSTEPS 20 #define OVERSHOOT 20 vecvecsub(proj_model[1].proj, proj_model[0].proj, dim, step); vecdiv(step, NSTEPS, dim, step); for (j=0; j < NSTEPS+OVERSHOOT; j++) { vecmul(step, j, dim, newp); vecvecadd(proj_model[0].proj, newp, dim, newp); undo_scale(newp, dim, M); vecvecadd(newp, mean, dim, newp); multi_out_write_ev_model((i+1)*100 + j, 'p', 0, 0, newp, dim); } free(newp); free(step); #undef NSTEPS #undef OVERSHOOT } } else { /*================================================================ * Write out the new models *==============================================================*/ for (m=0; m < 2; m++) { if (proj_model[m].best_dot_index != -1) { float proj_len_before_scale = veclen(proj_model[m].proj, dim); undo_scale(proj_model[m].proj, dim, M); /* add back mean */ vecvecadd(proj_model[m].proj,mean, dim, proj_model[m].proj); multi_out_write_ev_model(i, proj_model[m].symbol, proj_len_before_scale, proj_model[m].best_dot, proj_model[m].proj, dim); } } } } if (!opt_multi_out) fprintf(out, "#END ENSEM\n"); free(proj_model[0].proj); free(proj_model[1].proj); }