Exemple #1
0
void predg3f_from_predh3f(struct predg3f_s *g, const struct predh3f_s *h)
{
    struct vec3f_s r, nr;

    calc_r(&r, &h->p.n);
    vec3f_cross(&nr, &h->p.n, &r);

    g->k = nr;
    vec3f_cross(&g->l, &h->p.n, &nr);
    g->a = h->b;
    vec3f_neg(&g->b, &h->b);
    g->c = 2 * h->p.d * vec3f_sqlen(&nr);
}
Exemple #2
0
void find_best_coeffs(double fvco)
{
    double br, fvco_err;
    double min_fvco_err=100.0;
    int min_n, min_m, min_p, min_q, min_r;
    int n, m, nstroke, p, q , r;

    br=calc_target_br(fvco, fin);
    //printf("Fvco=%f; target BR: %f\n", fvco, br);
    for(m=511; m>0; m--)
    {
	n=(int)((double)m*br);
	if(n>4095)
	    continue;
	fvco_err=fabs(calc_fvco(fin, m, n)-fvco);
	p=calc_p(n, m);
	nstroke=calc_nstroke(n, p);
	q=calc_q(nstroke, m);
	r=calc_r(nstroke, m, q);
	if(is_valid(fvco, q, p, r))
	{
	    if(fvco_err<min_fvco_err)
	    {
		min_fvco_err=fvco_err;
		min_n=n;
		min_m=m;
		min_p=p;
		min_q=q;
		min_r=r;
	    }
	}
    }
    //printf("[N=%d|M=%d] Fvco=%0.3f, P=%d, Q=%d, R=%d\n", min_n, min_m, fvco, min_p, min_q, min_r);
    //printf("Error: %f (%.2f %%)\n", min_fvco_err, (min_fvco_err/fvco)*100.0);
    printf("%0.6f;%0.3f;%d;%d;%d;[%d;%d]\n", fvco, min_fvco_err*1000.0, min_p, min_q, min_r, min_n, min_m);
}
Exemple #3
0
void report_xvalid(double *xdata, double *xpred, double *xdiff, double *xstd,
		double *xzscore, int ndata, int var) {	
/*
 * DATE: Tue Oct  6 11:55:44 MET 1992
 * BY  : Edzer J. Pebesma
 * PURPOSE: report summary statistics of these five lists
 * SIDE EFFECTS: none
 */
	int i, nXdata = 0, nXpred = 0, nXdiff = 0, n_std = 0, nZscore = 0,
		compare(const double *a, const double *b);
	double min[5], max[5], p25[5], p75[5], p50[5], mean[5], std[5];
	double corr = 0.0;

	set_mv_double(&corr);
	calc_r(xdata, xpred, ndata, &corr);
	for (i = 0; i < 5; i ++) {
		set_mv_double(&(min[i])); 
		set_mv_double(&(p25[i])); 
		set_mv_double(&(p50[i])); 
		set_mv_double(&(p75[i])); 
		set_mv_double(&(max[i])); 
		set_mv_double(&(mean[i])); 
		set_mv_double(&(std[i])); 
	}
	/* select not missing values, put mv's at the end: */
	/* sorting arrays: */
	qsort(xdata, (size_t) ndata, sizeof(double), 
			(int (*)(const void *,const void *)) compare);
	while (!is_mv_double(&(xdata[nXdata])) && nXdata < ndata)
		nXdata++;
	qsort(xpred, (size_t) ndata, sizeof(double), 
			(int (*)(const void *,const void *)) compare);
	while (!is_mv_double(&(xpred[nXpred])) && nXpred < ndata)
		nXpred++;
	qsort(xdiff, (size_t) ndata, sizeof(double),
			(int (*)(const void *,const void *)) compare);
	while (!is_mv_double(&(xdiff[nXdiff])) && nXdiff < ndata)
		nXdiff++;
	if (var) { /* do everything for xstd and xzscore */
		qsort(xstd, (size_t) ndata, sizeof(double),
				(int (*)(const void *,const void *)) compare);
		while ((! is_mv_double(&(xstd[n_std]))) && (n_std < ndata))
			n_std++;
		qsort(xzscore, (size_t) ndata, sizeof(double),
				(int (*)(const void *,const void *)) compare);
		while ((! is_mv_double(&(xzscore[nZscore]))) && (nZscore < ndata))
			nZscore++;
	}
	/* calculate statistics: */
	if (nXdata) {
		min[0]=xdata[0];
		max[0]=xdata[nXdata-1];
		mean[0] = sample_mean(xdata, nXdata); 
		if (nXdata > 1) {
			p25[0]=est_quant(xdata, 0.25, nXdata);
			p50[0]=est_quant(xdata, 0.5, nXdata);
			p75[0]=est_quant(xdata, 0.75, nXdata);
			std[0] = sample_std(xdata, mean[0], nXdata);
		}
	}

	if (nXpred) {
		min[1]=xpred[0];
		max[1]=xpred[nXpred-1];
		mean[1] = sample_mean(xpred, nXpred);
		if (nXpred > 1) {
			p25[1]=est_quant(xpred, 0.25, nXpred);
			p50[1]=est_quant(xpred, 0.5, nXpred);
			p75[1]=est_quant(xpred, 0.75, nXpred);
			std[1] = sample_std(xpred, mean[1], nXpred);
		}
	}

	if (nXdiff) {
		min[2]=xdiff[0];
		max[2]=xdiff[nXdiff-1];
		mean[2] = sample_mean(xdiff, nXdiff);
		if (nXdiff > 1) {
			p25[2]=est_quant(xdiff, 0.25, nXdiff);
			p50[2]=est_quant(xdiff, 0.5, nXdiff);
			p75[2]=est_quant(xdiff, 0.75, nXdiff);
			std[2] = sample_std(xdiff, mean[2], nXdiff);
		}
	}

	if (var) {
		if (n_std) {
			min[3]=xstd[0];
			max[3]=xstd[n_std-1];
			mean[3] = sample_mean(xstd, n_std);
			if (n_std > 1) {
				p25[3]=est_quant(xstd, 0.25, n_std);
				p50[3]=est_quant(xstd, 0.5, n_std);
				p75[3]=est_quant(xstd, 0.75, n_std);
				std[3] = sample_std(xstd, mean[3], n_std);
			}
		}
		if (nZscore) {
			min[4]=xzscore[0];
			max[4]=xzscore[nZscore-1];
			mean[4] = sample_mean(xzscore, nZscore);
			if (nZscore > 1) {
				p25[4]=est_quant(xzscore, 0.25, nZscore);
				p50[4]=est_quant(xzscore, 0.5, nZscore);
				p75[4]=est_quant(xzscore, 0.75, nZscore);
				std[4] = sample_std(xzscore, mean[4], nZscore);
			}
		}
	}

	/* output: */
	printlog("corr(Obs, Pred): %s  [%s]\n\n",
		my_dtoa("%6.4g", &corr),
		method_string(get_method()));
	printlog("              observed   predicted   pred.-obs.   pred.std.     zscore\n");
	printlog("======================================================================\n");
	printlog("%-10s%12s", "minimum", my_dtoa("%6.4g", &(min[0])));
	printlog("%12s", my_dtoa("%6.4g", &(min[1]))); 
	printlog("%12s", my_dtoa("%6.4g", &(min[2]))); 
	printlog("%12s", my_dtoa("%6.4g", &(min[3]))); 
	printlog("%12s\n", my_dtoa("%6.4g", &(min[4]))); 
	printlog("%-10s%12s", "1st q.", my_dtoa("%6.4g", &(p25[0])));
	printlog("%12s", my_dtoa("%6.4g", &(p25[1]))); 
	printlog("%12s", my_dtoa("%6.4g", &(p25[2]))); 
	printlog("%12s", my_dtoa("%6.4g", &(p25[3]))); 
	printlog("%12s\n", my_dtoa("%6.4g", &(p25[4]))); 
	printlog("%-10s%12s", "median", my_dtoa("%6.4g", &(p50[0])));
	printlog("%12s", my_dtoa("%6.4g", &(p50[1]))); 
	printlog("%12s", my_dtoa("%6.4g", &(p50[2]))); 
	printlog("%12s", my_dtoa("%6.4g", &(p50[3]))); 
	printlog("%12s\n", my_dtoa("%6.4g", &(p50[4]))); 
	printlog("%-10s%12s", "3rd q.", my_dtoa("%6.4g", &(p75[0])));
	printlog("%12s", my_dtoa("%6.4g", &(p75[1]))); 
	printlog("%12s", my_dtoa("%6.4g", &(p75[2]))); 
	printlog("%12s", my_dtoa("%6.4g", &(p75[3]))); 
	printlog("%12s\n", my_dtoa("%6.4g", &(p75[4]))); 
	printlog("%-10s%12s", "maximum", my_dtoa("%6.4g", &(max[0])));
	printlog("%12s", my_dtoa("%6.4g", &(max[1]))); 
	printlog("%12s", my_dtoa("%6.4g", &(max[2]))); 
	printlog("%12s", my_dtoa("%6.4g", &(max[3]))); 
	printlog("%12s\n\n", my_dtoa("%6.4g", &(max[4]))); 
	printlog("%-10s%12d%12d%12d%12d%12d\n", "n",
		nXdata, nXpred, nXdiff, n_std, nZscore);
	printlog("%-10s%12s", "mean", my_dtoa("%6.4g", &(mean[0])));
	printlog("%12s", my_dtoa("%6.4g", &(mean[1]))); 
	printlog("%12s", my_dtoa("%6.4g", &(mean[2]))); 
	printlog("%12s", my_dtoa("%6.4g", &(mean[3]))); 
	printlog("%12s\n", my_dtoa("%6.4g", &(mean[4]))); 
	printlog("%-10s%12s", "std.dev.", my_dtoa("%6.4g", &(std[0])));
	printlog("%12s", my_dtoa("%6.4g", &(std[1]))); 
	printlog("%12s", my_dtoa("%6.4g", &(std[2]))); 
	printlog("%12s", my_dtoa("%6.4g", &(std[3]))); 
	printlog("%12s\n", my_dtoa("%6.4g", &(std[4]))); 
	return;
}