void compare_functionals(const Functional &f1, const Functional &f2, double kT, const Grid &n, double fraccuracy = 1e-15, double x = 0.001, double fraccuracydoub = 1e-15) { printf("\n************"); for (unsigned i=0;i<f1.get_name().size();i++) printf("*"); printf("\n* Testing %s *\n", f1.get_name().c_str()); for (unsigned i=0;i<f1.get_name().size();i++) printf("*"); printf("************\n\n"); printf("First energy:\n"); double f1n = f1.integral(kT, n); print_double("first energy is: ", f1n); printf("\n"); f1.print_summary("", f1n, f1.get_name().c_str()); printf("Second energy:\n"); double f2n = f2.integral(kT, n); print_double("second energy is: ", f2n); printf("\n"); f2.print_summary("", f2n, f2.get_name().c_str()); if (fabs(f1n/f2n - 1) > fraccuracy) { printf("E1 = %g\n", f1n); printf("E2 = %g\n", f2n); printf("FAIL: Error in f(n) is %g\n", f1n/f2n - 1); errors++; } Grid gr1(gd), gr2(gd); gr1.setZero(); gr2.setZero(); f1.integralgrad(kT, n, &gr1); f2.integralgrad(kT, n, &gr2); double err = (gr1-gr2).cwise().abs().maxCoeff(); double mag = gr1.cwise().abs().maxCoeff(); if (err/mag > fraccuracy) { printf("FAIL: Error in grad %s is %g as a fraction of %g\n", f1.get_name().c_str(), err/mag, mag); errors++; } errors += f1.run_finite_difference_test(f1.get_name().c_str(), kT, n); double f1x = f1(kT, x); double f2x = f2(kT, x); if (1 - fabs(f1x/f2x) > fraccuracydoub) { printf("FAIL: Error in double %s is %g as a fraction of %g\n", f1.get_name().c_str(), 1 - fabs(f1x/f2x), f2x); errors++; } double f1p = f1.derive(kT, x); double f2p = f2.derive(kT, x); if (1 - fabs(f1p/f2p) > fraccuracydoub) { printf("FAIL: Error in derive double %s is %g as a fraction of %g\n", f1.get_name().c_str(), 1 - fabs(f1p/f2p), f2p); errors++; } //errors += f2.run_finite_difference_test("other version", n); }
void Instruction_immediate::execute() const { if (operation()) { operation()->execute_immediate(gr1(), data()); } else { std::cout << "No operation defined " << opcode_str() << std::endl; } }
void Instruction_longInstruction::execute() const { if (operation()) { operation()->execute_longInstructionDirectAddr(gr1(), rx(), addr()); } else { std::cout << "No operation defined " << opcode_str() << std::endl; } }
void HeatControl2Delta::main() { HeatControl2Delta hc(100, 100, 100); hc.O.resize(2*hc.L); hc.O[0] = 0.50; hc.O[1] = 0.80; hc.O[2] = 0.70; hc.O[3] = 0.20; hc.O[4] = 0.20; hc.O[5] = 0.30; hc.initialize(); DoubleVector x(2*hc.L + (hc.M+1)*hc.L); x[0] = 0.60; x[1] = 0.70; x[2] = 0.65; x[3] = 0.25; x[4] = 0.25; x[5] = 0.35; for (unsigned int k=0; k<=hc.M; k++) { x[2*hc.L + 0*(hc.M+1) + k] = 1.0;//hc.v1(k*hc.ht); x[2*hc.L + 1*(hc.M+1) + k] = 1.0;//hc.v2(k*hc.ht); x[2*hc.L + 2*(hc.M+1) + k] = 1.0;//hc.v3(k*hc.ht); } /* Minimization */ ConjugateGradient g2; g2.setFunction(&hc); g2.setGradient(&hc); g2.setEpsilon1(0.0001); g2.setEpsilon2(0.0001); g2.setEpsilon3(0.0001); g2.setR1MinimizeEpsilon(1.0, 0.0001); g2.setPrinter(&hc); g2.setProjection(&hc); g2.setNormalize(true); g2.calculate(x); DoubleVector gr1(x.length()); IGradient::Gradient(&hc, 0.00001, x, gr1); gr1.L2Normalize(); DoubleVector gr2(x.length()); hc.gradient(x, gr2); gr2.L2Normalize(); printf("J[%d]: %.16f\n", 0, hc.fx(x)); printf("eo: [%12.8f, %12.8f] [%12.8f, %12.8f] [%12.8f, %12.8f]\n", hc.O[0], hc.O[1], hc.O[2], hc.O[3], hc.O[4], hc.O[5]); printf("e1: [%12.8f, %12.8f] [%12.8f, %12.8f] [%12.8f, %12.8f]\n", x[0], x[1], x[2], x[3], x[4], x[5]); printf("gr1: [%12.8f, %12.8f] [%12.8f, %12.8f] [%12.8f, %12.8f]\n", gr1[0], gr1[1], gr1[2], gr1[3], gr1[4], gr1[5]); printf("gr2: [%12.8f, %12.8f] [%12.8f, %12.8f] [%12.8f, %12.8f]\n", gr2[0], gr2[1], gr2[2], gr2[3], gr2[4], gr2[5]); }
void SSfind::prep_xmap( const clipper::Xmap<float>& xmap, const double radius ) { // make a 1-d array of gridded density values covering ASU+border grid = xmap.grid_sampling(); grrot = xmap.operator_orth_grid().rot(); clipper::Grid_range gr0 = xmap.grid_asu(); clipper::Grid_range gr1( xmap.cell(), xmap.grid_sampling(), radius ); mxgr = clipper::Grid_range( gr0.min()+gr1.min(), gr0.max()+gr1.max() ); mapbox = std::vector<float>( mxgr.size(), 0.0 ); // make 1d list of densities clipper::Xmap<float>::Map_reference_index ix( xmap ); for ( int i = 0; i < mapbox.size(); i++ ) { ix.set_coord( mxgr.deindex( i ) ); mapbox[i] = xmap[ix]; } }
void FitSignals(TTree * treeB, TCut cut, Int_t max){ AliSignalProcesor proc; TF1 * f1 = proc.GetAsymGauss(); TTreeSRedirector cstream("FitSignal.root"); TFile *f = cstream.GetFile(); char lname[100]; sprintf(lname,"Fit%s", cut.GetTitle()); TEventList *list = new TEventList(lname,lname); sprintf(lname,">>Fit%s", cut.GetTitle()); treeB->Draw(lname,cut); treeB->SetEventList(list); Int_t nFits=0; for (Int_t ievent=0; ievent<list->GetN(); ievent++){ if (nFits>max) break; if (nFits%50==0) printf("%d\n",nFits); char ename[100]; sprintf(ename,"Fit%d", ievent); Double_t nsample = treeB->Draw("Graph.fY-Mean09:Graph.fX","","",1,ievent); Double_t * signal = treeB->GetV1(); Double_t * time = treeB->GetV2(); Double_t maxpos =0; Double_t max = 0; for (Int_t ipos = 0; ipos<nsample; ipos++){ if (signal[ipos]>max){ max = signal[ipos]; maxpos = ipos; } } Int_t first = TMath::Max(maxpos-10,0.); Int_t last = TMath::Min(maxpos+60, nsample); // f->cd(); TH1F his(ename,ename,last-first,first,last); for (Int_t ipos=0; ipos<last-first; ipos++){ his.SetBinContent(ipos+1,signal[ipos+first]); } treeB->Draw("Sector:Row:Pad","","",1,ievent); Double_t sector = treeB->GetV1()[0]; Double_t row = treeB->GetV2()[0]; Double_t pad = treeB->GetV3()[0]; // TGraph graph(last-first,&time[first],&signal[first]); f1->SetParameters(0.75*max,maxpos,1.1,0.8,0.25,0.2); // TH1F * his = (TH1F*)graph.GetHistogram(); his.Fit(f1,"q"); his.Write(ename); gPad->Clear(); his.Draw(); gPad->Update(); Double_t params[6]; for (Int_t ipar=0; ipar<6; ipar++) params[ipar] = f1->GetParameters()[ipar]; Double_t chi2 = TFitter::GetFitter()->Chisquare(6,params); TMatrixD cov(6,6); cov.SetMatrixArray(TFitter::GetFitter()->GetCovarianceMatrix()); // // tail cancellation // Double_t x0[1000]; Double_t x1[1000]; Double_t x2[1000]; for (Int_t ipos=0; ipos<last-first; ipos++){ x0[ipos] = signal[ipos+first]; } proc.TailCancelationALTRO1(x0,x1,0.85*0.339,0.09,last-first); proc.TailCancelationALTRO1(x1,x2,0.85,0.789,last-first); // sprintf(ename,"Cancel1_%d", ievent); TH1F his1(ename,ename,last-first,first,last); for (Int_t ipos=0; ipos<last-first; ipos++){ his1.SetBinContent(ipos+1,x1[ipos]); } his1.Write(ename); sprintf(ename,"Cancel2_%d", ievent); TH1F his2(ename,ename,last-first,first,last); for (Int_t ipos=0; ipos<last-first; ipos++){ his2.SetBinContent(ipos+1,x1[ipos]); } f1->SetParameters(0.75*max,maxpos,1.1,0.8,0.25,0.2); his2.Fit(f1,"q"); his2.Write(ename); Double_t params2[6]; for (Int_t ipar=0; ipar<6; ipar++) params2[ipar] = f1->GetParameters()[ipar]; Double_t chi22 = TFitter::GetFitter()->Chisquare(6,params2); TMatrixD cov2(6,6); cov2.SetMatrixArray(TFitter::GetFitter()->GetCovarianceMatrix()); TGraph gr0(last-first, &time[first],x0); TGraph gr1(last-first, &time[first],x1); TGraph gr2(last-first, &time[first],x2); // cstream<<"Fit"<< "Sector="<<sector<< "Row="<<row<< "Pad="<<pad<< "First="<<first<< "Max="<<max<< "MaxPos="<<maxpos<< "chi2="<<chi2<< "chi22="<<chi22<< "Cov="<<&cov<< "Cov2="<<&cov2<< "gr0.="<<&gr0<< "gr1.="<<&gr1<< "gr2.="<<&gr2<< "p0="<<params[0]<< "p1="<<params[1]<< "p2="<<params[2]<< "p3="<<params[3]<< "p4="<<params[4]<< "p5="<<params[5]<< "p02="<<params2[0]<< "p12="<<params2[1]<< "p22="<<params2[2]<< "p32="<<params2[3]<< "p42="<<params2[4]<< "p52="<<params2[5]<< "\n"; // delete his; nFits++; } }
bool testFloatNbhoodReprBooleanOperations() { /* Testovani booleovskych operaci, tj. sjednoceni, pruniku a rozdilu (doplnek je v jinych testech) */ cout << "------------------------- "; cout << "testFloatNbhoodReprBooleanOperations:" << endl; vector<string> fileSet; string file1, file2; string datafile, spacefile; /* Kazda sada mnohostenu (kazda sada objahuje mnohosteny se stejnym Space) bude testovana tak, ze pro kazdou dvojici teto sady spocitame prunik (resp. sjednoceni, rozdil) ve vertex reprezentaci a otestujeme, zda je tento prunik (resp. sjednoceni, rozdil) stejny jako prunik (resp. sjednoceni, rozdil) v grid reprezentaci (tu povazujeme za referencni). */ /* Sada pro 2D prostor o rozmerech 4 x 4 */ cout << "test 2D polyhedra" << endl; fileSet.clear(); fileSet.push_back("06"); fileSet.push_back("07"); fileSet.push_back("08"); fileSet.push_back("09"); fileSet.push_back("10"); fileSet.push_back("11"); fileSet.push_back("12"); for (size_t i = 0; i < fileSet.size(); i ++) { for (size_t j = 0; j < fileSet.size(); j ++) { datafile = "src/test/data/uint/grid_repr/" + fileSet[i] + ".txt"; spacefile = "src/test/data/uint/grid_repr/" + fileSet[i] + "_space.txt"; GridRepr gr1(createSpaceFromSpacefile(spacefile, true), datafile.c_str(), true); datafile = "src/test/data/uint/grid_repr/" + fileSet[j] + ".txt"; spacefile = "src/test/data/uint/grid_repr/" + fileSet[j] + "_space.txt"; GridRepr gr2(createSpaceFromSpacefile(spacefile, true), datafile.c_str(), true); NbhoodRepr nr1(gr1); NbhoodRepr nr2(gr2); NbhoodRepr intersc = nr1.intersection(nr2); assert(gr1.intersection(gr2) == GridRepr(intersc)); NbhoodRepr unif = nr1.unification(nr2); assert(gr1.unification(gr2) == GridRepr(unif)); NbhoodRepr diff = nr1.difference(nr2); assert(gr1.difference(gr2) == GridRepr(diff)); } } /* Sada pro 3D prostor o rozmerech 6 x 6 x 6 */ cout << "test 3D polyhedra" << endl; fileSet.clear(); fileSet.push_back("13"); fileSet.push_back("14"); fileSet.push_back("15"); fileSet.push_back("16"); fileSet.push_back("17"); for (size_t i = 0; i < fileSet.size(); i ++) { for (size_t j = 0; j < fileSet.size(); j ++) { datafile = "src/test/data/uint/grid_repr/" + fileSet[i] + ".txt"; spacefile = "src/test/data/uint/grid_repr/" + fileSet[i] + "_space.txt"; GridRepr gr1(createSpaceFromSpacefile(spacefile, true), datafile.c_str(), true); datafile = "src/test/data/uint/grid_repr/" + fileSet[j] + ".txt"; spacefile = "src/test/data/uint/grid_repr/" + fileSet[j] + "_space.txt"; GridRepr gr2(createSpaceFromSpacefile(spacefile, true), datafile.c_str(), true); NbhoodRepr nr1(gr1); NbhoodRepr nr2(gr2); NbhoodRepr intersc = nr1.intersection(nr2); assert(gr1.intersection(gr2) == GridRepr(intersc)); NbhoodRepr unif = nr1.unification(nr2); assert(gr1.unification(gr2) == GridRepr(unif)); NbhoodRepr diff = nr1.difference(nr2); assert(gr1.difference(gr2) == GridRepr(diff)); } } /* Sada pro 1D prostor o rozmerech 20 */ cout << "test 1D polyhedra" << endl; fileSet.clear(); fileSet.push_back("18"); fileSet.push_back("19"); fileSet.push_back("20"); fileSet.push_back("21"); for (size_t i = 0; i < fileSet.size(); i ++) { for (size_t j = 0; j < fileSet.size(); j ++) { datafile = "src/test/data/uint/grid_repr/" + fileSet[i] + ".txt"; spacefile = "src/test/data/uint/grid_repr/" + fileSet[i] + "_space.txt"; GridRepr gr1(createSpaceFromSpacefile(spacefile, true), datafile.c_str(), true); datafile = "src/test/data/uint/grid_repr/" + fileSet[j] + ".txt"; spacefile = "src/test/data/uint/grid_repr/" + fileSet[j] + "_space.txt"; GridRepr gr2(createSpaceFromSpacefile(spacefile, true), datafile.c_str(), true); NbhoodRepr nr1(gr1); NbhoodRepr nr2(gr2); NbhoodRepr intersc = nr1.intersection(nr2); assert(gr1.intersection(gr2) == GridRepr(intersc)); NbhoodRepr unif = nr1.unification(nr2); assert(gr1.unification(gr2) == GridRepr(unif)); NbhoodRepr diff = nr1.difference(nr2); assert(gr1.difference(gr2) == GridRepr(diff)); } } #if 1 /* Sada pro 4D prostor o rozmerech 6 x 6 x 6 x 6 */ cout << "test 4D polyhedra" << endl; fileSet.clear(); fileSet.push_back("22"); fileSet.push_back("23"); fileSet.push_back("24"); for (size_t i = 0; i < fileSet.size(); i ++) { for (size_t j = 0; j < fileSet.size(); j ++) { datafile = "src/test/data/uint/grid_repr/" + fileSet[i] + ".txt"; spacefile = "src/test/data/uint/grid_repr/" + fileSet[i] + "_space.txt"; GridRepr gr1(createSpaceFromSpacefile(spacefile, true), datafile.c_str(), true); datafile = "src/test/data/uint/grid_repr/" + fileSet[j] + ".txt"; spacefile = "src/test/data/uint/grid_repr/" + fileSet[j] + "_space.txt"; GridRepr gr2(createSpaceFromSpacefile(spacefile, true), datafile.c_str(), true); NbhoodRepr nr1(gr1); NbhoodRepr nr2(gr2); NbhoodRepr intersc = nr1.intersection(nr2); assert(gr1.intersection(gr2) == GridRepr(intersc)); NbhoodRepr unif = nr1.unification(nr2); assert(gr1.unification(gr2) == GridRepr(unif)); NbhoodRepr diff = nr1.difference(nr2); assert(gr1.difference(gr2) == GridRepr(diff)); } } #endif #if 1 /* Sada pro 5D prostor o rozmerech 5 x 5 x 5 x 4 x 3 */ cout << "test 5D polyhedra" << endl; fileSet.clear(); fileSet.push_back("25"); fileSet.push_back("26"); for (size_t i = 0; i < fileSet.size(); i ++) { for (size_t j = 0; j < fileSet.size(); j ++) { datafile = "src/test/data/uint/grid_repr/" + fileSet[i] + ".txt"; spacefile = "src/test/data/uint/grid_repr/" + fileSet[i] + "_space.txt"; GridRepr gr1(createSpaceFromSpacefile(spacefile, true), datafile.c_str(), true); datafile = "src/test/data/uint/grid_repr/" + fileSet[j] + ".txt"; spacefile = "src/test/data/uint/grid_repr/" + fileSet[j] + "_space.txt"; GridRepr gr2(createSpaceFromSpacefile(spacefile, true), datafile.c_str(), true); NbhoodRepr nr1(gr1); NbhoodRepr nr2(gr2); NbhoodRepr intersc = nr1.intersection(nr2); assert(gr1.intersection(gr2) == GridRepr(intersc)); NbhoodRepr unif = nr1.unification(nr2); assert(gr1.unification(gr2) == GridRepr(unif)); NbhoodRepr diff = nr1.difference(nr2); assert(gr1.difference(gr2) == GridRepr(diff)); } } #endif return true; }
std::string Instruction_immediate::details() const { std::ostringstream os; os << std::hex << std::setfill('0') << std::uppercase << "GR(" << std::setw(2) << gr1() << "), DATA(" << std::setw(4) << data() << ")"; return os.str(); }
std::string Instruction_longInstruction::details() const { std::ostringstream os; os << "GR(" << std::hex << std::uppercase << std::setfill('0') << std::setw(2) << gr1() << "), RX(" << std::setw(2) <<rx() << "), ADDR(" << std::hex << std::uppercase << std::setw(4) << addr() << ")"; return os.str(); }