//#define DEBUG 1 /* Authors Martin Schlather, martin.schlather@math.uni-goettingen.de Collection of auxiliary functions Copyright (C) 2001 -- 2011 Martin Schlather, This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include "auxiliary.h" //#include #include "RandomFields.h" #include #include void distInt(int *X, int*N, int *Genes, double *dist) { int i,j, k, di, diff, *x, *y, ve, ho, endfor, n = *N, nP1 = n + 1, genes = *Genes; x = y = X; for (j=0, i=0; j 256) len = 256; for (i=0; i nline) m = nline; for (i=0; istart) { j--; PRINTF("\b \b"); continue; } for (i=0; i-1.0)) return 0.0; if (x<=0) return RF_NAN; // not programmed yet logx = log(0.5 * x); x1=1.5; x2=nu+1.5; sign=1.0; if (x2 > 0.0) { dummy = (nu + 1.0) * logx - lgammafn(x1) - lgammafn(x2); if (expscaled) dummy -= x; value = exp(dummy); } else { if ( (double) ((int) (x1-0.5)) != x1-0.5 ) return RF_NAN; value=pow(0.5 * x, nu + 1.0) / (gammafn(x1) * gammafn(x2)); if (expscaled) value *= exp(-x); if ((dummy= value) <0) { dummy = -dummy; sign = -1.0; } dummy = log(dummy); } logx *= 2.0; do { if (x2<0) { sign = -sign; } dummy += logx - log(x1) - log(fabs(x2)); value += sign * exp(dummy); x1 += 1.0; x2 += 1.0; sign = factor_sign * sign; } while (exp(dummy) > fabs(value) * epsilon); return value; } void vectordist(double *v, int *Dim, double *Dist, int *diag){ int d, dim, dr; double *v1, *v2, *end; bool notdiag = (*diag==0); dim = Dim[0]; end = v + Dim[1] * dim; // printf("%d %d %f %f\n", dim , Dim[0], v, end); for (dr=0, v1=v; v1 y[d]; return false; } bool smallerInt(int i, int j) { int *x, *y; int d; x = ORDERDINT + i * ORDERDIM; y = ORDERDINT + j * ORDERDIM; for(d=0; d y[d]; return false; } int is_positive_definite(double *C, int dim) { int err, bytes = sizeof(double) * dim * dim; double *test; test = (double*) malloc(bytes); memcpy(test, C, bytes); F77_CALL(dpofa)(test, &dim, &dim, &err); free(test); return(err == 0); } void order(int *pos, int start, int end) { int randpos, pivot, left, right, pivotpos, swap; if( start < end ) { //GetRNGstate();randpos = start + (int) (UNIFORM_RANDOM * (end-start+1)); PutRNGstate(); randpos = (int) (0.5 * (start + end)); pivot = pos[randpos]; pos[randpos] = pos[start]; pos[start] = pivot; pivotpos=start; left = start; right=end+1; while (left < right) { while (++left < right && SMALLER(pos[left], pivot)) pivotpos++; while (--right > left && GREATER(pos[right], pivot)); if (left < right) { swap=pos[left]; pos[left]=pos[right]; pos[right]=swap; pivotpos++; } } pos[start] = pos[pivotpos]; pos[pivotpos] = pivot; order(pos, start, pivotpos-1 ); order(pos, pivotpos + 1, end ); } } void ordering(double *d, int len, int dim, int *pos) { /* quicksort algorithm, slightly modified: does not sort the data, but d[pos] will be ordered NOTE: pos must have the values 0,1,2,...,start-end ! (orderdouble is a kind of sorting pos according to the variable d) */ int i; for (i=0; i