int main (int argc, char **argv) { char archivo[256]; strcpy(archivo,argv[1]); double *tiempo, *posicion; int n_filas = 0; int n_columnas = 2; int t = 0; int p = 1; int i,x = 0; tiempo = load_data(archivo, &n_filas, t); posicion = load_data(archivo, &n_filas, p); gsl_matrix *G = gsl_matrix_calloc(n_filas,3); gsl_vector *d = gsl_vector_calloc(n_filas); gsl_matrix *G_t = gsl_matrix_calloc(3,n_filas); for (i=0; i<n_filas; i++) { gsl_matrix_set(G,i,0,1); gsl_matrix_set(G,i,1,tiempo[i]); gsl_matrix_set(G,i,2,0.5*tiempo[i]*tiempo[i]); gsl_vector_set(d,i,posicion[i]); gsl_matrix_set(G,0,i,1); gsl_matrix_set(G,1,i,tiempo[i]); gsl_matrix_set(G,2,i,0.5*tiempo[i]*tiempo[i]); } //t_data = transpose_data(data, n_filas, n_columnas); }
/** * Construct an empty KDE structure. * * Create an empty LALInferenceKDE structure, allocated to handle the given size * and dimension. * @param[in] npts Number of samples that will be used to estimate * the distribution. * @param[in] dim Number of dimensions that the probability density function * will be estimated in. * @return An allocated, empty LALInferenceKDE structure. * \sa LALInferenceKDE, LALInferenceSetKDEBandwidth() */ LALInferenceKDE *LALInferenceInitKDE(INT4 npts, INT4 dim) { INT4 p; LALInferenceKDE *kde = XLALCalloc(1, sizeof(LALInferenceKDE)); kde->dim = dim; kde->npts = npts; kde->mean = gsl_vector_calloc(dim); kde->cholesky_decomp_cov = gsl_matrix_calloc(dim, dim); kde->cholesky_decomp_cov_lower = gsl_matrix_calloc(dim, dim); kde->cov = gsl_matrix_calloc(dim, dim); kde->lower_bound_types = XLALCalloc(dim, sizeof(LALInferenceParamVaryType)); kde->upper_bound_types = XLALCalloc(dim, sizeof(LALInferenceParamVaryType)); kde->lower_bounds = XLALCalloc(dim, sizeof(REAL8)); kde->upper_bounds = XLALCalloc(dim, sizeof(REAL8)); for (p = 0; p < dim; p++) { kde->lower_bound_types[p] = LALINFERENCE_PARAM_OUTPUT; kde->upper_bound_types[p] = LALINFERENCE_PARAM_OUTPUT; } if (npts > 0) kde->data = gsl_matrix_alloc(npts, dim); return kde; }
gsl_matrix *pseudo_inverse(gsl_matrix* input) { int m = input->size1; int n = input->size2; gsl_matrix *U = gsl_matrix_calloc(m,n); gsl_matrix_memcpy(U, input); gsl_matrix *V = gsl_matrix_calloc(n,n); gsl_vector *sigma = gsl_vector_calloc(n); gsl_vector *tmp = gsl_vector_calloc(n); gsl_linalg_SV_decomp(U, V, sigma, tmp); for (int i = 0; i < n; i++) { double s = gsl_vector_get(sigma, i); if (s > 0.0000000001) { gsl_vector_set(sigma, i, 1/s); } else if (s > 0) { gsl_vector_set(sigma, i, 0); } } gsl_matrix *tmpa = gsl_matrix_calloc(n,n); gsl_matrix *tmpb = gsl_matrix_calloc(n,m); gsl_matrix *tmpc = gsl_matrix_calloc(n,m); for (int i = 0; i < n; i++) { gsl_matrix_set(tmpa, i, i, gsl_vector_get(sigma, i)); } gsl_blas_dgemm(CblasNoTrans, CblasTrans, 1, tmpa, U, 0, tmpb); gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1, V, tmpb, 0, tmpc); return tmpc; }
int main(int argc, char **argv) { int i,j; int mallas=3; int m=mallas-1; int elementos = pow(2,mallas)+1; gsl_matrix * f = gsl_matrix_calloc(elementos,elementos); gsl_matrix * u = gsl_matrix_calloc(elementos,elementos); int divisor = pow(elementos-1,2); for(i=1; i< elementos-1; i++) { for(j=1; j<elementos-1; j++) { gsl_matrix_set(u,i,j,cos(12.0*i*j)); } } for(i=0;i<10; i++) { suavizador(u,f,1); muestra_matriz(u); printf("%d\n"); } }
int main(int argc, char **argv){ FILE *fp; if(argc != 2) { printf("Niepoprawna liczba argumentów!\n"); exit(0); } N = atoi(argv[1]); int **A, **B, **C; A = calloc(N, sizeof(int*)); B = calloc(N, sizeof(int*)); C = calloc(N, sizeof(int*)); for(i = 0; i<N; i++){ A[i] = calloc(N, sizeof(int)); B[i] = calloc(N, sizeof(int)); C[i] = calloc(N, sizeof(int)); } gsl_matrix *matrix1 = gsl_matrix_calloc(N, N); gsl_matrix *matrix2 = gsl_matrix_calloc(N, N); gsl_matrix *result = gsl_matrix_calloc(N, N); CBLAS_TRANSPOSE_t TransA = CblasNoTrans; srand(time(NULL)); fp = fopen("result.txt", "a"); //fill matrix for(i=0; i<N; i++){ for(j=0; j<N; j++){ tmp = rand() % 100; A[i][j] = tmp; gsl_matrix_set(matrix1, j, k, tmp); tmp = rand() % 100; B[i][j] = tmp; gsl_matrix_set(matrix2, j, k, tmp); } } for(l = 0; l < 20; l++){ //algorithms start = clock(); naive(A,B,C); fprintf(fp, "%d,alg1,%f\n", N, (double)(clock() - start)/CLOCKS_PER_SEC); //printf("Algorytm 1: %g [s]\n", (double)(clock() - start)/CLOCKS_PER_SEC); start = clock(); ver2(A,B,C); fprintf(fp, "%d,alg2,%f\n", N, (double)(clock() - start)/CLOCKS_PER_SEC); //printf("Algorytm 2: %g [s]\n", (double)(clock() - start)/CLOCKS_PER_SEC); start = clock(); gsl_blas_dgemm (TransA, TransA, 1, matrix1, matrix2, 1, result); fprintf(fp, "%d,blas,%f\n", N, (double)(clock() - start)/CLOCKS_PER_SEC); //printf("Algorytm 3: %g [s]\n", (double)(clock() - start)/CLOCKS_PER_SEC); } return 0; }
lda_post* new_lda_post(int ntopics, int max_length) { lda_post* p = (lda_post*) malloc(sizeof(lda_post)); p->phi = gsl_matrix_calloc(max_length, ntopics); p->log_phi = gsl_matrix_calloc(max_length, ntopics); p->gamma = gsl_vector_calloc(ntopics); p->lhood = gsl_vector_calloc(ntopics + 1); return(p); }
int main(int argc, char **argv) { FILE *in; FILE *out; int i,j; int n_rows, n_columns; float *mtiempo; in = fopen( argv[1] , "r"); n_rows = contarlineas(argv[1]); n_columns = 2; /* incialisa las matrices y los vectores*/ gsl_matrix *matriz = gsl_matrix_calloc (n_rows, n_columns); gsl_matrix *g = gsl_matrix_calloc (n_rows, 3); gsl_matrix *gTg = gsl_matrix_calloc (3,3); gsl_matrix *inversa = gsl_matrix_calloc (3,3); gsl_vector *t = gsl_vector_calloc (n_rows); gsl_vector *pos = gsl_vector_calloc (n_rows); gsl_vector *gTd = gsl_vector_calloc (3); gsl_vector *m = gsl_vector_calloc (3); // se crear la matriz con los datos del archivo gsl_matrix_fscanf (in, matriz); // se separa la matris en vectores gsl_matrix_get_col (t, matriz, 0); gsl_matrix_get_col (pos, matriz, 1); /* crea g*/ crearg (t, g, n_rows); /* se crea (G^T) * G */ gsl_blas_dgemm (CblasTrans, CblasNoTrans, 1.0, g, g, 0.0, gTg); /* se crea [(G^T) * G]^(-1) */ invertirmatriz (gTg, inversa, 3); /* se crea (G^T) * d */ gsl_blas_dgemv (CblasTrans, 1.0, g, pos, 0.0, gTd); /* se obtiene m */ gsl_blas_dgemv (CblasNoTrans, 1.0, inversa, gTd, 0.0, m); /* imprime el archivo con los valores de m*/ out = fopen("parametros_movimiento.dat", "w"); fprintf(out, "%f %f %f" ,gsl_vector_get (m, 0), gsl_vector_get (m, 1) ,gsl_vector_get (m, 2)); return 0; }
MVEE::MVEE(gsl_matrix* XX): tol(0.0000001), KKY(0), maxit(100000), doPrint(false) { n = XX->size1; m = XX->size2; X = gsl_matrix_calloc(n,m); M = gsl_matrix_calloc(n,n); u = gsl_vector_calloc(m); gsl_matrix_memcpy(X,XX); }
void CRebuildGraph::CompareAndGenerateResults(SettingsSimulation settingsSimulation, gslGraph *targetGraph, gslGraph *bestGraph, char* inputFilename, time_t timeStart, double Tk, double *&bestBC, double costBest, double &compareResult, char *outputGraphFilename ){ CFuncTrace lFuncTrace(false,string("CRebuildGraph::CompareAndGenerateResults")); time_t timeEnd; gsl_matrix *targetGraphGsl = gsl_matrix_calloc(targetGraph->getOrder(), targetGraph->getOrder()); gsl_matrix *bestGraphGsl = gsl_matrix_calloc(bestGraph->getOrder(), bestGraph->getOrder()); targetGraph->graphToGsl(targetGraphGsl); bestGraph->graphToGsl(bestGraphGsl); compareResult = this->compareMatrix(targetGraphGsl, bestGraphGsl); // Processing tasks accomplished // Showing results timeEnd=time(NULL); lFuncTrace.trace(CTrace::TRACE_DEBUG,"RESULTS:\n"); lFuncTrace.trace(CTrace::TRACE_DEBUG,"CPU time needed: %f seconds\n",difftime(timeEnd,timeStart)); // printf("Output file: %s\n",outputFilename); double *targetBC = NULL; { graphIndicator * graphIndicator = FactoryMethodGraphIndicator::createGraphIndicator(settingsSimulation.graphProperty,targetGraph); targetBC = graphIndicator->calculateIndicatorWithReescale(settingsSimulation.reescale); delete graphIndicator; } generateOutputFile(targetGraph,inputFilename, Tk, costBest,targetBC, bestBC, timeStart, timeEnd,settingsSimulation); lFuncTrace.trace(CTrace::TRACE_DEBUG,"Reconstructed graph file: %s",outputGraphFilename); bestGraph->printMyGraph(outputGraphFilename,settingsSimulation.outputFormatGraphResultAdjList); gsl_matrix_free(bestGraphGsl); gsl_matrix_free(targetGraphGsl); }
void Params::init(int size) { cov = gsl_matrix_calloc (size, size); evec = gsl_matrix_calloc (size, size); // initialize sumsOfMetrics and sumsOfProducts for (int i = 0; i < size; i++) { sumsOfMetrics.push_back(0.0); stddevs.push_back(0.0); std::vector<double> v; for (int j = 0; j < size; j++) v.push_back(0.0); sumsOfProducts.push_back(v); } }
chapeau * chapeau_alloc ( int m, double rmin, double rmax, int npart ) { chapeau * ch; int d,i; ch=(chapeau*)malloc(sizeof(chapeau)); if (npart<1) { fprintf(stderr,"CFACV/C) ERROR: chapeau objects without particles\n"); exit(-1); } if (m<1) { fprintf(stderr,"CFACV/C) ERROR: chapeau objects without bins\n"); exit(-1); } ch->m=m; ch->N=npart; ch->rmin=rmin; ch->rmax=rmax; ch->dr=(rmax-rmin)/(m-1); ch->idr=1.0/ch->dr; ch->lam=gsl_vector_calloc(m); ch->nsample=0; ch->hits=(int*)calloc(m,sizeof(int)); //ch->s=(double***) calloc(npart,sizeof(double**)); //for (i=0;i<npart;i++) { // ch->s[i]=(double**)calloc(3,sizeof(double*)); // for (d=0;d<3;d++) { // ch->s[i][d]=(double*)calloc(m,sizeof(double)); // } //} ch->mask=(int*)calloc(npart,sizeof(int)); ch->b=gsl_vector_calloc(m); ch->A=gsl_matrix_calloc(m,m); ch->bfull=gsl_vector_calloc(m); ch->Afull=gsl_matrix_calloc(m,m); fprintf(stdout,"CFACG4/DEBUG) allocated chapeau with %i knots on [%.5f,%.5f] dr %g \n",m,rmin,rmax,ch->dr); fflush(stdout); ch->alpha=0; return ch; }
double R0(const double theta[numParam], const double r0time, double * eigenvec) { gsl_matrix * Fmat = gsl_matrix_calloc(NG*(DS-1)*RG, NG*(DS-1)*RG); gsl_matrix * Vmat = gsl_matrix_calloc(NG*(DS-1)*RG, NG*(DS-1)*RG); gsl_matrix * VmatInv = gsl_matrix_calloc(NG*(DS-1)*RG, NG*(DS-1)*RG); gsl_matrix * ngm = gsl_matrix_calloc(NG*(DS-1)*RG, NG*(DS-1)*RG); createNGM(theta, r0time, Fmat, Vmat); gsl_permutation * p = gsl_permutation_alloc(NG*(DS-1)*RG); int s; gsl_linalg_LU_decomp(Vmat, p, &s); gsl_linalg_LU_invert(Vmat, p, VmatInv); gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, Fmat, VmatInv, 0.0, ngm); gsl_eigen_nonsymmv_workspace * w = gsl_eigen_nonsymmv_alloc(NG*(DS-1)*RG); gsl_vector_complex * eval = gsl_vector_complex_alloc(NG*(DS-1)*RG); gsl_matrix_complex * evec = gsl_matrix_complex_alloc(NG*(DS-1)*RG, NG*(DS-1)*RG); gsl_set_error_handler_off(); gsl_eigen_nonsymmv(ngm, eval, evec, w); size_t r0_idx = 0; double r0 = 0.0; for(size_t i = 0; i < NG*(DS-1)*RG; i++){ if(GSL_REAL(gsl_vector_complex_get(eval, i)) > r0){ r0_idx = i; r0 = GSL_REAL(gsl_vector_complex_get(eval, i)); } } if(eigenvec != NULL){ for(size_t i = 0; i < NG*(DS-1)*RG; i++) eigenvec[i] = GSL_REAL(gsl_matrix_complex_get(evec, i, r0_idx)); } gsl_matrix_free(Fmat); gsl_matrix_free(Vmat); gsl_matrix_free(VmatInv); gsl_matrix_free(ngm); gsl_permutation_free(p); gsl_eigen_nonsymmv_free(w); gsl_vector_complex_free(eval); gsl_matrix_complex_free(evec); return r0; }
/* gsl_matrix_part function copies the specified elements of a gsl_matrix to the specified area of an other gsl_matrix */ gsl_matrix *gsl_matrix_part(const gsl_matrix *src, gsl_matrix **part, int src_from_row, int src_from_col, int src_to_row, int src_to_col, int dest_from_row, int dest_from_col) { int row, col; int brow = src_to_row - src_from_row + 1; int bcol = src_to_col - src_from_col + 1; gsl_matrix *p; /* check if target matrix ist not initialized or no pointer has been given to copy data to */ if(part == NULL || *part == NULL) { /* allocate new matrix of correct size */ p = gsl_matrix_alloc(dest_from_row + brow, dest_from_col + bcol); } else { /* check if given target matrix is smaller than needed*/ if((*part)->size1 < dest_from_row + brow || (*part)->size2 < dest_from_col + bcol) { int psize1 = ((*part)->size1 >= dest_from_row + brow) ? (*part)->size1 : dest_from_row + brow; int psize2 = ((*part)->size2 >= dest_from_col + bcol) ? (*part)->size2 : dest_from_col + bcol; p = gsl_matrix_calloc(psize1, psize2); /* copy constant part of target matrix to new matrix */ for(row = 0; row < (*part)->size1; ++row) for(col = 0; col < (*part)->size2; ++col) gsl_matrix_set(p, row, col, gsl_matrix_get(*part, row, col)); /* free memory of old matrix */ gsl_matrix_free(*part); } else { /* if size of target matrix fits than just copy the pointers */ p = *part; } } /* copy new data to target matrix */ for(row = 0; row < brow; ++row) for(col = 0; col < bcol; ++col) gsl_matrix_set(p, dest_from_row + row, dest_from_col + col, gsl_matrix_get(src, src_from_row + row, src_from_col + col)); /* check if to set pointer */ if(part != NULL) *part = p; return p; }
int soltrack_init(double deg_lat, double deg_long) { // Check domain if (!(check_lat(deg_lat) && check_long(deg_long))) { return SOL_DOMAIN_ERROR; } // Calculate latitude and longitude in radians double rad_lat = deg_to_rad(deg_lat); double rad_long = deg_to_rad(deg_long); // Create a 3-dimensional vector uv_orth_w_spin = gsl_vector_alloc(V_DIM); gsl_vector_set(uv_orth_w_spin, X_AXIS, \ gsl_sf_cos(rad_long) * gsl_sf_cos(rad_lat)); gsl_vector_set(uv_orth_w_spin, Y_AXIS, \ gsl_sf_sin(rad_long) * gsl_sf_cos(rad_lat)); gsl_vector_set(uv_orth_w_spin, Z_AXIS, gsl_sf_sin(rad_lat)); // Create the rotation matrix for axial tilt of the earth rm_ax_tilt = gsl_matrix_calloc(V_DIM, V_DIM); // Initialize 0 // X-Axis gsl_matrix_set(rm_ax_tilt, X_AXIS, X_AXIS, gsl_sf_cos(rad_ax_tilt)); gsl_matrix_set(rm_ax_tilt, X_AXIS, Z_AXIS, -gsl_sf_sin(rad_ax_tilt)); // Y-Axis (no rotation) gsl_matrix_set(rm_ax_tilt, Y_AXIS, Y_AXIS, 1.0); // Z-Axis gsl_matrix_set(rm_ax_tilt, Z_AXIS, X_AXIS, gsl_sf_sin(rad_ax_tilt)); gsl_matrix_set(rm_ax_tilt, Z_AXIS, Z_AXIS, gsl_sf_cos(rad_ax_tilt)); // Initialisation complete initialized = 1; return 0; }
int cholcrout(gsl_matrix *A, gsl_matrix **L) { size_t i, j, k; double temp; if (A->size1 != A->size2) { return MATRIX_NOT_SQUARE; } *L = gsl_matrix_calloc(A->size1, A->size2); for (j = 0; j < A->size2; ++j) { for (i = j; i < A->size1; ++i) { temp = 0.0; if (i > j) { for (k = 0; k < j; ++k) { temp += gsl_matrix_get(*L, i, k) * gsl_matrix_get(*L, j, k); } gsl_matrix_set(*L, i, j, (gsl_matrix_get(A, i, j) - temp) / gsl_matrix_get(*L, j, j)); } else if (i == j) { for (k = 0; k < i; ++k) { temp += gsl_matrix_get(*L, i, k) * gsl_matrix_get(*L, i, k); } gsl_matrix_set(*L, i, i, sqrt(gsl_matrix_get(A, i, i) - temp)); } } } return 0; }
/* compute compact QR factorization and get Q M is mxn; Q is mxk and R is kxk (not computed) */ void QR_factorization_getQ(gsl_matrix *M, gsl_matrix *Q){ int i,j,m,n,k; m = M->size1; n = M->size2; k = min(m,n); gsl_matrix *QR = gsl_matrix_calloc(M->size1, M->size2); gsl_vector *tau = gsl_vector_alloc(min(M->size1,M->size2)); gsl_matrix_memcpy (QR, M); gsl_linalg_QR_decomp (QR, tau); gsl_vector *vj = gsl_vector_calloc(m); for(j=0; j<k; j++){ gsl_vector_set(vj,j,1.0); gsl_linalg_QR_Qvec (QR, tau, vj); gsl_matrix_set_col(Q,j,vj); vj = gsl_vector_calloc(m); } gsl_vector_free(vj); gsl_vector_free(tau); gsl_matrix_free(QR); }
/* * FUNCTION * Name: stationary * Description: Given the dissipator in Bloch form, reduce to a 3x3 problem and store * the stationary state in the 3x1 vector *X * * M X = 0 * * | 0 0 0 0 | | 1 | 0 * | M10 M11 M12 M13 | | X1 | 0 * | M20 M21 M22 M23 | | X2 | = 0 * | M30 M31 M32 M33 | | X3 | 0 * * * A x = b * * | M11 M12 M13 | | X1 | | -M10 | * | M21 M22 M23 | | X2 | = | -M20 | * | M31 M32 M33 | | X3 | | -M30 | */ int stationary ( const gsl_matrix* M, gsl_vector* stat_state ) { /* Store space for the stationary state */ gsl_vector* req = gsl_vector_calloc ( 4 ) ; gsl_vector_set ( req, 0, 1 ) ; /* Copy the dissipator matrix in a temporary local matrix m * (because the algorithm destroys it...) */ gsl_matrix* m = gsl_matrix_calloc ( 4, 4 ) ; gsl_matrix_memcpy ( m, M ) ; /* Create a view of the spatial part of vector req */ gsl_vector_view x = gsl_vector_subvector ( req, 1, 3 ) ; /* Create a submatrix view of the spatial part of m and a vector view * of the spatial part of the 0-th column, which goes into -b in the system * A x = b */ gsl_matrix_view A = gsl_matrix_submatrix ( m, 1, 1, 3, 3 ) ; gsl_vector_view b = gsl_matrix_subcolumn ( m, 0, 1, 3 ) ; int status1 = gsl_vector_scale ( &b.vector, -1.0 ) ; /* Solve the system A x = b using Householder transformations. * Changing the view x of req => also req is changed, in the spatial part */ int status2 = gsl_linalg_HH_solve ( &A.matrix, &b.vector, &x.vector ) ; /* Set the returning value for the state stat_state */ *stat_state = *req ; /* Free memory */ gsl_matrix_free(m) ; return status1 + status2 ; } /* ----- end of function stationary ----- */
/* load matrix from file format: % comment num_rows num_columns num_nonzeros row col nnz ..... row col nnz */ gsl_matrix * matrix_load_from_text_file(char *fname){ int i, j, num_rows, num_columns, num_nonzeros, row_num, col_num; double nnz_val; char *nnz_val_str; char *line; FILE *fp; gsl_matrix *M; line = (char*)malloc(200*sizeof(char)); fp = fopen(fname,"r"); fgets(line,100,fp); //read comment fgets(line,100,fp); //read dimensions and nnzs sscanf(line, "%d %d %d", &num_rows, &num_columns, &num_nonzeros); M = gsl_matrix_calloc(num_rows, num_columns); // calloc sets all elements to zero // read and set elements nnz_val_str = (char*)malloc(50*sizeof(char)); for(i=0; i<num_nonzeros; i++){ fgets(line,100,fp); sscanf(line, "%d %d %s", &row_num, &col_num, nnz_val_str); nnz_val = atof(nnz_val_str); gsl_matrix_set(M, row_num, col_num, nnz_val); } fclose(fp); // clean free(line); free(nnz_val_str); return M; }
//detects targets at a specified scale as a low/hi-gradient section LinkedList<Point2D<int> >*gradeSmoothDetect(ARVP_Image*src_img,int init_scale,int max_scale, int low_threshold,int hi_threshold,bool debug = false) { int scale; ARVP_Image*gradient_img = new ARVP_Image(src_img->height,src_img->width); ARVP_Image*scale_space_img = new ARVP_Image(src_img->height,src_img->width); //this is what is returned LinkedList<Point2D<int> >*candidate_list = new LinkedList<Point2D<int> >(); gsl_matrix*filter; //perform gradient, the blob is found as a low-gradient area printf("Performing gradient operation\n"); gradient_RGB(src_img,gradient_img,true); //the image is evaluated at scales //printf("Beginning the scales\n"); //for(scale = init_scale;scale<=max_scale;scale++) for(scale = init_scale;scale<=init_scale;scale++) //ignore max_scale for now { //perform gaussian blur for scale space int blur_size = (int)ceil(sqrt(scale)*6); if(scale>0) { filter = gsl_matrix_calloc(blur_size,blur_size); gaussian(filter,scale); printf("Doing Gaussian\n"); convolution_RGB(gradient_img,scale_space_img,filter,blur_size/2,blur_size/2); gsl_matrix_free(filter); } //pass the scale space image to the detection detectGradeScale(gradient_img,scale,low_threshold,hi_threshold,candidate_list,debug); } printf("Finished detecting, now deleting\n"); delete gradient_img; delete scale_space_img; return candidate_list; }
/* Create a covariance struct for a two-pass algorithm. If categorical variables are involed, the dimension cannot be know until after the first data pass, so the actual covariances will not be allocated until then. */ struct covariance * covariance_2pass_create (size_t n_vars, const struct variable *const *vars, struct categoricals *cats, const struct variable *wv, enum mv_class exclude) { size_t i; struct covariance *cov = xmalloc (sizeof *cov); cov->passes = 2; cov->state = 0; cov->pass_one_first_case_seen = cov->pass_two_first_case_seen = false; cov->vars = vars; cov->wv = wv; cov->n_vars = n_vars; cov->dim = n_vars; cov->moments = xmalloc (sizeof *cov->moments * n_MOMENTS); for (i = 0; i < n_MOMENTS; ++i) cov->moments[i] = gsl_matrix_calloc (n_vars, n_vars); cov->exclude = exclude; cov->n_cm = -1; cov->cm = NULL; cov->categoricals = cats; cov->unnormalised = NULL; return cov; }
crlb_so_run(const vector2 *anchor, const size_t num_anchors, const vector2 *location) { int s; float crlb; const float v = crlb_so_sdev * crlb_so_sdev; gsl_matrix *A = gsl_matrix_calloc(2, 2); gsl_matrix *Ai = gsl_matrix_alloc(2, 2); gsl_permutation *p = gsl_permutation_alloc(2); /* See Equation (2.157) of So's Chapter. */ for (size_t i = 0; i < num_anchors; i++) { const float dx = location->x - anchor[i].x; const float dy = location->y - anchor[i].y; const float d2 = dx * dx + dy * dy; A->data[0 /* 0, 0 */] += (dx * dx) / (v * d2); A->data[1 /* 1, 0 */] += (dx * dy) / (v * d2); A->data[2 /* 0, 1 */] += (dy * dx) / (v * d2); A->data[3 /* 1, 1 */] += (dy * dy) / (v * d2); } gsl_linalg_LU_decomp(A, p, &s); gsl_linalg_LU_invert(A, p, Ai); /* See Equation (2.158) of So's Chapter. */ crlb = (float) (gsl_matrix_get(Ai, 0, 0) + gsl_matrix_get(Ai, 1, 1)); gsl_permutation_free(p); gsl_matrix_free(Ai); gsl_matrix_free(A); return crlb; }
static void MatVecProd(double *rbt, double *vec1,double *vec2){ gsl_matrix *T = gsl_matrix_calloc(3,3); gsl_vector *V = gsl_vector_calloc(3); gsl_vector *V2 = gsl_vector_calloc(3); double Tij[9] = {cos(rbt[2]),-sin(rbt[2]),rbt[0], sin(rbt[2]), cos(rbt[2]), rbt[1], 0, 0, 1}; memcpy(T->data,Tij,sizeof(double)*9); memcpy(V->data,vec1,sizeof(double)*3); gsl_blas_dgemv(CblasNoTrans,1.0,T,V,0.0,V2); memcpy(vec2,V2->data,sizeof(double)*3); gsl_matrix_free(T); gsl_vector_free(V); gsl_vector_free(V2); }
/* Create a covariance struct. */ struct covariance * covariance_1pass_create (size_t n_vars, const struct variable *const *vars, const struct variable *weight, enum mv_class exclude) { size_t i; struct covariance *cov = xzalloc (sizeof *cov); cov->passes = 1; cov->state = 0; cov->pass_one_first_case_seen = cov->pass_two_first_case_seen = false; cov->vars = vars; cov->wv = weight; cov->n_vars = n_vars; cov->dim = n_vars; cov->moments = xmalloc (sizeof *cov->moments * n_MOMENTS); for (i = 0; i < n_MOMENTS; ++i) cov->moments[i] = gsl_matrix_calloc (n_vars, n_vars); cov->exclude = exclude; cov->n_cm = (n_vars * (n_vars - 1) ) / 2; cov->cm = xcalloc (cov->n_cm, sizeof *cov->cm); cov->categoricals = NULL; return cov; }
void tridiag_eigenv(double *eig, double *a, double *b, int n) { gsl_matrix *A = gsl_matrix_calloc(n, n); gsl_matrix_set (A, 0, 0, a[0]); gsl_matrix_set (A, 0, 0+1, b[0]); for(int i=1; i<n-1; i++) { gsl_matrix_set(A, i, i, a[i]); gsl_matrix_set(A, i, i+1, b[i]); gsl_matrix_set(A, i, i-1, b[i-1]); } gsl_matrix_set(A, n-1, n-1, a[n-1]); gsl_matrix_set(A, n-1, n-1-1, b[n-1-1]); gsl_vector *e = gsl_vector_alloc(n); gsl_eigen_symm_workspace *w = gsl_eigen_symm_alloc(n); gsl_eigen_symm(A, e, w); gsl_eigen_symm_free(w); gsl_matrix_free(A); gsl_sort_vector(e); for(int i=0; i<n; i++) eig[i] = gsl_vector_get(e, i); gsl_vector_free(e); return; }
int CRebuildGraph::calculateCommunicability(const char *argv[]){ CFuncTrace lFuncTrace(false,"fCalculateConnectivity"); gslGraph *targetGraph=NULL; // targetGraph=GetGraphfromFile(argv[1]); int graphOrder=targetGraph->getOrder(); lFuncTrace.trace(CTrace::TRACE_DEBUG,"Graph Order %d",graphOrder); // Get Numpy Matrix // Matriu d'adjacencia gsl_matrix *A1=gsl_matrix_calloc(graphOrder,graphOrder); //targetGraph->printGraph(); targetGraph->graphToGsl(A1); lFuncTrace.trace(CTrace::TRACE_DEBUG,"Printing Home made Matrix\n"); printGslMatrix(A1); lFuncTrace.trace(CTrace::TRACE_DEBUG,"Printing with gsl function\n"); gsl_matrix_fprintf(stdout, A1, "%g"); gsl_vector_complex *eval = calculateEgeinval(A1); /*gsl_vector *evalexp = */ calculateExp(eval); return RESULT_OK; }
static int newton_alloc (void * vstate, size_t n) { newton_state_t * state = (newton_state_t *) vstate; gsl_permutation * p; gsl_matrix * m; m = gsl_matrix_calloc (n,n); if (m == 0) { GSL_ERROR ("failed to allocate space for lu", GSL_ENOMEM); } state->lu = m ; p = gsl_permutation_calloc (n); if (p == 0) { gsl_matrix_free(m); GSL_ERROR ("failed to allocate space for permutation", GSL_ENOMEM); } state->permutation = p ; return GSL_SUCCESS; }
//Wishart distribution random number generator int ran_wishart(const gsl_rng *r, const double nu, const gsl_matrix *V, gsl_matrix *X) { const int k = V->size1; int i, j; gsl_matrix *A = gsl_matrix_calloc(k, k); gsl_matrix *L = gsl_matrix_alloc(k, k); for(i=0; i<k; i++) { gsl_matrix_set(A, i, i, sqrt(gsl_ran_chisq(r, (nu-i)))); for (j=0; j<i; j++){ gsl_matrix_set(A, i, j, gsl_ran_gaussian(r, 1)); } } gsl_matrix_memcpy(L, V); gsl_linalg_cholesky_decomp(L); gsl_blas_dtrmm(CblasLeft, CblasLower, CblasNoTrans, CblasNonUnit, 1.0, L, A); gsl_blas_dgemm(CblasNoTrans, CblasTrans, 1.0, A, A, 0.0, X); gsl_matrix_free(A); gsl_matrix_free(L); return 0; }
/* Allocate and return a gsl_matrix containing the covariances of the data. */ static gsl_matrix * cm_to_gsl (struct covariance *cov) { int i, j; gsl_matrix *m = gsl_matrix_calloc (cov->dim, cov->dim); /* Copy the non-diagonal elements from cov->cm */ for ( j = 0 ; j < cov->dim - 1; ++j) { for (i = j+1 ; i < cov->dim; ++i) { double x = cov->cm [cm_idx (cov, i, j)]; gsl_matrix_set (m, i, j, x); gsl_matrix_set (m, j, i, x); } } /* Copy the diagonal elements from cov->moments[2] */ for (j = 0 ; j < cov->dim ; ++j) { double sigma = gsl_matrix_get (cov->moments[2], j, j); gsl_matrix_set (m, j, j, sigma); } return m; }
/* Create a new matrix of NEW_SIZE x NEW_SIZE and copy the elements of matrix IN into it. IN must be a square matrix, and in normal usage it will be smaller than NEW_SIZE. IN is destroyed by this function. The return value must be destroyed when no longer required. */ static gsl_matrix * resize_matrix (gsl_matrix *in, size_t new_size) { size_t i, j; gsl_matrix *out = NULL; assert (in->size1 == in->size2); if (new_size <= in->size1) return in; out = gsl_matrix_calloc (new_size, new_size); for (i = 0; i < in->size1; ++i) { for (j = 0; j < in->size2; ++j) { double x = gsl_matrix_get (in, i, j); gsl_matrix_set (out, i, j, x); } } gsl_matrix_free (in); return out; }
/* compute compact QR factorization M is mxn; Q is mxk and R is kxk */ void compute_QR_compact_factorization(gsl_matrix *M, gsl_matrix *Q, gsl_matrix *R){ int i,j,m,n,k; m = M->size1; n = M->size2; k = min(m,n); //printf("QR setup..\n"); gsl_matrix *QR = gsl_matrix_calloc(M->size1, M->size2); gsl_vector *tau = gsl_vector_alloc(min(M->size1,M->size2)); gsl_matrix_memcpy (QR, M); //printf("QR decomp..\n"); gsl_linalg_QR_decomp (QR, tau); //printf("extract R..\n"); for(i=0; i<k; i++){ for(j=0; j<k; j++){ if(j>=i){ gsl_matrix_set(R,i,j,gsl_matrix_get(QR,i,j)); } } } //printf("extract Q..\n"); gsl_vector *vj = gsl_vector_calloc(m); for(j=0; j<k; j++){ gsl_vector_set(vj,j,1.0); gsl_linalg_QR_Qvec (QR, tau, vj); gsl_matrix_set_col(Q,j,vj); vj = gsl_vector_calloc(m); } }