/************************************************************ * * * Permission is hereby granted to any individual or * * institution for use, copying, or redistribution of * * this code and associated documentation, provided * * that such code and documentation are not sold for * * profit and the following copyright notice is retained * * in the code and documentation: * * Copyright (c) held by Dianne Cook * * All Rights Reserved. * * * * Questions and comments are welcome, and I request * * that you share any modifications with me. * * * * Dianne Cook * * dicook@iastate.edu * * * ************************************************************/ #define _GT_UTIL_C #include #include #include #include #include "defs_and_types.h" #include "util.h" #include "gt_util.h" #include "gt.h" /* external variables */ extern int ntour_vars, *tour_vars, *tour_vars_bool; extern int pdim; int gen_norm_variates(int n, int p, float *vars) { int i, check=1; long runif[2]; double frunif[2]; double r, fac, frnorm[2]; for (i=0; i<(n*p+1)/2; i++) { while (check) { runif[1] = (int) random(); runif[0] = (int) random(); frunif[0] = (double)(2.0 * ((float)(runif[0])/(float)(MAXINT)) - 1.0); frunif[1] = (double)(2.0 * ((float)(runif[1])/(float)(MAXINT)) - 1.0); r = frunif[0] * frunif[0] + frunif[1] * frunif[1]; if (r < 1) { check = 0; fac = sqrt(-2. * log(r) / r); frnorm[0] = frunif[0] * fac; frnorm[1] = frunif[1] * fac; } } check = 1; vars[2*i] = (float)(frnorm[0]); vars[2*i+1] = (float)(frnorm[1]); } return(1); } /* * Generate two random p dimensional vectors to form new ending basis */ void new_random_basis(float **basis, int ncols, int ntour_vars, int *tour_vars, int pdim) { int j, k; float *tmp_basis; tmp_basis = (float *) malloc((unsigned int) (pdim*ncols)*sizeof(float)); gen_norm_variates(pdim, ntour_vars, tmp_basis); /* zero basis before filling */ for (k=0; k= tmpf) tmpf = tau[k=j]; if (k != i) { tau[k] = tau[i]; tau[i] = tmpf; for (j=0; j1.0) { spandim -= 1; } /* generate principal directions */ mat_mult(u0, tv, v0, ncols, tour_vars, pdim, pdim); for (k=0; kpdim-spandim-1; k--) gram_schmidt(v0[k],v1[k],ncols); /* compute principal angles */ for (k=0; k tol) all_equal = 0; if (all_equal) { ret_val = 1; } else { for (k=0; k tau[k]) ret_val = 1; } return(ret_val); } void increment_tour() { tour_reproject(); scale_into_window(); /* Put a plot function here if you have a graphics driver. */ } /* If the last increment doesn't match up with the requested tau's * do one last small increment to get to the target basis. */ void finishing_step(float *tinc, float *tau, int spandim) { int k, do_final_step = 0; for (k=0; k