Beispiel #1
0
double q_f(int df1, int df2, double f)  /* ¾å¦ÎßÀѳÎΨ */
{
    int i;
    double cos2, sin2, prob, temp;

    if (f <= 0) return 1;
    if (df1 % 2 != 0 && df2 % 2 == 0)
        return 1 - q_f(df2, df1, 1 / f);
    cos2 = 1 / (1 + df1 * f / df2);  sin2 = 1 - cos2;
    if (df1 % 2 == 0) {
        prob = pow(cos2, df2 / 2.0);  temp = prob;
        for (i = 2; i < df1; i += 2) {
            temp *= (df2 + i - 2) * sin2 / i;
            prob += temp;
        }
        return prob;
    }
    prob = atan(sqrt(df2 / (df1 * f)));
    temp = sqrt(sin2 * cos2);
    for (i = 3; i <= df1; i += 2) {
        prob += temp;  temp *= (i - 1) * sin2 / i;
    }
    temp *= df1;
    for (i = 3; i <= df2; i += 2) {
        prob -= temp;
        temp *= (df1 + i - 2) * cos2 / i;
    }
    return prob * 2 / PI;
}
Beispiel #2
0
mat Wavefunction::q_force() {
    mat q_f = zeros(n_particles, dim);

    //#if NUMERICAL  
#if 0
    double h = 0.05;

    mat r_plus = zeros(n_particles, dim);
    mat r_minus = zeros(n_particles, dim);

    // Initiating r_plus and r_minus.
    r_plus = r_new;
    r_minus = r_new;

    // Calculating the Quantum Force numerically.
    for (int i = 0; i < n_particles; i++) {
        for (int j = 0; j < dim; j++) {
            r_plus(i, j) += h;
            r_minus(i, j) -= h;
            q_f(i, j) = 2 * (evaluate(r_plus) - evaluate(r_minus)) / (2 * h * evaluate(r_new));
            r_plus(i, j) = r_new(i, j);
            r_minus(i, j) = r_new(i, j);
        }
    }
#else
    rowvec gradient_slater;
    rowvec gradient_jastrow;
    double R = slater->get_ratio();
    
    for (int i = 0; i < n_particles; i++) {

        // Finding the Orbitals' gradient.
        slater->compute_gradient(i);
        gradient_slater = slater->get_gradient();

        // Finding the Jastrow's gradient.
        jas->compute_gradient(r_new, i);
        gradient_jastrow = jas->get_gradient();

        q_f.row(i) = 2 * (gradient_jastrow + gradient_slater)/R;
    }
#endif
    return q_f;
}
Beispiel #3
0
double p_f(int df1, int df2, double f)  /* ²¼Â¦ÎßÀѳÎΨ */
{
    if (f <= 0) return 0;
    return q_f(df2, df1, 1 / f);
}
Beispiel #4
0
Datei: ci.cpp Projekt: cran/lm.br
int Clmbr::ci_af( METHOD met, double * bds )
// using AF to calculate significance level
{
	double  th,  sl_th,  thold;
	int  k,  numi=0,  ind=0;	// ind = indicator = 0 if sl was below SL, 1 if above


	if( Model==M3 )  {

		const double  sl_inf= sl(-Inf,met,false);

		const double  yx = *pqy*pqx[0],  y1 = *pqy*pq1[0],  thzero =yx/y1; 
		const double  ya =yx*qx1[0]-y1*qxx[0],  yb =yx*q11[0]-y1*qx1[0],  thk =ya/yb;
		const double  th1 = min(thk,thzero),  th2 = max(thk,thzero);


		th= min( -1., xs[0] );
		th= min( th, th1 );
		th *= 2,  sl_th= sl( th, met, false );
		int it =0;
		while( fabs( sl_th - sl_inf ) > tol_sl_abs  &&  it < 18 )  
			th *= 2,  sl_th= sl(th,met,false),  it++;
		if (sl_th > SL)  bds[numi++] = -Inf,  ind=1;
		thold= th;

		if ( th1 < xs[0]) {
			th = th1;
			sl_th = sl( th, met, false );
			if (sl_th > SL && ind==0) {
				bds[numi++] = bisect_sl( thold, th, met, -tol_xb );
				ind=1;
			}
			if (sl_th < SL && ind==1) {
				bds[numi++] = bisect_sl( thold, th, met, -tol_xb );
				ind=0;
			}
			thold = th;
		}

		if ( th2 < xs[0]) {
			th = th2;
			sl_th = sl( th, met, false );
			if (sl_th > SL && ind==0) {
				bds[numi++] = bisect_sl( thold, th, met, -tol_xb );
				ind=1;
			}
			if (sl_th < SL && ind==1) {
				bds[numi++] = bisect_sl( thold, th, met, -tol_xb );
				ind=0;
			}
			thold = th;
		}

		th = xs[0];
		sl_th = sl( th, met, false );
		if (sl_th > SL && ind==0) {
			bds[numi++] = bisect_sl( thold, th, met, -tol_xb );
			ind=1;
		}
		if (sl_th < SL && ind==1) {
			bds[numi++] = bisect_sl( thold, th, met, -tol_xb );
			ind=0;
		}
		thold = th;


	}  else  {
	

// if Model=M1, treat regions before xs[0] and after xs[ns-1] as two seperate regions

// check region before xs[0]
		th = xs[0] - 1.;
		sl_th = sl( th, met, false );
		if (sl_th > SL) {
			bds[numi++] = -Inf;
			ind=1;
		}

// check first end interval
		if (Model==M1) {
			th = xs[1]; 
			sl_th = sl( th, met, false );
			if (sl_th > SL && ind==0) {
				bds[numi++] = xs[0];
				ind=1;
			}
			if (sl_th < SL && ind==1) {
				bds[numi++] = xs[0];
				ind=0;
			}
		}

	}


//check critical points
// (gamma*sy)^2 is monotonic between each of  xs[k],  'thzero' where gamma*sy=0,  'thk' where d(gamma*sy)=0,  and  xs[k+1]

	int  ki = max(k1,0);
	double  yf = *pqy*q_f(xs[ki],ki);
	thold = xs[ki];

	for (k=ki;k<ns-2;k++) 
	{
		const double  y1 = *pqy*pq1[k+1],  yx = yf + y1*xs[k];	
		yf = yx - y1*xs[k+1];

		const double ya =yx*qx1[k+1]-y1*qxx[k+1], yb =yx*q11[k+1]-y1*qx1[k+1], thk =ya/yb, thzero =yx/y1;

		const double th1 = min(thk,thzero), th2 = max(thk,thzero);

		if (xs[k] < th1 && th1 < xs[k+1]) {
			th = th1;
			sl_th = sl( th, met, false );
			if (sl_th > SL && ind==0) {
				bds[numi++] = bisect_sl( thold, th, met, -tol_xb );
				ind=1;
			}
			if (sl_th < SL && ind==1) {
				bds[numi++] = bisect_sl( thold, th, met, -tol_xb );
				ind=0;
			}
			thold = th;
		}

		if (xs[k] < th2 && th2 < xs[k+1]) {
			th = th2;
			sl_th = sl(th,met,false);
			if (sl_th > SL && ind==0) {
				bds[numi++] = bisect_sl(thold,th,met,-tol_xb);
				ind=1;
			}
			if (sl_th < SL && ind==1) {
				bds[numi++] = bisect_sl(thold,th,met,-tol_xb);
				ind=0;
			}
			thold = th;
		}

		th = xs[k+1];
		sl_th = sl(th,met,false);
		if (sl_th > SL && ind==0) {
			bds[numi++] = bisect_sl(thold,th,met,-tol_xb);
			ind=1;
		}
		if (sl_th < SL && ind==1) {
			bds[numi++] = bisect_sl(thold,th,met,-tol_xb);
			ind=0;
		}
		thold = th;

	}



// check final end interval
	th = (xs[ns-1]+xs[ns-2])/2.;
	sl_th = sl(th,met,false);
	if (sl_th > SL && ind==0) {
		bds[numi++] = bisect_sl(thold,xs[ns-2],met,-tol_xb);
		ind=1;
	}
	if (sl_th < SL && ind==1) {
		bds[numi++] = bisect_sl(thold,xs[ns-2],met,-tol_xb);
		ind=0;
	}

// check region after xs[ns-1]
	th = xs[ns-1]+1.;
	sl_th = sl(th,met,false);
	if (sl_th > SL && ind==0) {
		bds[numi++] = xs[ns-1];
		bds[numi++] = Inf;
	}
	if (sl_th < SL && ind==1) bds[numi++] = xs[ns-1];
	if (sl_th > SL && ind==1) bds[numi++] = Inf;


	return numi/2;
}