void TestNtt(const std::string &aName) { Tiff_Im aTF = Tiff_Im::StdConvGen(aName,1,true); Pt2di aSz = aTF.sz(); Im2D_REAL4 aI0(aSz.x,aSz.y); ELISE_COPY( aTF.all_pts(),aTF.in(),aI0.out()); int aWSz=2; TIm2D<REAL4,REAL8> aTIm(aI0); double aSomGlob=0.0; double aNbGlob=0.0; for (int aKdx=-aWSz ; aKdx<=aWSz ; aKdx+=aWSz) { printf("## "); for (int aKdy=-aWSz ; aKdy<=aWSz ; aKdy+=aWSz) { int aDx = aKdx; int aDy = aKdy; Pt2di aDep(aDx,aDy); Pt2di aP; RMat_Inertie aMat; for (aP.x = aWSz ; aP.x<aSz.x-aWSz ; aP.x++) { for (aP.y=aWSz ; aP.y<aSz.y-aWSz ; aP.y++) { aMat.add_pt_en_place(aTIm.get(aP),aTIm.get(aP+aDep)); } } double aC = aMat.correlation(); aC = 1-aC; if (dist8(aDep) == aWSz) { aSomGlob += aC; aNbGlob ++; } printf(" %4d",round_ni(10000*(aC))); } printf("\n"); } aSomGlob /= aNbGlob; std::cout << " G:" << aSomGlob << "\n"; printf("\n\n"); }
void cBenchLeastSquare::TestFoncNVar() { cFormQuadCreuse aFQuad(mNbVar,false); aFQuad.SetEpsB(1e-10); cOptimSommeFormelle anOSF(mNbVar); for (INT kEq=0; kEq<mNbEq ; kEq++) { Fonc_Num f = Fonc_Num(0); for (INT kV=0; kV<mNbVar ; kV++) { f = f+mSys.CoefLin(kV,kEq)*kth_coord(kV); } f = f-mSys.CoefCste(kEq); f = Square(f) * mSys.Pds(kEq); anOSF.Add(f,NRrandom3()<0.5); aFQuad.AddDiff(f); } // Verif de gradient + fonc sur aFQuad for (INT aNb=0 ; aNb<10 ; aNb++) { Im1D_REAL8 aPt(mNbVar); ELISE_COPY(aPt.all_pts(),frandr(),aPt.out()); REAL aVSom = anOSF.ValFNV(aPt.data()); REAL aVQ = aFQuad.ValFNV(aPt.data()); REAL aVSys = mSys.L2SomResiduPond(aPt); REAL aDif = DiffRel(aVQ,aVSys,epsilon); BENCH_ASSERT(aDif<epsilon); aDif = DiffRel(aVSom,aVSys,epsilon); BENCH_ASSERT(aDif<epsilon); Im1D_REAL8 aGradQ(mNbVar,0.0); Im1D_REAL8 aGradSys(mNbVar,0.0); Im1D_REAL8 aGradSom(mNbVar,0.0); aFQuad.GradFNV(aGradQ.data(),aPt.data()); GradFNV(aGradSys.data(),aPt.data()); anOSF.GradFNV(aGradSom.data(),aPt.data()); for (INT kV=0; kV<mNbVar ; kV++) { REAL aGQ = aGradQ.data()[kV]; REAL aGSys = aGradSys.data()[kV]; REAL aGSom = aGradSom.data()[kV]; aDif = DiffRel(aGQ,aGSys,epsilon); BENCH_ASSERT(aDif<epsilon); aDif = DiffRel(aGSom,aGSys,epsilon); BENCH_ASSERT(aDif<epsilon); } } // Verif de la formule du gradient { for (INT aNb=0 ; aNb<10 ; aNb++) { Im1D_REAL8 aPt(mNbVar,0.0); Im1D_REAL8 aGrad(mNbVar,0.0); GradFNV(aGrad.data(),aPt.data()); Im1D_REAL8 aDep(mNbVar,0.0); ELISE_COPY(aDep.all_pts(),(frandr()-0.5) * 0.0001,aDep.out()); REAL aScal; ELISE_COPY(aDep.all_pts(),aDep.in()*aGrad.in(),sigma(aScal)); REAL f1 = mSys.L2SomResiduPond(aDep); ELISE_COPY(aDep.all_pts(),-aDep.in(),aDep.out()); REAL f2 = mSys.L2SomResiduPond(aDep); REAL aDif = DiffRel(f1,f2,epsilon); BENCH_ASSERT(aDif<BIG_epsilon); } } Im1D_REAL8 aPt(mNbVar,0.0); powel(aPt.data(),1e-8,200); REAL aRes1 = mSys.L2SomResiduPond(mSol); REAL aRes2 = mSys.L2SomResiduPond(aPt); REAL aDif = DiffRel(aRes1,aRes2,epsilon); BENCH_ASSERT(aDif<epsilon); ELISE_COPY(aPt.all_pts(),frandr(),aPt.out()); GradConj(aPt.data(),1e-8,200); REAL aRes3 = mSys.L2SomResiduPond(aPt); aDif = DiffRel(aRes1,aRes3,epsilon); BENCH_ASSERT(aDif<epsilon); ELISE_COPY(aPt.all_pts(),frandr(),aPt.out()); anOSF. GradConjMin(aPt.data(),1e-8,200); REAL aRes4 = mSys.L2SomResiduPond(aPt); aDif = DiffRel(aRes1,aRes4,epsilon); BENCH_ASSERT(aDif<epsilon); }