/* Generates a retinal map FWHM (full width at half maximum) is used to compute appropriate sigmas for the width of the fovea, parafovea and periphery three gaussians are generated and combined to create the retinal map */ void Saliency_map::retinal_distribution(double fv, double paraF, double perif) { double periphery_sigma = FWHM_constant * perif; double fovea_sigma = FWHM_constant * fv; double parafovea_sigma = FWHM_constant * paraF; int x_mean = (int)get_width() / 2; int y_mean = (int)get_height() / 2; double fv_A = M_PI * fv * fv; double paraF_A = M_PI * paraF * paraF; double perif_A = M_PI * perif * perif; Saliency_map fovea = Saliency_map(angular_resolution, periphery_radius); Saliency_map parafovea = Saliency_map(angular_resolution, periphery_radius); Saliency_map periphery = Saliency_map(angular_resolution, periphery_radius); fovea.to_gaussian(x_mean, y_mean, fovea_sigma); parafovea.to_gaussian(x_mean, y_mean, parafovea_sigma); periphery.to_gaussian(x_mean, y_mean, periphery_sigma); linear_combination(fovea, fv_A); linear_combination(parafovea, paraF_A); linear_combination(periphery, perif_A); //normalize(); }
int minimal_residual_solver (const double *msr_matrix, const int *indexes, const int n, const double *b, double *x, double *workspace, const int my_rank, const int total_thread, const int maxit, const double eps) { double *r = workspace; // residual vector double *v = r + n; // additional vector v = Au // r = b - Ax double *u = v + n; // precond vector u = M^(-1)r int iter = 0; // iteration double c1 = 0, c2 = 0, tau = 0; // c1 = (Au, r) // c2 = (Au, Au) msr_residual (msr_matrix, indexes, n, x, b, r, my_rank, total_thread); for (iter = 0; iter < maxit; iter++) { // Mu = r multi_jacobi_preconditioner (msr_matrix, n, u, r, my_rank, total_thread); // v = Au msr_multiply_matrix (msr_matrix, indexes, n, u, v, my_rank, total_thread); // c1 = (v, r) c1 = inner_product (v, r, n, my_rank, total_thread); // c2 = (v, v) c2 = inner_product (v, v, n, my_rank, total_thread); if (c1 < eps * eps || c2 < eps * eps) break; // tau = (v, r) / (v, v) = c1 / c2 tau = c1 / c2; // x += tau * u linear_combination (x, u, tau, n, my_rank, total_thread); // r += -tau * v linear_combination (r, v, -tau, n, my_rank, total_thread); double residual = compute_vector_inf_norm (r, n, my_rank, total_thread); if (my_rank == 0) { printf ("It = %d Residual = %2.8e\n", iter, residual); } if (residual < eps * eps) break; } synchronize (total_thread); // iteration if (c1 < 0 || c2 < 0 || iter >= maxit) return -1; else return iter; }
float calcAngle(vector<float> & A, vector<float> & B, vector<float> & C) { vector<float> BA(3), BC(3); linear_combination(BA, 1, A, -1, B); linear_combination(BC, 1, C, -1, B); normalize_point(BA, BA); normalize_point(BC, BC); float dp = dot_product(BA,BC); if(dp > 1) dp = 1; else if(dp < -1) dp = -1; return RADIANS_TO_DEGREES( acos(dp) ); }
int main(){ Rat one_half = Rat(1, 2); Rat one_third = Rat(1, 3); std::cerr << one_half << std::endl; std::cerr << one_third << std::endl; std::cerr << one_half + one_third << std::endl; std::cerr << one_half + one_third << std::endl; std::cerr << linear_combination(1, 2, 3, 4) << std::endl; std::cerr << linear_combination(one_half, one_half, one_third, one_third) << std::endl; }
void Saliency_map::insert_regional_cue(double upper_asymptote, const Symbol& region) { Saliency_map cue_map = Saliency_map(angular_resolution, periphery_radius); if (region == Right_c) { cue_map.to_positive_sigmoid(upper_asymptote); } else if (region == Left_c) { cue_map.to_negative_sigmoid(upper_asymptote); } else if (region == Upper_Right_c) { cue_map.to_multivariable_sigmoid(upper_asymptote, 1); } else if (region == Upper_Left_c) { cue_map.to_multivariable_sigmoid(upper_asymptote, 2); } else if (region == Lower_Left_c) { cue_map.to_multivariable_sigmoid(upper_asymptote, 3); } else if (region == Lower_Right_c) { cue_map.to_multivariable_sigmoid(upper_asymptote, 4); } else if (region == Above_c) { cue_map.to_yaxis_sigmoid(upper_asymptote, true); } else if (region == Below_c) { cue_map.to_yaxis_sigmoid(upper_asymptote, false); } else { cue_map.flat_distribution(); } linear_combination(cue_map, 1); // FIXME: Scalar coeff??? }
void find4thPoint(vector<float>& p4, vector<float>& p1, vector<float>& p2, vector<float>& p3, float dist, float ang, float dihed) { vector<float> n1(3), n2(3), a(3), b(3); point_sub(a, p1,p2); point_sub(b, p3,p2); cross_product(n1, a,b); normalize_point(n1,n1); cross_product(n2, b,n1); normalize_point(n2,n2); double Sang = sin( DEGREES_TO_RADIANS(ang) ); double Cang = cos( DEGREES_TO_RADIANS(ang) ); double Sdihed = sin( DEGREES_TO_RADIANS(dihed) ); double Cdihed = cos( DEGREES_TO_RADIANS(dihed) ); normalize_point(b,b); //cout << point_string(b) << point_string(n1) << point_string(n2) << endl; linear_combination(p4, Sang*Cdihed, n2, -1*Cang, b); linear_combination(p4, -1*Sang*Sdihed, n1, 1, p4); //cout << point_string(p4) << endl; linear_combination(p4, dist, p4, 1, p3); }
void Saliency_map::insert_gaussian_cue( GU::Point loc, GU::Size size ) { double h_sz = size.h; double v_sz = size.v; double x_mean = loc.x; double y_mean = loc.y; double cue_sigma = FWHM_constant * h_sz * v_sz; //double cue_area = M_PI * (size / 2) * (size / 2); Saliency_map cue_map = Saliency_map(angular_resolution, periphery_radius); cue_map.to_gaussian(x_mean, y_mean, cue_sigma); linear_combination(cue_map, 1); // FIXME: Scalar coeff??? }
void Saliency_map::parafoveal_distribution(double fv, double paraF) { double parafovea_sigma = FWHM_constant * paraF; int x_mean = (int)get_width() / 2; int y_mean = (int)get_height() / 2; double paraF_A = M_PI * paraF * paraF; Saliency_map parafovea = Saliency_map(angular_resolution, periphery_radius); parafovea.to_gaussian(x_mean, y_mean, parafovea_sigma); linear_combination(parafovea, paraF_A); //normalize(get_max()); }
// on intersection of spheres c1,r1 and c2,r2 find p such that p-c1-q is of certain value, and lies on intersection of 2 spheres // this is solved by sampling points on the circle of intersection and checking the angle int findSphereSphereAngleIntx(float r1, vector<float> & c1, float r2, vector<float> & c2, vector<float> & q, float desiredAngle, vector<float>& p1, vector<float>& p2) { vector<float> c1c2(3), Y(3), Z(3), c(3); linear_combination(c1c2, 1, c2, -1, c1); double cc = magnitude(c1c2); cout << cc << endl; if(cc > r1+r2) return 0; normalize_point(c1c2, c1c2); findYZgivenX(c1c2, Y, Z); cout << "c1c2 " << c1c2[0] << " " << c1c2[1] << " " << c1c2[2] << endl; cout << "Y " << Y[0] << " " << Y[1] << " " << Y[2] << endl; cout << "Z " << Z[0] << " " << Z[1] << " " << Z[2] << endl; double c1c = (r1*r1 + cc*cc - r2*r2) / (2*cc); double r = sqrt(r1*r1 - c1c*c1c); linear_combination(c, 1, c1, c1c, c1c2); cout << "C " << c[0] << " " << c[1] << " " << c[2] << endl; float lastAngle = -999, angle, lastTheta = -999; float startTheta = 0, stopTheta = 360, step = 5; // clockwise int nsol = 0; vector<float> p(3); for(float theta = startTheta; theta <= stopTheta; theta += step) { double th = M_PI * theta / 180; linear_combination(p, 1, c, r*sin(th), Y); linear_combination(p, 1, p, r*cos(th), Z); angle = calcAngle(q, c1, p); cout << "P " << lastAngle << " " << desiredAngle << " " << angle << " " << p[0] << " " << p[1] << " " << p[2] << endl; if(lastAngle != -999 && (desiredAngle-angle)*(desiredAngle-lastAngle) <= 0) { double th = M_PI * (theta + lastTheta)/360.; if(nsol==0) { linear_combination(p1, 1, c, r*sin(th), Y); linear_combination(p1, 1, p1, r*cos(th), Z); } if(nsol==1) { linear_combination(p2, 1, c, r*sin(th), Y); linear_combination(p2, 1, p2, r*cos(th), Z); } assert(nsol!=2); nsol++; cout << "NSOL " << nsol << endl; } lastAngle = angle; lastTheta = theta; } return nsol; }
static position interpolate(GLfloat t, position p[4]) { /* de Casteljau's algorithm, 4 control points */ position p10 = linear_combination(t, p[0], p[1]); position p11 = linear_combination(t, p[1], p[2]); position p12 = linear_combination(t, p[2], p[3]); position p20 = linear_combination(t, p10, p11); position p21 = linear_combination(t, p11, p12); return linear_combination(t, p20, p21); }
// if fwd, C,N,CA are C,N,CA, else assumed to be N,C,CA void InformedPhipsiSampler::sample( vector<float>& curC, vector<float>& curN, vector<float>& curCA, float & phi, float & psi, float & omega, float & r, float & a, float & t) { float d0 = calcDist(target, curCA); float cisdist = 2.8, transdist = 3.81; bool cis = false, trans = false; if(cisdist > d0 - targetTol && cisdist < d0 + targetTol) cis = true; if(transdist > d0 - targetTol && transdist < d0 + targetTol) trans = true; if(cis && trans) { // if both cis and trans are possible, choose one if(ran01() > 0.95) trans = false; } else if(!cis && !trans) { cout << "target unreachable " <<curCA[0]<<" "<<curCA[1]<<" "<<curCA[2] << " : " << d0 <<" : "<< targetTol <<" : "<< target[0]<<" "<<target[1]<<" "<<target[2] << endl; exit(0); } // now either cis or trans is true float interCA; if(cis) { omega = 0; interCA = cisdist; } if(trans) { omega = -180; interCA = transdist; } phi = -999; psi = -999; // find a,t which take u into restraint sphere with this interCA vector<float> tar(3,0), noi(3,0); while(1) { // add some noise to target, proportional to noise randomNormalVector(noi); linear_combination(tar, 1, target, targetTol*ran01(), noi); // for this interCA, find a,t that takes you closest to target r = calcDist(curCA, tar); a = calcAngle(curN, curCA, tar); t = calcDihed(curC, curN, curCA, tar); find4thPoint(tar, curC, curN, curCA, interCA, a, t); if( calcDist(target, tar) <= targetTol ) break; } // return a phi-psi value for this a,t if available if(fwd) { RATdata & ratdata = RATdata::fwdinstance(RATdataPath.c_str()); vector<PSO>::iterator bi, ei; ratdata.range(resn, interCA, a, t, bi, ei); int rs = ei - bi; assert(rs >= 0); if(rs == 0) { return; } int incr = (int) floor ( (0.+rs) * ran01() ); bi += incr; phi = bi->r; psi = bi->a; omega = bi->t; } else { RATdata & ratdata = RATdata::bwdinstance(RATdataPath.c_str()); vector<PSO>::iterator bi, ei; ratdata.range(resn, interCA, a, t, bi, ei); int rs = ei - bi; assert(rs >= 0); if(rs == 0) { return; } int incr = (int) floor ( (0.+rs) * ran01() ); bi += incr; psi = bi->r; phi = bi->a; omega = bi->t; } //cout << phi <<" "<< psi <<" "<< omega << " shd take u from ("<< curCA[0]<<" "<< curCA[1]<<" "<< curCA[2] <<" "; //vector<float> exppt(3,0); //find4thPoint(exppt, curC, curN, curCA, interCA, a, t); //cout << ") to ("<< exppt[0]<<" "<< exppt[1]<<" "<< exppt[2] <<") " << endl;; }