void psi_4(const double * p, const double ** v, void * value) { double * val = (double *)value; double lambda[4], volume; get_lambda(p, v, lambda, &volume); val[0] = 4.0*lambda[1]*lambda[2]; }
void phi_1(const double * p, const double ** v, void * value) { double * val = (double *)value; double lambda[4]; double area; get_lambda(p, v, lambda, &area); val[0] = lambda[0]*(2*lambda[0] - 1.0); }
void gradient_phi_1(const double * p, const double ** v, void * value) { double * val = (double *)value; double lambda[4]; double area; get_lambda(p, v, lambda, &area); val[0] = (4.0*lambda[0] - 1.0)*dlambda0_dx; val[1] = (4.0*lambda[0] - 1.0)*dlambda0_dy; }
void gradient_phi_4(const double * p, const double ** v, void * value) { double * val = (double *)value; double lambda[4], volume; get_lambda(p, v, lambda, &volume); val[0] = co_det(v, 3, 0)/volume * (4.*lambda[3] - 1.); val[1] = co_det(v, 3, 1)/volume * (4.*lambda[3] - 1.); val[2] = co_det(v, 3, 2)/volume * (4.*lambda[3] - 1.); }
void PoissonStimulator::init( NeuronGroup * target, AurynFloat rate, AurynWeight w ) { sys->register_monitor(this); dst = target; set_target_state(); poisson_weight = w; poisson_rate = rate; stringstream oss; oss << scientific << "PoissonStimulator:: initializing with mean " << get_lambda(); logger->msg(oss.str(),NOTIFICATION); seed(61093*communicator->rank()); dist = new boost::poisson_distribution<int> (get_lambda()); die = new boost::variate_generator<boost::mt19937&, boost::poisson_distribution<int> > ( gen, *dist ); }
/** * @brief Determines feasible descent direction with respect to added * inequality constraints. * * @param[in] ppar parameters. * @param[in] active_set a vector of active constraints. * @param[in] x initial guess. * @param[out] dx feasible descent direction, must be allocated. */ void chol_solve::resolve ( const AS::problem_parameters& ppar, const vector <AS::constraint>& active_set, const double *x, double *dx) { int i; const int nW = active_set.size(); // backward substitution for icL for (i = nW-1; i >= 0; --i) { const int last_el_num = i + ppar.N*SMPC_NUM_STATE_VAR; nu[last_el_num] /= icL[i][last_el_num]; for (int j = active_set[i].ind; j < last_el_num; ++j) { nu[j] -= nu[last_el_num] * icL[i][j]; } } // backward substitution for ecL ecL.solve_backward(ppar.N, nu); // - i2H * E' * nu E.form_i2HETx (ppar, nu, dx); // dx = -(x + inv(H) * E' * nu) // ~~~~~~~~~~~~~~~~ // dx = -(x + dx ) for (i = 0; i < ppar.N*SMPC_NUM_VAR; i += SMPC_NUM_VAR) { // dx for state variables dx[i] -= x[i] ; dx[i+1] -= x[i+1]; dx[i+2] -= x[i+2]; dx[i+3] -= x[i+3]; dx[i+4] -= x[i+4]; dx[i+5] -= x[i+5]; dx[i+6] -= x[i+6]; dx[i+7] -= x[i+7]; } // -iH * A(W,:)' * lambda const double *lambda = get_lambda(ppar); const double i2Q0 = ppar.i2Q[0]; for (i = 0; i < nW; ++i) { constraint c = active_set[i]; dx[c.ind] -= i2Q0 * c.coef_x * lambda[i]; dx[c.ind+3] -= i2Q0 * c.coef_y * lambda[i]; } }
void gradient_psi_1(const double * p, const double ** v, void * value) { double * val = (double *)value; double lambda[4], volume; get_lambda(p, v, lambda, &volume); val[0] = 4 * (co_det(v, 1, 0)/volume * lambda[0] + co_det(v, 0, 0)/volume * lambda[1]); val[1] = 4 * (co_det(v, 1, 1)/volume * lambda[0] + co_det(v, 0, 1)/volume * lambda[1]); val[2] = 4 * (co_det(v, 1, 2)/volume * lambda[0] + co_det(v, 0, 2)/volume * lambda[1]); }
void gradient_psi_6(const double * p, const double ** v, void * value) { double * val = (double *)value; double lambda[4], volume; get_lambda(p, v, lambda, &volume); val[0] = 4 * (co_det(v, 2, 0)/volume * lambda[3] + co_det(v, 3, 0)/volume * lambda[2]); val[1] = 4 * (co_det(v, 2, 1)/volume * lambda[3] + co_det(v, 3, 1)/volume * lambda[2]); val[2] = 4 * (co_det(v, 2, 2)/volume * lambda[3] + co_det(v, 3, 2)/volume * lambda[2]); }
void phi_6(const double * p, const double ** v, void * value) { double * val = (double *)value; double lambda[4]; double area; get_lambda(p, v, lambda, &area); if (lambda[1] < 0) { val[0] = 0.; } else { val[0] = 4.0*lambda[1]*lambda[2]; } }
void phi_3(const double * p, const double ** v, void * value) { double * val = (double *)value; double lambda[4]; double area; get_lambda(p, v, lambda, &area); if (lambda[1] < 0) { val[0] = lambda[3]*(2*lambda[3] - 1.0); } else { val[0] = lambda[2]*(2*lambda[2] - 1.0); } }
void phi_4(const double * p, const double ** v, void * value) { double * val = (double *)value; double lambda[4]; double area; get_lambda(p, v, lambda, &area); if (lambda[1] < 0) { lambda[1] = -lambda[1]; val[0] = lambda[1]*(2*lambda[1] - 1.0); } else { val[0] = 0.; } }
void gradient_phi_4(const double * p, const double ** v, void * value) { double * val = (double *)value; double lambda[4]; double area; get_lambda(p, v, lambda, &area); val[0] = (4.0*lambda[1] + 1.0)*dlambda1_dx; val[1] = (4.0*lambda[1] + 1.0)*dlambda1_dy; if (fabs(lambda[1]) < 1.0e-4*area) { val[0] /= 2.0; val[1] /= 2.0; } else if (lambda[1] > 0) { val[0] = 0.0; val[1] = 0.0; } }
void gradient_phi_8(const double * p, const double ** v, void * value) { double * val = (double *)value; double lambda[4]; double area; get_lambda(p, v, lambda, &area); val[0] = -4.0*(lambda[0]*dlambda1_dx + lambda[1]*dlambda0_dx); val[1] = -4.0*(lambda[0]*dlambda1_dy + lambda[1]*dlambda0_dy); if (fabs(lambda[1]) < 1.0e-4*area) { val[0] /= 2.0; val[1] /= 2.0; } else if (lambda[1] > 0) { val[0] = 0.0; val[1] = 0.0; } }
void gradient_phi_3(const double * p, const double ** v, void * value) { double * val = (double *)value; double lambda[4]; double area; get_lambda(p, v, lambda, &area); if (fabs(lambda[1]) < 1.0e-4*area) { val[0] = 0.5*((4.0*lambda[2] - 1.0)*dlambda20_dx + (4.0*lambda[3] - 1.0)*dlambda21_dx); val[1] = 0.5*((4.0*lambda[2] - 1.0)*dlambda20_dy + (4.0*lambda[3] - 1.0)*dlambda21_dy); } else if (lambda[1] > 0) { val[0] = (4.0*lambda[2] - 1.0)*dlambda20_dx; val[1] = (4.0*lambda[2] - 1.0)*dlambda20_dy; } else { val[0] = (4.0*lambda[3] - 1.0)*dlambda21_dx; val[1] = (4.0*lambda[3] - 1.0)*dlambda21_dy; } }
void gradient_phi_9(const double * p, const double ** v, void * value) { double * val = (double *)value; double lambda[4]; double area; get_lambda(p, v, lambda, &area); if (fabs(lambda[1]) < 1.0e-4*area) { val[0] = 2.0*(lambda[0]*dlambda20_dx + lambda[2]*dlambda0_dx) + 2.0*(lambda[0]*dlambda21_dx + lambda[3]*dlambda0_dx); val[1] = 2.0*(lambda[0]*dlambda20_dy + lambda[2]*dlambda0_dy) + 2.0*(lambda[0]*dlambda21_dy + lambda[3]*dlambda0_dy); } else if (lambda[1] > 0) { val[0] = 4.0*(lambda[0]*dlambda20_dx + lambda[2]*dlambda0_dx); val[1] = 4.0*(lambda[0]*dlambda20_dy + lambda[2]*dlambda0_dy); } else { val[0] = 4.0*(lambda[0]*dlambda21_dx + lambda[3]*dlambda0_dx); val[1] = 4.0*(lambda[0]*dlambda21_dy + lambda[3]*dlambda0_dy); } }
int test2() { auto L = get_lambda(); L(3); }
void read_pssm(unsigned char *aa0, int n0, int nsq, double pamscale, FILE *fp, struct pstruct *ppst) { int i, j, len; int qi, rj; int **pam2p; int first, too_high; char *query; double freq, **freq2d, lambda, new_lambda; double scale, scale_high, scale_low; pam2p = ppst->pam2p[0]; if(1 != fread(&len, sizeof(int), 1, fp)) { fprintf(stderr, "error reading from checkpoint file: %d\n", len); exit(1); } if(len != n0) { fprintf(stderr, "profile length (%d) and query length (%d) don't match!\n", len,n0); exit(1); } /* read over query sequence stored in BLAST profile */ if(NULL == (query = (char *) calloc(len, sizeof(char)))) { fprintf(stderr, "Couldn't allocate memory for query!\n"); exit(1); } if(len != fread(query, sizeof(char), len, fp)) { fprintf(stderr, "Couldn't read query sequence from profile: %s\n", query); exit(1); } printf("%d\n%s\n",len,query); /* currently we don't do anything with query; ideally, we should check to see that it actually matches aa0 ... */ /* quick 2d array alloc: */ if((freq2d = (double **) calloc(n0, sizeof(double *))) == NULL) { fprintf(stderr, "Couldn't allocate memory for frequencies!\n"); exit(1); } if((freq2d[0] = (double *) calloc(n0 * N_EFFECT, sizeof(double))) == NULL) { fprintf(stderr, "Couldn't allocate memory for frequencies!\n"); exit(1); } /* a little pointer arithmetic to fill out 2d array: */ for (qi = 1 ; qi < n0 ; qi++) { freq2d[qi] = freq2d[0] + (N_EFFECT * qi); } for (qi = 0 ; qi < n0 ; qi++) { printf("%c",query[qi]); for (rj = 0 ; rj < N_EFFECT ; rj++) { if(1 != fread(&freq, sizeof(double), 1, fp)) { fprintf(stderr, "Error while reading frequencies!\n"); exit(1); } printf(" %8.7g",freq*10.0); if (freq > 1e-12) { freq = log(freq /((double) (rrcounts[rj+1])/(double) rrtotal)); freq /= pamscale; /* this gets us close to originial pam scores */ freq2d[qi][rj] = freq; } else {freq2d[qi][rj] = freq;} } printf("\n"); } /* now figure out the right scale */ scale = 1.0; lambda = get_lambda(ppst->pam2[0], 20, 20, "\0ARNDCQEGHILKMFPSTWYV"); /* should be near 1.0 because of our initial scaling by ppst->pamscale */ fprintf(stderr, "real_lambda: %g\n", lambda); /* get initial high/low scale values: */ first = 1; while (1) { fill_pam(pam2p, n0, 20, freq2d, scale); new_lambda = get_lambda(pam2p, n0, 20, query); if (new_lambda > lambda) { if (first) { first = 0; scale = scale_high = 1.0 + 0.05; scale_low = 1.0; too_high = 1; } else { if (!too_high) break; scale = (scale_high += scale_high - 1.0); } } else if (new_lambda > 0) { if (first) { first = 0; scale_high = 1.0; scale = scale_low = 1.0 - 0.05; too_high = 0; } else { if (too_high) break; scale = (scale_low += scale_low - 1.0); } } else { fprintf(stderr, "new_lambda (%g) <= 0; matrix has positive average score", new_lambda); exit(1); } } /* now do binary search between low and high */ for (i = 0 ; i < 10 ; i++) { scale = 0.5 * (scale_high + scale_low); fill_pam(pam2p, n0, 20, freq2d, scale); new_lambda = get_lambda(pam2p, n0, 20, query); if (new_lambda > lambda) scale_low = scale; else scale_high = scale; } scale = 0.5 * (scale_high + scale_low); fill_pam(pam2p, n0, 20, freq2d, scale); fprintf(stderr, "final scale: %g\n", scale); for (qi = 0 ; qi < n0 ; qi++) { fprintf(stderr, "%4d %c: ", qi+1, query[qi]); for (rj = 1 ; rj <= 20 ; rj++) { fprintf(stderr, "%4d", pam2p[qi][rj]); } fprintf(stderr, "\n"); } free(freq2d[0]); free(freq2d); free(query); }
void PoissonStimulator::set_rate(AurynFloat rate) { delete dist; poisson_rate = rate; dist = new boost::poisson_distribution<int> (get_lambda()); }