void testRNG() { const int n = 500000; std::cerr << "Testing random number generator (n = " << n << " * bins)..." << std::endl; const int min = 1; const int minMax = 2; const int maxMax = 10; QVector<QVector<int>> numbers(maxMax - minMax + 1); QVector<double> chisq(maxMax - minMax + 1); for (int max = minMax; max <= maxMax; ++max) { numbers[max - minMax] = rng->makeNumbersVector(n * (max - min + 1), min, max); chisq[max - minMax] = rng->testRandom(numbers[max - minMax]); } for (int i = 0; i <= maxMax - min; ++i) { std::cerr << (min + i); for (int j = 0; j < numbers.size(); ++j) { if (i < numbers[j].size()) std::cerr << "\t" << numbers[j][i]; else std::cerr << "\t"; } std::cerr << std::endl; } std::cerr << std::endl << "Chi^2 ="; for (int j = 0; j < chisq.size(); ++j) std::cerr << "\t" << QString::number(chisq[j], 'f', 3).toStdString(); std::cerr << std::endl << "k ="; for (int j = 0; j < chisq.size(); ++j) std::cerr << "\t" << (j - min + minMax); std::cerr << std::endl << std::endl; }
void compute_metrics(const Ty* X1, const Ty* X2, Ty* M, int d, int n1, int n2, int opcode, const mxArray *prhs[]) { switch (opcode) { case 1: cityblock(X1, X2, M, d, n1, n2); break; case 2: mindiff(X1, X2, M, d, n1, n2); break; case 3: maxdiff(X1, X2, M, d, n1, n2); break; case 4: minkowski(X1, X2, M, d, n1, n2, *((const Ty*)mxGetData(prhs[3]))); break; case 5: intersect(X1, X2, M, d, n1, n2); break; case 6: chisq(X1, X2, M, d, n1, n2); break; case 7: kldiv(X1, X2, M, d, n1, n2); break; case 8: jeffrey(X1, X2, M, d, n1, n2); break; } }
virtual double execute( const GenoVec& geno, const PhenoVec& pheno, const unsigned cardGenotype, const unsigned cardPhenotype ) const { return chisq(geno, pheno, cardGenotype, cardPhenotype); }
double Calibration::MeanFeed::chisq (const MEAL::Complex2* model) const { const Feed* feed = dynamic_cast<const Feed*>(model); if (!feed) throw Error (InvalidParam, "Calibration::MeanFeed::chisq", "Complex2 model is not a Feed"); return chisq (feed); }
/*c.d.f of Chi-square*/ double Chisq(int df, double x) { switch(df){ case 1: return 2*Phi(sqrt(x))-1; case 2: return 1-exp(-x/2); default: break; } return ( Chisq(df-2,x)-2*chisq(df,x) ); }
void Dtest(n) /* requires static 'size', static int array P[size] */ /* generates n Dran()'s, tests output */ { double x=0,y,s=0,*E; int kb=0,ke=1000,i,j=0,*M; E=malloc(size*sizeof(double)); M=malloc(size*sizeof(int)); for(i=0;i<size;i++) {E[i]=(n+0.)*P[i]/1073741824.;M[i]=0;} s=0; for(i=0;i<size;i++) {s+=E[i]; if(s>10){kb=i;E[kb]=s;break;} } s=0; for(i=size-1;i>0;i--) {s+=E[i]; if(s>10){ke=i;E[ke]=s;break;} } s=0; x=0; for(i=0;i<n;i++) {j=Dran(); if(j<kb+offset) j=kb+offset; if(j>ke+offset) j=ke+offset; M[j-offset]++;} printf("\n D Observed Expected (O-E)^2/E sum\n"); fprintf(fp,"\n D Observed Expected (O-E)^2/E sum\n"); for(i=kb;i<=ke;i++){ y=M[i]-E[i]; y=y*y/E[i]; s+=y; printf("%4d %10d %12.2f %7.2f %7.2f\n",i+offset,M[i],E[i],y,s); fprintf(fp,"%4d %10d %12.2f %7.2f %7.2f\n",i+offset,M[i],E[i],y,s); } printf(" chisquare for %d d.f.=%7.2f, p=%7.5f\n",ke-kb,s,chisq(s,ke-kb)); fprintf(fp," chisquare for %d d.f.=%7.2f, p=%7.5f\n",ke-kb,s,chisq(s,ke-kb)); }
int main(int iargc, char *argv[]){ //d=8 -> delta_chisq=15.5 //d=5 -> delta_chisq=11 int seed=99; int dim,ncenters; int nsamples=10000; seed=atoi(argv[1]); dim=atoi(argv[2]); ncenters=atoi(argv[3]); if(iargc>4){ nsamples=atoi(argv[4]); } char timingname[letters],outname[letters]; //what is the name of the file where APS will store its timing information sprintf(timingname,"timingFiles/ellipse_d%d_c%d_timing.sav",dim,ncenters); //what is the name of the file where APS will output the points it sampled sprintf(outname,"outputFiles/ellipse_d%d_c%d_output.sav",dim,ncenters); if(seed<0){ seed=int(time(NULL)); } printf("seed %d\n",seed); //declare the covariogram for APS's Gaussian process matern_covariance cv; //declare the chisquared function APS will be searching //ellipses_integrable chisq(dim,ncenters); ellipses chisq(dim,ncenters); //declare APS //the '20' below is the number of nearest neighbors to use when seeding the //Gaussian process // //the '11.0' is the \Delta\chi^2 corresponding to a 95% confidence limit //on a 5-dimensional parameter space aps aps_test(dim,20,11.0,seed); //pass chisq to the aps object aps_test.assign_chisquared(&chisq); //pass the covariogram to the aps object aps_test.assign_covariogram(&cv); //how often will APS stop and write its output aps_test.set_write_every(3000); //set the G parameter from equation (4) in the paper aps_test.set_grat(1.0); //set the maximum and minimum values in parameter space array_1d<double> max,min; max.set_name("driver_max"); min.set_name("driver_min"); max.set_dim(dim); min.set_dim(dim); int i,j; for(i=0;i<dim;i++){ min.set(i,-100.0); max.set(i,100.0); } aps_test.set_timingname(timingname); aps_test.set_outname(outname); //initialize aps with 1000 random samples printf("time to initialize\n"); aps_test.initialize(100,min,max); double chival,chivaltest,err; i=-1; //search parameter space until the //chisquared function has been called //10000 times while(aps_test.get_called()<nsamples){ aps_test.search(); } aps_test.write_pts(); array_1d<double> minpt; //what is the point in parameter space corresponding to the //minimum chisquared aps_test.get_minpt(minpt); printf("chimin %e\n",aps_test.get_chimin()); printf("ct_aps %d ct_simplex %d total %d\n", aps_test.get_ct_aps(),aps_test.get_ct_simplex(), aps_test.get_called()); }