/* Diese Funktion verknüpft die Nischenwertdaten einzelner Spezies zu einer Fressmatrix. Dabei ist der Zeilenindex der Fressmatrix den Räubern zugeordnet und die Spalte der Beute. Ein Null-Eintrag bedeutet, dass keine Fressbeziehung besteht. Eine 1 bedeutet, dass die Zeilenspezies die Spaltenspezies fressen kann. Die Konnektivität (Anzahl vorhandener Links/ Anzahl möglicher Links) sollte innerhalb von C+-CRange liegen, ansonsten wird ein Hinweis angegeben, dass C zu groß/klein ist. Für Spezies, die keine anderen Spezies fressen können, wird ein Link zur Ressource eingerichtet. Die Anzahl der basalen Spezies wird zum Programmstart vorgegeben (B). Gibt es eine abweichende Anzahl von basalen Spezies wird dies dem Benutzer mitgeteilt, damit Anpassungen gemacht werden können. */ gsl_matrix *SetFeedingMatrix(struct foodweb nicheweb, gsl_matrix* NV, double C, double CRange){ int S = nicheweb.S; int Rnum = nicheweb.Rnum; int i, j = 0; int k = 0; double nvi = 0; double fri = 0; double fci = 0; double nvj = 0; gsl_matrix* A = gsl_matrix_calloc((nicheweb.Rnum+nicheweb.S), (nicheweb.Rnum+nicheweb.S)); //printf("Starte Berechnung der Fressmatrix...\n"); for(i = 0; i< S; i++) { nvi = gsl_matrix_get(NV, 0, i); // NV = 3xS Matrix! -> 0,1,2 x 0,...S-1 Felderindizes fri = gsl_matrix_get(NV, 1, i); fci = gsl_matrix_get(NV, 2, i); for(j = 0; j< S; j++) { nvj = gsl_matrix_get(NV, 0, j); if( (fci-nvi*fri/2 < nvj) && (nvj < fci+nvi*fri/2) ) // falls nvj im Fressbereich von i liegt setze Link bei A[i+Rnum][j+Rnum] gsl_matrix_set(A, i+Rnum, j+Rnum, 1); } //--Kannibalismus vermeiden---------------------------------------------------------------------------------------------------------- gsl_matrix_set(A, i+Rnum, i+Rnum, 0); // printf("Kannibalismus vermeiden: A[%i][%i] gesetzt auf %f\n", i+Rnum, i+Rnum, gsl_matrix_get(A, i+Rnum, i+Rnum)); //--Basale Spezies finden------------------------------------------------------------------------------------------------------------- k = 0; gsl_vector_view tempp = gsl_matrix_row(A, i+Rnum); // Falls eine Spezies keine Beute hat (Zeile hat keinen Eintrag != 0) wird sie zur Ressource verlinkt k = gsl_vector_isnull(&tempp.vector); // 1: Vektor ist 0-Vektor, 0: Vektor ist nicht der 0-Vektor if(k==1) { gsl_matrix_set(A, i+Rnum, 0, 1); // A[i][0] gibt an wer die Ressource fressen darf (Ressource darf sich nicht selbst fressen) } } return A; }//end SetFeedingMatrix
void scale (gsl_vector * x, double factor) { size_t i, n = x->size; if (gsl_vector_isnull(x)) { for (i = 0; i < n; i++) { gsl_vector_set (x, i, factor); } } else { for (i = 0; i < n; i++) { double xi = gsl_vector_get(x, i); gsl_vector_set(x, i, factor * xi); } } }
int AnovaTest::anovacase(gsl_matrix *bY, gsl_matrix *bX) { unsigned int j; // if Y col is all zeros for ( j=0; j<nVars; j++ ){ gsl_vector_view colj = gsl_matrix_column(bY, j); if ( gsl_vector_isnull(&colj.vector) == TRUE ) return GSL_ERANGE; } unsigned int i, hid, aid; double *sj, *pj, *bj; gsl_matrix *Z = gsl_matrix_alloc(nRows, nVars); gsl_matrix_memcpy(Z, bY); // Hats.X for (i=0; i<nModels-1; i++){ hid = i+1; aid = i; gsl_vector_view ref1 = gsl_matrix_row(inRef, aid); subX(bX, &ref1.vector, Hats[aid].X); gsl_vector_view ref0 = gsl_matrix_row(inRef, hid); subX(bX, &ref0.vector, Hats[hid].X); //Y = X*coef gsl_blas_dgemm(CblasNoTrans,CblasNoTrans,-1.0,Hats[aid].X,Hats[aid].Coef,0.0,Z); //Z = bY - Yhat; gsl_matrix_add (Z, bY); // calc teststats calcSS(Z, &(Hats[hid]), mmRef); calcSS(Z, &(Hats[aid]), mmRef); testStatCalc(&(Hats[hid]), &(Hats[aid]), mmRef, TRUE, &(bMultStat), bStatj); if (bMultStat >= multstat[i]) Pmultstat[i]++; sj = gsl_matrix_ptr (statj, i, 0); pj = gsl_matrix_ptr (Pstatj, i, 0); bj = gsl_vector_ptr (bStatj, 0); calcAdjustP(mmRef->punit, nVars, bj, sj, pj, sortid[i]); } gsl_matrix_free(Z); return 0; }
bool Vector::isNull () const { return gsl_vector_isnull( &vector ); }
/* ------------------------------------------------------------------------- * This function minimises fContact defined above using the * Brent method. It returns the minima with a negative sign (which then * becomes the maxima of the actual contact function. This can be compared * to 1 to check if two ellipsoids indeed overlap. * ------------------------------------------------------------------------*/ REAL8 XLALCheckOverlapOfEllipsoids ( const gsl_vector *ra, const gsl_vector *rb, fContactWorkSpace *workSpace ) { gsl_function F; INT4 min_status; INT4 iter = 0, max_iter = 100; REAL8 m = 0.6180339887; REAL8 a = 0.0L, b = 1.0L; gsl_min_fminimizer *s = workSpace->s; /* Sanity check on input arguments */ if ( !ra || !rb || !workSpace ) XLAL_ERROR_REAL8( XLAL_EFAULT ); if ( ra->size != rb->size || ra->size != workSpace->n ) XLAL_ERROR_REAL8( XLAL_EBADLEN); /* Set r_AB to be rb - ra */ XLAL_CALLGSL( gsl_vector_memcpy( workSpace->r_AB, rb) ); XLAL_CALLGSL( gsl_vector_sub (workSpace->r_AB, ra) ); if ( gsl_vector_isnull( workSpace->r_AB )) { XLALPrintWarning("Position vectors ra and rb are identical.\n"); return 0; } F.function = &fContact; F.params = workSpace; XLAL_CALLGSL( min_status = gsl_min_fminimizer_set (s, &F, m, a, b) ); if ( min_status != GSL_SUCCESS ) XLAL_ERROR_REAL8( XLAL_EFUNC ); do { iter++; XLAL_CALLGSL( min_status = gsl_min_fminimizer_iterate (s) ); if (min_status != GSL_SUCCESS ) { if (min_status == GSL_EBADFUNC) XLAL_ERROR_REAL8( XLAL_EFUNC | XLAL_EFPINVAL ); else if (min_status == GSL_EZERODIV) XLAL_ERROR_REAL8( XLAL_EFUNC | XLAL_EFPDIV0 ); else XLAL_ERROR_REAL8( XLAL_EFUNC ); } m = gsl_min_fminimizer_x_minimum (s); a = gsl_min_fminimizer_x_lower (s); b = gsl_min_fminimizer_x_upper (s); XLAL_CALLGSL( min_status = gsl_min_test_interval (a, b, workSpace->convParam, 0.0) ); if (min_status != GSL_CONTINUE && min_status != GSL_SUCCESS ) XLAL_ERROR_REAL8( XLAL_EFUNC ); } while (min_status == GSL_CONTINUE && iter < max_iter ); /* End of minimization routine */ /* Throw an error if max iterations would have been exceeded */ if ( iter == max_iter && min_status == GSL_CONTINUE ) { XLAL_ERROR_REAL8( XLAL_EMAXITER ); } return ( -(s->f_minimum) ); }