static int secs2d_matrix_row_df_J(const double theta, const double phi, gsl_vector *X, gsl_vector *Y, gsl_vector *Z, secs2d_state_t *state) { size_t i, j; gsl_vector_set_zero(X); gsl_vector_set_zero(Y); gsl_vector_set_zero(Z); for (i = 0; i < state->ntheta; ++i) { double theta0 = state->theta0[i]; for (j = 0; j < state->nphi; ++j) { double phi0 = state->phi0[j]; size_t pole_idx = secs2d_idx(i, j, state); double J[3]; /* compute divergence-free 1D SECS Green's functions */ secs2d_green_df_J(theta, phi, theta0, phi0, J, state); gsl_vector_set(X, state->df_offset + pole_idx, J[0]); gsl_vector_set(Y, state->df_offset + pole_idx, J[1]); gsl_vector_set(Z, state->df_offset + pole_idx, J[2]); } } return 0; }
ambisonicWeight::ambisonicWeight(int anOrder, int aVectorSize, std::string anOptimMode) { m_order = anOrder; m_number_of_harmonics = m_order * 2 + 1; m_number_of_outputs = m_number_of_harmonics; m_number_of_inputs = m_number_of_harmonics; m_vector_size = aVectorSize; m_speakers_angles = new double[m_order]; m_index_of_harmonics = new int[m_number_of_harmonics]; m_optimVector = new double[m_number_of_harmonics]; m_input_vector = gsl_vector_alloc(m_number_of_harmonics * m_number_of_harmonics); m_input_vector_view = new gsl_vector_view[m_number_of_harmonics]; m_output_vector = gsl_vector_alloc(m_number_of_harmonics * m_number_of_harmonics); m_output_vector_view = new gsl_vector_view[m_number_of_harmonics]; gsl_vector_set_zero(m_input_vector); gsl_vector_set_zero(m_output_vector); for (int j = 0; j < m_number_of_harmonics; j++) { m_input_vector_view[j] = gsl_vector_subvector(m_input_vector, j * m_number_of_harmonics, m_number_of_harmonics); m_output_vector_view[j] = gsl_vector_subvector(m_output_vector, j * m_number_of_harmonics, m_number_of_harmonics); } computeIndex(); computeAngles(); computePseudoInverse(); setOptimMode(anOptimMode); }
int gsl_linalg_COD_lssolve (const gsl_matrix * QRZ, const gsl_vector * tau_Q, const gsl_vector * tau_Z, const gsl_permutation * perm, const size_t rank, const gsl_vector * b, gsl_vector * x, gsl_vector * residual) { const size_t M = QRZ->size1; const size_t N = QRZ->size2; if (M < N) { GSL_ERROR ("QRZ matrix must have M>=N", GSL_EBADLEN); } else if (M != b->size) { GSL_ERROR ("matrix size must match b size", GSL_EBADLEN); } else if (rank > GSL_MIN (M, N)) { GSL_ERROR ("rank must be <= MIN(M,N)", GSL_EBADLEN); } else if (N != x->size) { GSL_ERROR ("matrix size must match solution size", GSL_EBADLEN); } else if (M != residual->size) { GSL_ERROR ("matrix size must match residual size", GSL_EBADLEN); } else { gsl_matrix_const_view R11 = gsl_matrix_const_submatrix (QRZ, 0, 0, rank, rank); gsl_vector_view QTb1 = gsl_vector_subvector(residual, 0, rank); gsl_vector_view x1 = gsl_vector_subvector(x, 0, rank); gsl_vector_set_zero(x); /* compute residual = Q^T b */ gsl_vector_memcpy(residual, b); gsl_linalg_QR_QTvec (QRZ, tau_Q, residual); /* solve x1 := R11^{-1} (Q^T b)(1:r) */ gsl_vector_memcpy(&(x1.vector), &(QTb1.vector)); gsl_blas_dtrsv(CblasUpper, CblasNoTrans, CblasNonUnit, &(R11.matrix), &(x1.vector)); /* compute Z^T ( R11^{-1} x1; 0 ) */ cod_householder_ZTvec(QRZ, tau_Z, rank, x); /* compute x = P Z^T ( R11^{-1} x1; 0 ) */ gsl_permute_vector_inverse(perm, x); /* compute residual = b - A x = Q (Q^T b - R [ R11^{-1} x1; 0 ]) */ gsl_vector_set_zero(&(QTb1.vector)); gsl_linalg_QR_Qvec(QRZ, tau_Q, residual); return GSL_SUCCESS; } }
void Compute_Forces(gsl_matrix * Positions, gsl_matrix * Velocities, gsl_matrix * Neighbors, gsl_vector * ListHead, gsl_vector * List, int type1, int type2, gsl_matrix * Forces, gsl_vector * Energy, gsl_vector * Kinetic ) { // RESET MATRICES AND VECTORS // TODO: Redundant? gsl_matrix_set_zero(Forces); gsl_vector_set_zero(Energy); gsl_vector_set_zero(Kinetic); // Begin of parallel region int omp_get_max_threads(); int chunks = NParticles / omp_get_max_threads(); #pragma omp parallel { #pragma omp for schedule (dynamic,chunks) for (int i=0;i<NParticles;i++) { gsl_vector_view vi = gsl_matrix_row(Velocities, i); double * fij = malloc(3*sizeof(double)); // Compute the kinetic energy of particle i (0.5 mi vi^2) double ei = KineticEnergy(&vi.vector, (int) gsl_matrix_get(Positions,i,0)); gsl_vector_set(Kinetic,i,ei); // Obtain the list of neighboring cells to iCell (the cell i belongs to) int iCell = FindParticle(Positions,i); gsl_vector_view NeighboringCells = gsl_matrix_row(Neighbors, iCell); // Obtain the list of neighboring particles that interacts with i // i interacts with all Verlet[j] particles (j = 0 .. NNeighbors-1) int * Verlet = malloc(27 * NParticles * sizeof(int) / (Mx*My*Mz)); int NNeighbors = Compute_VerletList(Positions, i, &NeighboringCells.vector, iCell, ListHead, List, Verlet); // Loop over all the j-neighbors of i-particle for (int j=0;j<NNeighbors;j++) { ei = Compute_Force_ij(Positions, i, Verlet[j], type1, type2, fij); Forces->data[i*Forces->tda + 0] += fij[0]; Forces->data[i*Forces->tda + 1] += fij[1]; Forces->data[i*Forces->tda + 2] += fij[2]; Energy->data[i*Energy->stride] += ei; } free(Verlet); free(fij); } } // End of parallel region }
void Testinca(CuTest* tc) { gsl_rng* r = gsl_rng_alloc(gsl_rng_default); gsl_vector* x[2]; for(int m=0; m<2; m++) { x[m] = gsl_vector_alloc(1); gsl_vector_set(x[m], 0, 0.1 * ((double) m)); } double inc = 0.2; double suff = 0.0; mcmclib_mh_q* q = mcmclib_mh_q_alloc(r, sampler, NULL, &inc, NULL); gsl_vector* x_trash = gsl_vector_alloc(1); gsl_vector_set_zero(x_trash); mcmclib_mh* mh = mcmclib_mh_alloc(r, dtarget, NULL, q, x_trash); mcmclib_amh* amh = mcmclib_amh_alloc(mh, 0, &suff, NULL, update_suff, NULL); mcmclib_inca* s = mcmclib_inca_alloc(amh, x, 2); double suff_check = 0.0; for(int n=0; n<2; n++) { mcmclib_inca_update(s); for(int m=0; m<2; m++) suff_check += v0(x[m]); CuAssertTrue(tc, check_dequal(suff, suff_check)); } CuAssertTrue(tc, check_dequal(v0(x[0]), inc * 2)); CuAssertTrue(tc, check_dequal(v0(x[1]), inc * 2 + 0.1)); gsl_vector_free(x_trash); mcmclib_inca_free(s); for(int m=0; m<2; m++) gsl_vector_free(x[m]); gsl_rng_free(r); }
double mcmclib_mcar_model_phi_fcond(mcmclib_mcar_model* in_p, size_t i, gsl_vector* x) { mcmclib_mcar_tilde_lpdf* lpdf = in_p->lpdf; const size_t p = lpdf->p; if(x->size != p) { static char msg[1024]; sprintf(msg, "'x' vector size is %zd, it should be %zd", x->size, p); GSL_ERROR(msg, GSL_FAILURE); } assert(x->size == p); gsl_matrix* W = lpdf->M; const double mi = 1.0 / gsl_vector_get(lpdf->m, i); gsl_matrix* Lambdaij = lpdf->Lambda_ij; gsl_vector* mean = gsl_vector_alloc(p); gsl_vector_set_zero(mean); for(size_t j=0; j < lpdf->n; j++) { if(gsl_matrix_get(W, i, j) == 1.0) { gsl_vector_view phij_v = gsl_vector_subvector(in_p->e, j*p, p); gsl_blas_dgemv(CblasNoTrans, mi, Lambdaij, &phij_v.vector, 1.0, mean); } } gsl_matrix* Gammai = lpdf->Gammai; gsl_matrix_memcpy(Gammai, lpdf->Gamma); gsl_matrix_scale(Gammai, mi); mcmclib_mvnorm_lpdf* tmp = mcmclib_mvnorm_lpdf_alloc(mean, Gammai->data); double ans = mcmclib_mvnorm_lpdf_compute(tmp, x); gsl_vector_free(mean); mcmclib_mvnorm_lpdf_free(tmp); return ans; }
int resudial_itegral_r(const gsl_vector *in, void * p, gsl_vector *out){ struct mu_data_fit * mu = (struct mu_data_fit *)p; struct fit_params fp = {in->data[0], in->data[1], in->data[2], \ in->data[3], in->data[4], in->data[5]} ; gsl_vector_set_zero(out); /* for (int i =0; i< in->size; i++){ printf("%14.5f", gsl_vector_get (in, i)) ; } printf("\n") ; */ size_t vsize= mu->k->size; gsl_vector *fftR_abs = gsl_vector_alloc(vsize/2); compute_itegral_r(mu, fp, fftR_abs); size_t irmin=search_min(mu->r, mu->rmin - 0.5*mu->dwr); size_t irmax=search_min(mu->r, mu->rmax + 0.5*mu->dwr); int j=0, istep = (irmax-irmin)/MAX_FIT_POINTS; for (int i =0; i< out->size; i+=istep){ double df = gsl_vector_get(fftR_abs, i+irmin) - gsl_vector_get(mu->mu_ft, i+irmin); gsl_vector_set(out, j, df); //printf("%10.5f", gsl_vector_get (out, i)) ; j++; } gsl_vector_free(fftR_abs); return GSL_SUCCESS;}
/** * Evaluate the delayed vector field from fields for each delay. * \param[in] state State at which to evaluate the vector field. * \param[out] field Vector resulting from the evaluation of the vector field. */ void vectorFieldDelay::evalField(gsl_matrix *state, gsl_vector *field) { gsl_vector_view delayedState; unsigned int delay; // Set field evaluation to 0 gsl_vector_set_zero(field); /** Add delayed drifts */ for (size_t d = 0; d < nDelays; d++) { delay = gsl_vector_uint_get(delays, nDelays - d - 1); // Assign pointer to delayed state delayedState = gsl_matrix_row(state, delay); // Evaluate vector field at delayed state fields->at(nDelays - d - 1)->evalField(&delayedState.vector, work); // Add to newState in workspace gsl_vector_add(field, work); } return; }
int compute_itegral(const gsl_vector *k, const void * p, gsl_vector *out){ //delta=phase_f(k)+phc_f(k); omega= 2.0*k struct fit_params * fp = (struct fit_params *)p; double L=10.0, result, error; gsl_function F; struct student_params params; params.mu=fp->mu; params.sig=fp->sig; params.skew=fp->skew; params.nu=fp->nu; F.function = &itegral_student; F.params = ¶ms; if ( params.nu < -1. ) { gsl_vector_set_zero(out); return GSL_SUCCESS; } gsl_integration_workspace * w = gsl_integration_workspace_alloc (10000); for (int i=0; i< k->size; i++){ double kv=gsl_vector_get(k, i); params.delta= gsl_spline_eval(splines.pha_spline, kv, splines.acc) + \ gsl_spline_eval(splines.phc_spline, kv, splines.acc); params.omega=2.*kv; params.lam = gsl_spline_eval(splines.lam_spline, kv, splines.acc); //printf("%12.5f %12.5f %12.5f %12.5f %12.5f %12.5f\n", kv, params.delta, params.lam, params.mu, params.sig, params.skew ); gsl_integration_qag(&F, 0.1, L, 0., 1e-8, 1000, GSL_INTEG_GAUSS51, w, &result, &error); //gsl_integration_qawo (&F, 0., 0., 1e-7, 100, w, int_table, &result, &error); //amp=N*S02*mag_f(k_var)*np.power(k_f(k_var), kweight-1.0)*tmp result*=double(N)*(-1.*fp->S02)*gsl_spline_eval(splines.mag_spline, kv, splines.acc)/kv; gsl_vector_set(out, i, result); } gsl_integration_workspace_free (w); return GSL_SUCCESS;}
static void moveGN( const gsl_matrix *Vt, const gsl_vector *sig2, const gsl_vector *ufuncsig, double lambda2, gsl_vector * dx, int k, gsl_vector * scaling ) { gsl_vector_set_zero(dx); double threshold = gsl_vector_get(sig2, 0) * Vt->size2 * DBL_EPSILON * 100; size_t i; for (i = 0; (i<sig2->size) &&(gsl_vector_get(sig2, i) >= threshold); i++) { gsl_vector VtRow = gsl_matrix_const_row(Vt, i).vector; gsl_blas_daxpy(gsl_vector_get(ufuncsig, i) / (gsl_vector_get(sig2, i) * gsl_vector_get(sig2, i) + lambda2), &VtRow, dx); } /* if (i >= k) { PRINTF("Pseudoinverse threshold exceeded.\n"); PRINTF("Threshold: %g, i: %d, last: %g, next: %g\n", threshold, i, gsl_vector_get(sig2, i-1), gsl_vector_get(sig2, i)); }*/ if (scaling != NULL) { gsl_vector_mul(dx, scaling); } }
void VarproFunction::computeJacobianOfCorrection( const gsl_vector* yr, const gsl_matrix *Rorig, const gsl_matrix *perm, gsl_matrix *jac ) { size_t nrow = perm != NULL ? perm->size2 : getNrow(); gsl_matrix_set_zero(jac); gsl_matrix_set_zero(myTmpGradR); fillZmatTmpJac(myTmpJac, yr, Rorig, 1); for (size_t i = 0; i < perm->size2; i++) { for (size_t j = 0; j < getD(); j++) { gsl_vector_view jac_col = gsl_matrix_column(jac, i * getD() + j); /* Compute first term (correction of Gam^{-1} z_{ij}) */ gsl_vector_set_zero(myTmpCorr); mulZmatPerm(myTmpJacobianCol, myTmpJac, perm, i, j); myGam->multInvGammaVector(myTmpJacobianCol); myStruct->multByGtUnweighted(myTmpCorr, Rorig, myTmpJacobianCol, -1, 1); /* Compute second term (gamma * dG_{ij} * yr) */ gsl_matrix_set_zero(myTmpGradR); setPhiPermCol(i, perm, myPhiPermCol); gsl_matrix_set_col(myTmpGradR, j, myPhiPermCol); myStruct->multByGtUnweighted(myTmpCorr, myTmpGradR, yr, -1, 1); myStruct->multByWInv(myTmpCorr, 1); gsl_vector_memcpy(&jac_col.vector, myTmpCorr); } } }
int gsl_multifit_linear_Lk(const size_t p, const size_t k, gsl_matrix *L) { if (p <= k) { GSL_ERROR("p must be larger than derivative order", GSL_EBADLEN); } else if (k >= GSL_MULTIFIT_MAXK - 1) { GSL_ERROR("derivative order k too large", GSL_EBADLEN); } else if (p - k != L->size1 || p != L->size2) { GSL_ERROR("L matrix must be (p-k)-by-p", GSL_EBADLEN); } else { double c_data[GSL_MULTIFIT_MAXK]; gsl_vector_view cv = gsl_vector_view_array(c_data, k + 1); size_t i, j; /* zeroth derivative */ if (k == 0) { gsl_matrix_set_identity(L); return GSL_SUCCESS; } gsl_matrix_set_zero(L); gsl_vector_set_zero(&cv.vector); gsl_vector_set(&cv.vector, 0, -1.0); gsl_vector_set(&cv.vector, 1, 1.0); for (i = 1; i < k; ++i) { double cjm1 = 0.0; for (j = 0; j < k + 1; ++j) { double cj = gsl_vector_get(&cv.vector, j); gsl_vector_set(&cv.vector, j, cjm1 - cj); cjm1 = cj; } } /* build L, the c_i are the entries on the diagonals */ for (i = 0; i < k + 1; ++i) { gsl_vector_view v = gsl_matrix_superdiagonal(L, i); double ci = gsl_vector_get(&cv.vector, i); gsl_vector_set_all(&v.vector, ci); } return GSL_SUCCESS; } } /* gsl_multifit_linear_Lk() */
static int lmniel_set(void *vstate, const gsl_vector *swts, gsl_multifit_function_fdf *fdf, gsl_vector *x, gsl_vector *f, gsl_vector *dx) { int status; lmniel_state_t *state = (lmniel_state_t *) vstate; const size_t p = x->size; size_t i; /* initialize counters for function and Jacobian evaluations */ fdf->nevalf = 0; fdf->nevaldf = 0; /* evaluate function and Jacobian at x and apply weight transform */ status = gsl_multifit_eval_wf(fdf, x, swts, f); if (status) return status; if (fdf->df) status = gsl_multifit_eval_wdf(fdf, x, swts, state->J); else status = gsl_multifit_fdfsolver_dif_df(x, swts, fdf, f, state->J); if (status) return status; /* compute rhs = -J^T f */ gsl_blas_dgemv(CblasTrans, -1.0, state->J, f, 0.0, state->rhs); #if SCALE gsl_vector_set_zero(state->diag); #else gsl_vector_set_all(state->diag, 1.0); #endif /* set default parameters */ state->nu = 2; #if SCALE state->mu = state->tau; #else /* compute mu_0 = tau * max(diag(J^T J)) */ state->mu = -1.0; for (i = 0; i < p; ++i) { gsl_vector_view c = gsl_matrix_column(state->J, i); double result; /* (J^T J)_{ii} */ gsl_blas_ddot(&c.vector, &c.vector, &result); state->mu = GSL_MAX(state->mu, result); } state->mu *= state->tau; #endif return GSL_SUCCESS; } /* lmniel_set() */
int lls_reset(lls_workspace *w) { gsl_matrix_set_zero(w->ATA); gsl_vector_set_zero(w->ATb); w->bTb = 0.0; return 0; }
void operator()(gsl_vector* phi,const input_type& input) const { gsl_vector_set_zero(phi); check(phi); switch(input) { case 0: gsl_vector_set(phi,3,1); break; case 1: gsl_vector_set(phi,2,0.25); gsl_vector_set(phi,3,0.75); break; case 2: gsl_vector_set(phi,2,0.5); gsl_vector_set(phi,3,0.5); break; case 3: gsl_vector_set(phi,2,0.75); gsl_vector_set(phi,3,0.25); break; case 4: gsl_vector_set(phi,2,1); break; case 5: gsl_vector_set(phi,1,0.25); gsl_vector_set(phi,2,0.75); break; case 6: gsl_vector_set(phi,1,0.5); gsl_vector_set(phi,2,0.5); break; case 7: gsl_vector_set(phi,1,0.75); gsl_vector_set(phi,2,0.25); break; case 8: gsl_vector_set(phi,1,1); break; case 9: gsl_vector_set(phi,0,0.25); gsl_vector_set(phi,1,0.75); break; case 10: gsl_vector_set(phi,0,0.5); gsl_vector_set(phi,1,0.5); break; case 11: gsl_vector_set(phi,0,0.75); gsl_vector_set(phi,1,0.25); break; case 12: gsl_vector_set(phi,0,1); break; default: throw BadPhase(input,"in rl::problem::boyan_chain::Feature::operator()"); } }
int gsl_linalg_QRPT_lssolve2 (const gsl_matrix * QR, const gsl_vector * tau, const gsl_permutation * p, const gsl_vector * b, const size_t rank, gsl_vector * x, gsl_vector * residual) { const size_t M = QR->size1; const size_t N = QR->size2; if (M < N) { GSL_ERROR ("QR matrix must have M>=N", GSL_EBADLEN); } else if (M != b->size) { GSL_ERROR ("matrix size must match b size", GSL_EBADLEN); } else if (rank == 0 || rank > N) { GSL_ERROR ("rank must have 0 < rank <= N", GSL_EBADLEN); } else if (N != x->size) { GSL_ERROR ("matrix size must match solution size", GSL_EBADLEN); } else if (M != residual->size) { GSL_ERROR ("matrix size must match residual size", GSL_EBADLEN); } else { gsl_matrix_const_view R11 = gsl_matrix_const_submatrix (QR, 0, 0, rank, rank); gsl_vector_view QTb1 = gsl_vector_subvector(residual, 0, rank); gsl_vector_view x1 = gsl_vector_subvector(x, 0, rank); size_t i; /* compute work = Q^T b */ gsl_vector_memcpy(residual, b); gsl_linalg_QR_QTvec (QR, tau, residual); /* solve R_{11} x(1:r) = [Q^T b](1:r) */ gsl_vector_memcpy(&(x1.vector), &(QTb1.vector)); gsl_blas_dtrsv (CblasUpper, CblasNoTrans, CblasNonUnit, &(R11.matrix), &(x1.vector)); /* x(r+1:N) = 0 */ for (i = rank; i < N; ++i) gsl_vector_set(x, i, 0.0); /* compute x = P y */ gsl_permute_vector_inverse (p, x); /* compute residual = b - A x = Q (Q^T b - R x) */ gsl_vector_set_zero(&(QTb1.vector)); gsl_linalg_QR_Qvec(QR, tau, residual); return GSL_SUCCESS; } }
static void take_step (const gsl_vector * x, const gsl_vector * p, double step, double lambda, gsl_vector * x1, gsl_vector * dx) { gsl_vector_set_zero (dx); gsl_blas_daxpy (-step * lambda, p, dx); gsl_vector_memcpy (x1, x); gsl_blas_daxpy (1.0, dx, x1); }
/*forms asymmetric matrix with the same lower triangular part*/ inline void asym(double* a,int n){ int i; gsl_matrix_view av=gsl_matrix_view_array(a,n,n); for (i=1;i<n;i++){ gsl_vector_view vsup=gsl_matrix_superdiagonal(&av.matrix,i); gsl_vector_view vsub=gsl_matrix_subdiagonal(&av.matrix,i); gsl_vector_memcpy(&vsup.vector,&vsub.vector); gsl_vector_scale(&vsup.vector,-1); } gsl_vector_view vsup=gsl_matrix_superdiagonal(&av.matrix,0); gsl_vector_set_zero(&vsup.vector); }
/* Restart Method Instance *----------------------------------------------------------------------------*/ int ool_conmin_minimizer_restart( ool_conmin_minimizer *M ) { /* Reset dx vector */ gsl_vector_set_zero( M->dx ); /* Restart evaluation counters */ M->fcount = 0; M->gcount = 0; M->hcount = 0; return (M->type->restart)( M ); }
static int lin2_fvv (const gsl_vector * x, const gsl_vector * v, void *params, gsl_vector * fvv) { (void)x; /* avoid unused parameter warnings */ (void)v; (void)params; gsl_vector_set_zero(fvv); return GSL_SUCCESS; }
static int secs2d_matrix_row_cf_J(const double theta, gsl_vector *X, gsl_vector *Z, secs2d_state_t *state) { size_t i; gsl_vector_set_zero(X); gsl_vector_set_zero(Z); for (i = 0; i < state->ntheta; ++i) { double theta0 = state->theta0[i]; double J[3]; /* compute curl-free 1D SECS Green's functions */ secs2d_green_cf_J(state->R, theta, theta0, J, state); gsl_vector_set(X, state->cf_offset + i, J[0]); gsl_vector_set(Z, state->cf_offset + i, J[2]); } return 0; }
int penalty_fvv (const gsl_vector * x, const gsl_vector * v, void *params, gsl_vector * fvv) { const size_t p = x->size; double normv = gsl_blas_dnrm2(v); gsl_vector_set_zero(fvv); gsl_vector_set(fvv, p, 2.0 * normv * normv); (void)params; /* avoid unused parameter warning */ return GSL_SUCCESS; }
int resudial_itegral_k(const gsl_vector *in, void * p, gsl_vector *out){ struct mu_data_fit * mu = (struct mu_data_fit *)p; struct fit_params fp = {in->data[0], in->data[1], in->data[2], \ in->data[3], in->data[4], in->data[5]} ; gsl_vector_set_zero(out); compute_itegral(mu->k, &fp, out); /* for (int i =0; i< in->size; i++){ printf("%10.5f", gsl_vector_get (out, i)) ; } printf("\n") ;*/ gsl_vector_set (out, 0, 0.0) ; gsl_vector_sub(out, mu->mu); return GSL_SUCCESS;}
int gsl_linalg_LQ_lssolve_T (const gsl_matrix * LQ, const gsl_vector * tau, const gsl_vector * b, gsl_vector * x, gsl_vector * residual) { const size_t N = LQ->size1; const size_t M = LQ->size2; if (M < N) { GSL_ERROR ("LQ matrix must have M>=N", GSL_EBADLEN); } else if (M != b->size) { GSL_ERROR ("matrix size must match b size", GSL_EBADLEN); } else if (N != x->size) { GSL_ERROR ("matrix size must match solution size", GSL_EBADLEN); } else if (M != residual->size) { GSL_ERROR ("matrix size must match residual size", GSL_EBADLEN); } else { gsl_matrix_const_view L = gsl_matrix_const_submatrix (LQ, 0, 0, N, N); gsl_vector_view c = gsl_vector_subvector(residual, 0, N); gsl_vector_memcpy(residual, b); /* compute rhs = b^T Q^T */ gsl_linalg_LQ_vecQT (LQ, tau, residual); /* Solve x^T L = rhs */ gsl_vector_memcpy(x, &(c.vector)); gsl_blas_dtrsv (CblasLower, CblasTrans, CblasNonUnit, &(L.matrix), x); /* Compute residual = b^T - x^T A = (b^T Q^T - x^T L) Q */ gsl_vector_set_zero(&(c.vector)); gsl_linalg_LQ_vecQ(LQ, tau, residual); return GSL_SUCCESS; } }
int gsl_linalg_QR_lssolve (const gsl_matrix * QR, const gsl_vector * tau, const gsl_vector * b, gsl_vector * x, gsl_vector * residual) { const size_t M = QR->size1; const size_t N = QR->size2; if (M < N) { GSL_ERROR ("QR matrix must have M>=N", GSL_EBADLEN); } else if (M != b->size) { GSL_ERROR ("matrix size must match b size", GSL_EBADLEN); } else if (N != x->size) { GSL_ERROR ("matrix size must match solution size", GSL_EBADLEN); } else if (M != residual->size) { GSL_ERROR ("matrix size must match residual size", GSL_EBADLEN); } else { gsl_matrix_const_view R = gsl_matrix_const_submatrix (QR, 0, 0, N, N); gsl_vector_view c = gsl_vector_subvector(residual, 0, N); gsl_vector_memcpy(residual, b); /* compute rhs = Q^T b */ gsl_linalg_QR_QTvec (QR, tau, residual); /* Solve R x = rhs */ gsl_vector_memcpy(x, &(c.vector)); gsl_blas_dtrsv (CblasUpper, CblasNoTrans, CblasNonUnit, &(R.matrix), x); /* Compute residual = b - A x = Q (Q^T b - R x) */ gsl_vector_set_zero(&(c.vector)); gsl_linalg_QR_Qvec(QR, tau, residual); return GSL_SUCCESS; } }
static int penalty1_fvv (const gsl_vector * x, const gsl_vector * v, void *params, gsl_vector * fvv) { double u; gsl_vector_set_zero(fvv); gsl_blas_ddot(v, v, &u); gsl_vector_set(fvv, penalty1_N - 1, 2.0 * u); (void)x; /* avoid unused parameter warning */ (void)params; /* avoid unused parameter warning */ return GSL_SUCCESS; }
/*! \fn VImage VMedianImage2d (VImage src, VImage dest, int dim, VBoolean ignore) \param src input image \param dest output image \param dim kernel size \param ignore whether to ignore zero voxels */ VImage VMedianImage2d (VImage src, VImage dest, int dim, VBoolean ignore) { int nbands,nrows,ncols; int i,len,b,r,c,rr,cc,d=0; gsl_vector *vec=NULL; double u,tiny=1.0e-10; if (dim%2 == 0) VError("VMedianImage2d: dim (%d) must be odd",dim); nrows = VImageNRows (src); ncols = VImageNColumns (src); nbands = VImageNBands (src); d = dim/2; len = dim * dim; vec = gsl_vector_calloc(len); dest = VCopyImage(src,dest,VAllBands); for (b=0; b<nbands; b++) { for (r=d; r<nrows-d; r++) { for (c=d; c<ncols-d; c++) { gsl_vector_set_zero(vec); u = VGetPixel(src,b,r,c); if ( !ignore || ABS(u) > tiny) { i = 0; for (rr=r-d; rr<=r+d; rr++) { for (cc=c-d; cc<=c+d; cc++) { u = VGetPixel(src,b,rr,cc); if (ABS(u) > 0) { gsl_vector_set(vec,i,u); i++; } } } gsl_sort_vector(vec); u = gsl_stats_median_from_sorted_data(vec->data,vec->stride,i); VSetPixel(dest,b,r,c,u); } } } } return dest; }
int magcal_initcond(gsl_vector *m) { gsl_vector_set_zero(m); gsl_vector_set(m, MAGCAL_IDX_SX, 1.0); gsl_vector_set(m, MAGCAL_IDX_SY, 1.0); gsl_vector_set(m, MAGCAL_IDX_SZ, 1.0); gsl_vector_set(m, MAGCAL_IDX_OX, 0.0); gsl_vector_set(m, MAGCAL_IDX_OY, 0.0); gsl_vector_set(m, MAGCAL_IDX_OZ, 0.0); gsl_vector_set(m, MAGCAL_IDX_AXY, M_PI / 2.0); gsl_vector_set(m, MAGCAL_IDX_AXZ, M_PI / 2.0); gsl_vector_set(m, MAGCAL_IDX_AYZ, M_PI / 2.0); return GSL_SUCCESS; }
void VarproFunction::computeCorrectionAndJacobian( const gsl_matrix *R, const gsl_matrix *perm, gsl_vector *res, gsl_matrix *jac ) { computeGammaSr(R, myRorig, myTmpYr, true); myGam->multInvGammaVector(myTmpYr); if (res != NULL) { if (myIsGCD) { gsl_vector_memcpy(res, getP()); myStruct->multByGtUnweighted(res, myRorig, myTmpYr, -1, 1); } else { gsl_vector_set_zero(res); myStruct->multByGtUnweighted(res, myRorig, myTmpYr, -1, 1); } myStruct->multByWInv(res, 1); } if (jac != NULL) { computeJacobianOfCorrection(myTmpYr, R, perm, jac); } }
void measurement_fdf(const gsl_vector *v, void *params, double *f, gsl_vector *df) { Measurement *p = (Measurement *) params; double pf; gsl_vector* pdf = gsl_vector_alloc(df->size); if (pdf) { *f = 0.0; gsl_vector_set_zero(df); while (p) { df += polifunc_fdf(v, p->params, &pf, pdf); *f += pf; gsl_vector_add(df, pdf); p = p->next; } gsl_vector_free(pdf); } else { *f = GSL_NAN; gsl_vector_set_all(df, GSL_NAN); } }