Пример #1
0
Файл: m_pd.c Проект: Tzero2/pd
t_pd *pd_findbyclass(t_symbol *s, t_class *c)
{
    t_pd *x = 0;
    
    if (!s->s_thing) return (0);
    if (*s->s_thing == c) return (s->s_thing);
    if (*s->s_thing == bindlist_class)
    {
        t_bindlist *b = (t_bindlist *)s->s_thing;
        t_bindelem *e, *e2;
        int warned = 0;
        for (e = b->b_list; e; e = e->e_next)
            if (*e->e_who == c)
        {
            if (x && !warned)
            {
                zz();
                post("warning: %s: multiply defined", s->s_name);
                warned = 1;
            }
            x = e->e_who;
        }
    }
    return x;
}
Пример #2
0
//-----------------------------------------------------------------------------
//
//	TriContV series
//
//-----------------------------------------------------------------------------
void MGL_EXPORT mgl_tricontv_xyzcv(HMGL gr, HCDT v, HCDT nums, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, const char *opt)
{
	mglDataV zz(x->GetNx(),x->GetNy());
	if(!z)	z = &zz;
	if(mgl_check_trig(gr,nums,x,y,z,a,"TriContV"))	return;

	gr->SaveState(opt);
	static int cgid=1;	gr->StartGroup("TriContV",cgid++);
	bool fixed=(mglchr(sch,'_')) || (gr->Min.z==gr->Max.z);
	long s=gr->AddTexture(sch);
	gr->SetPenPal(sch);

	for(long k=0;k<v->GetNx();k++)
	{
		mreal v0 = v->v(k);		zz.Fill(fixed ? gr->Min.z : v0);
		mreal dv = (gr->Max.c-gr->Min.c)/8, c = gr->GetC(s,v0);
		if(k>0)	dv = v->v(k-1)-v->v(k);
		else if(k<v->GetNx()-1)	dv = v->v(k)-v->v(k+1);
		if(fixed)	dv=-dv;

		const std::vector<mglSegment> curvs = mgl_get_curvs(gr,mgl_tri_lines(v0,nums,a,x,y,fixed?&zz:z));
		for(size_t i=0;i<curvs.size();i++)
		{
			const std::list<mglPoint> &pp=curvs[i].pp;
			long f2=-1,g2=-1;
			for(std::list<mglPoint>::const_iterator it=pp.begin(); it != pp.end(); ++it)
			{
				mglPoint p=*it,q(p.y,-p.x);
				long f1 = f2;	f2 = gr->AddPnt(p,c,q);	p.z+=dv;
				long g1 = g2;	g2 = gr->AddPnt(p,c,q);
				gr->quad_plot(f1,g1,f2,g2);
			}
		}
	}
}
Пример #3
0
int main( ){

    // DEFINE VARIABLES:
    // -----------------------
       DifferentialState x, y;
       IntermediateState    z;
       Function             f;

       z = myProduct( x, y );

       f << x*z + z;


    // TEST THE FUNCTION f:
    // --------------------
       EvaluationPoint zz(f);

       DVector xx(2), result;
       xx(0) = 2.0;
       xx(1) = 3.0;

       zz.setX( xx );
       result = f.evaluate( zz );

       result.print("result");

    return 0;
}
Пример #4
0
t_pd *pd_findbyclass(t_symbol *s, t_class *c)
{
    t_pd *x = 0;
    
    //fprintf(stderr,"pd_findbyclass\n");
    if (!s->s_thing) return (0);
    if (*s->s_thing == c) return (s->s_thing);
    if (*s->s_thing == bindlist_class)
    {
        t_bindlist *b = (t_bindlist *)s->s_thing;
        t_bindelem *e;
        int warned = 0;
        for (e = b->b_list; e; e = e->e_next)
        {
            //if (e->e_who != NULL && *e->e_who == c)
            //fprintf(stderr, "(e_who == c)?%d || e->e_delayed_free=%d\n", (*e->e_who == c ? 1 : 0), e->e_delayed_free);
            if (e->e_delayed_free != 1 && *e->e_who == c)
            {
                //fprintf(stderr,"...found %lx", e);
                if (x && !warned)
                {
                    zz();
                    post("warning: %s: multiply defined", s->s_name);
                    warned = 1;
                }
                x = e->e_who;
            }
        }
    }
    //fprintf(stderr,"====\n");
    return x;
}
Пример #5
0
int main()
{
  boost::owner_less<boost::shared_ptr<int> > comp;
  {
    boost::shared_ptr<int> x;
    boost::shared_ptr<int> y;
    boost::weak_ptr<int> w;
    BOOST_TEST(!(comp(x, w) || comp(w, x)));
  }
  {
    boost::shared_ptr<int> z((int*)0);
    boost::weak_ptr<int> w;
    BOOST_TEST(comp(z, w) || comp(w, z));
    {
      boost::shared_ptr<int> zz(z);
      w = boost::weak_ptr<int>(zz);
      BOOST_TEST(!(comp(z, zz) || comp(z, zz)));
      BOOST_TEST(!(comp(z, w) || comp(z, w)));
    }
    BOOST_TEST(!(comp(z, w) || comp(w, z)));
  }
  {
    boost::shared_ptr<int> x;
    boost::shared_ptr<int> z((int*)0);
    BOOST_TEST(comp(x, z) || comp(z, x));
  }
  {
    boost::shared_ptr<int> a((int*)0);
    boost::shared_ptr<int> b((int*)0);
    BOOST_TEST(comp(a, b) || comp(b, a));
    boost::weak_ptr<int> w(a);
    BOOST_TEST(!(comp(a, w) || comp(w, a)));
    BOOST_TEST(comp(b, w) || comp(w, b));
  }

  boost::owner_less<boost::weak_ptr<int> > weak_comp;
  {
    boost::shared_ptr<int> a((int*)0);
    boost::weak_ptr<int> wa(a);
    boost::shared_ptr<int> b((int*)0);
    boost::weak_ptr<int> wb(b);
    BOOST_TEST(!(weak_comp(a, wa) || weak_comp(wa, a)));
    BOOST_TEST(!(weak_comp(b, wb) || weak_comp(wb, b)));
    BOOST_TEST(weak_comp(wa, wb) || weak_comp(wb, wa));
    BOOST_TEST(weak_comp(wa, b) || weak_comp(b, wa));
  }

  return boost::report_errors();
}
int main()
{
   // Single caracters reading
   cChar::read(' ');
   cChar::read('-');
   cChar::read('\n');
   for (int i = 1 ; i <= 5 ; i++)
      cChar::read(cChar::NO_END);
   cChar::readNewLine();

   cInt::read(cInt::NO_END);
   cChar::read('\n');


   // Line/word reading
   cString::readLine();
   cString::readLine().size().equal(34);
   cString::readWord(' ');       // word with space at the end
   cString::readWord('\n');      // word with newline at the end
   cString::read(10, ' ', '\n'); // 10 chars separated by spaces and newline at the end
   cString::readChars(10, ' ');  // 10 chars with space at the end
   cString::readChars(5, '\n');  // 10 chars with newline at the end

   // Matrix
   cMatrix<char>::read(3, 2, ' ', '\n');
   cMatrix<char>::read(3, 2, '-', '\n');
   cMatrix<char>::readLines(3);

   // Specials
   cString::readLine().in(sani::LOWER);
   cString::readLine().in(sani::UPPER);
   cString::readLine().in(sani::DIGITS);
   cString::readLine().in(sani::ALPHA);
   cString::readLine().in(sani::ALPHANUM);

   cString name = cString::readLine();
   name.sub(0, 1).in(sani::UPPER);
   name.sub(1).in(sani::LOWER);

   // Conversion
   std::string xx = cString::readLine();
   cString yy(xx);
   cString zz(xx + xx);
}
Пример #7
0
/* >>> start tutorial code >>> */
int main( ){

    USING_NAMESPACE_ACADO

    // DEFINE VALRIABLES:
    // ---------------------------
    DMatrix                 A(3,3);
    DVector                 b(3)  ;
    DifferentialState      x("", 3, 1);
    Function               f     ;


    // DEFINE THE VECTOR AND MATRIX ENTRIES:
    // -------------------------------------
    A.setZero() ;
    A(0,0) = 1.0;  A(1,1) = 2.0;  A(2,2) = 3.0;
    b(0)   = 1.0;  b(1)   = 1.0;  b(2)   = 1.0;


    // DEFINE A TEST FUNCTION:
    // -----------------------
    f << A*x + b;
    f << ( A*x(0) ).getRow( 1 );
    f << ( A*x(0) ).getCol( 0 );

    // TEST THE FUNCTION f:
    // --------------------
    EvaluationPoint zz(f);

    DVector xx(3);
    xx(0) = 1.0;
    xx(1) = 2.0;
    xx(2) = 3.0;

    zz.setX( xx );

    DVector result = f.evaluate( zz );

    result.print(std::cout, "result");

    return 0;
}
Пример #8
0
void StringTest::testCompare()
{
    const cxxtools::Char abc[] = { 'a', 'b', 'c', '\0' };

    const wchar_t* z = L"abcxyz";
    cxxtools::String s(L"abcd");
    cxxtools::String t(abc);

    CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare(s)                 , 0);
    CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare(t)                 , 1);
    CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare(z)                 , -1);
    CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare(1, 3, t)           , 1);
    CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare(1, 3, t, 1, 2)     , 1);
    CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare(1, 3, z)           , 1);
    CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare(1, 2, z + 1, 0, 2) , 0);

    cxxtools::String x1(L"abc");
    cxxtools::String x2(abc);
    CXXTOOLS_UNIT_ASSERT(x1 == x2);
    CXXTOOLS_UNIT_ASSERT(x1 == abc);
    CXXTOOLS_UNIT_ASSERT(x2 == abc);

    const cxxtools::Char empty[] = { '\0' };
    cxxtools::String y1(L"");
    cxxtools::String y2(empty);
    CXXTOOLS_UNIT_ASSERT(y1 == y2);
    CXXTOOLS_UNIT_ASSERT(y1 == empty);
    CXXTOOLS_UNIT_ASSERT(y2 == empty);

    CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare(L"abcd"), 0);
    CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare(L"abc"), 1);
    CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare(L"abcde"), -1);

    cxxtools::String zz(L"abcd\0ef", 7);
    CXXTOOLS_UNIT_ASSERT_EQUALS(zz.compare(L"abcd"), 1);
    CXXTOOLS_UNIT_ASSERT_EQUALS(zz.compare(L"abcde"), -1);
    CXXTOOLS_UNIT_ASSERT_EQUALS(zz.compare(L"abcd\0ef", 7), 0);
    CXXTOOLS_UNIT_ASSERT_EQUALS(zz.compare(L"abcd\0ee", 7), 1);
    CXXTOOLS_UNIT_ASSERT_EQUALS(zz.compare(L"abcd\0eg", 7), -1);
    CXXTOOLS_UNIT_ASSERT_EQUALS(zz.compare(L"abcd\0eff", 9), -1);
    CXXTOOLS_UNIT_ASSERT_EQUALS(zz.compare(L"abcd\0eff", 5), 0);
}
Пример #9
0
/* >>> start tutorial code >>> */
int main( ){


    USING_NAMESPACE_ACADO

    // DEFINE VALRIABLES:
    // ---------------------------
    DVector                 b(3)  ;
    DifferentialState      x("", 2, 2);
    Function               f     ;


    // DEFINE THE VECTOR AND MATRIX ENTRIES:
    // -------------------------------------
    b(0)   = 1.0;  b(1)   = 1.0;  b(2)   = 1.0;


    // DEFINE A TEST FUNCTION:
    // -----------------------
    f << x.getInverse();


    // TEST THE FUNCTION f:
    // --------------------
    EvaluationPoint zz(f);

    DVector xx(4);

    xx(0) = 2.0;
    xx(1) = 0.1;
    xx(2) = 0.0;
    xx(3) = 2.0;

    zz.setX( xx );

    // EVALUATE f AT THE POINT  (tt,xx):
    // ---------------------------------
    std::cout << "f: " << std::endl << f.evaluate( zz ) << std::endl;

    return 0;
}
Пример #10
0
//-----------------------------------------------------------------------------
void MGL_EXPORT mgl_tricont_xyzcv(HMGL gr, HCDT v, HCDT nums, HCDT x, HCDT y, HCDT z, HCDT a, const char *sch, const char *opt)
{
	mglDataV zz(x->GetNx(),x->GetNy());
	if(!z)	z = &zz;
	if(mgl_check_trig(gr,nums,x,y,z,a,"TriCont"))	return;

	gr->SaveState(opt);
	static int cgid=1;	gr->StartGroup("TriCont",cgid++);
	int text=0;
	if(mglchr(sch,'t'))	text=1;
	if(mglchr(sch,'T'))	text=2;
	bool fixed=(mglchr(sch,'_')) || (gr->Min.z==gr->Max.z);
	long s=gr->AddTexture(sch);
	gr->SetPenPal(sch);

	for(long k=0;k<v->GetNx();k++)
	{
		mreal v0 = v->v(k);		zz.Fill(fixed ? gr->Min.z : v0);
		mgl_draw_curvs(gr,v0,gr->GetC(s,v0),text,mgl_get_curvs(gr,mgl_tri_lines(v0,nums,a,x,y,fixed?&zz:z)));
	}
}
Пример #11
0
void forDibosons(std::string path, std::string pdfName){

  readHist ww(Form("%s/diBosons/WW_TuneCUETP8M1_13TeV_pseudoTest.root",path.data()));
  readHist wz(Form("%s/diBosons/WZ_TuneCUETP8M1_13TeV_pseudoTest.root",path.data()));
  readHist zz(Form("%s/diBosons/ZZ_TuneCUETP8M1_13TeV_pseudoTest.root",path.data()));
 
  TH1D* h_prmass = (TH1D*)(ww.getHist("corrPRmassAll"))->Clone("h_prmass");

  h_prmass->Reset();
  h_prmass->Add(ww.getHist("corrPRmassAll"));
  h_prmass->Add(wz.getHist("corrPRmassAll"));
  h_prmass->Add(zz.getHist("corrPRmassAll"));

  TH1D* h_prmass_hollow = (TH1D*)(ww.getHist("corrPRmass"))->Clone("h_prmass_hollow");

  h_prmass_hollow->Reset();
  h_prmass_hollow->Add(ww.getHist("corrPRmass"));
  h_prmass_hollow->Add(wz.getHist("corrPRmass"));
  h_prmass_hollow->Add(zz.getHist("corrPRmass"));

  TGraphAsymmErrors* g_errorBands = new TGraphAsymmErrors(); 
  TGraphAsymmErrors* g_errorBands_hollow = new TGraphAsymmErrors();

  TH1D* h_bias   = new TH1D("h_bias",   "", 50, -1, 1);
  TH1D* h_upPull = new TH1D("h_upPull", "", 50, -1, 1);
  TH1D* h_dwPull = new TH1D("h_dwPull", "", 50, -1, 1);

  fitTest(h_prmass, h_prmass_hollow, 
	  &g_errorBands, &g_errorBands_hollow,
	  h_bias, h_upPull, h_dwPull);
  
  fitDraw(h_prmass, h_prmass_hollow,
	  g_errorBands, g_errorBands_hollow,
	  h_bias, h_upPull, h_dwPull,
	  pdfName);

}
Пример #12
0
int main( ){

    USING_NAMESPACE_ACADO

    // DEFINE VARIABLES:
    // -----------------------
       DifferentialState x, y;
       IntermediateState z   ;
       Function f;

       z = 1.0;

       int run1;

       for( run1 = 0; run1 < 5; run1++ )
            z += sin( z + x*y );

       f << z;


    // TEST THE FUNCTION f:
    // --------------------
       EvaluationPoint zz(f);

       Vector xx(2);
       xx.setZero();
       xx(0) = 2.0;
       xx(1) = 0.0;

       zz.setX(xx);

       Vector result = f.evaluate( zz );
       result.print("result");

    return 0;
}
Пример #13
0
NM_Status
SubspaceIteration :: solve(SparseMtrx &a, SparseMtrx &b, FloatArray &_eigv, FloatMatrix &_r, double rtol, int nroot)
//
// this function solve the generalized eigenproblem using the Generalized
// jacobi iteration
//
{
    if ( a.giveNumberOfColumns() != b.giveNumberOfColumns() ) {
        OOFEM_ERROR("matrices size mismatch");
    }

    FloatArray temp, w, d, tt, f, rtolv, eigv;
    FloatMatrix r;
    int nn, nc1, ij = 0, is;
    double rt, art, brt, eigvt;
    FloatMatrix ar, br, vec;
    std :: unique_ptr< SparseLinearSystemNM > solver( GiveClassFactory().createSparseLinSolver(ST_Direct, domain, engngModel) );

    GJacobi mtd(domain, engngModel);
    int nc = min(2 * nroot, nroot + 8);
    nn = a.giveNumberOfColumns();
    if ( nc > nn ) {
        nc = nn;
    }

    ar.resize(nc, nc);
    ar.zero();
    br.resize(nc, nc);
    br.zero();

    //
    // creation of initial iteration vectors
    //
    nc1 = nc - 1;

    w.resize(nn);
    w.zero();
    d.resize(nc);
    d.zero();
    tt.resize(nn);
    tt.zero();
    rtolv.resize(nc);
    rtolv.zero();
    vec.resize(nc, nc);
    vec.zero();                   // eigen vectors of reduced problem

    //
    // create work arrays
    //
    r.resize(nn, nc);
    r.zero();
    eigv.resize(nc);
    eigv.zero();

    FloatArray h(nn);
    for ( int i = 1; i <= nn; i++ ) {
        h.at(i) = 1.0;
        w.at(i) = b.at(i, i) / a.at(i, i);
    }

    b.times(h, tt);
    r.setColumn(tt, 1);

    for ( int j = 2; j <= nc; j++ ) {
        rt = 0.0;
        for ( int i = 1; i <= nn; i++ ) {
            if ( fabs( w.at(i) ) >= rt ) {
                rt = fabs( w.at(i) );
                ij = i;
            }
        }

        tt.at(j) = ij;
        w.at(ij) = 0.;
        for ( int i = 1; i <= nn; i++ ) {
            if ( i == ij ) {
                h.at(i) = 1.0;
            } else {
                h.at(i) = 0.0;
            }
        }

        b.times(h, tt);
        r.setColumn(tt, j);
    } // (r = z)

# ifdef DETAILED_REPORT
    OOFEM_LOG_INFO("SubspaceIteration :: solveYourselfAt: Degrees of freedom invoked by initial vectors :\n");
    tt.printYourself();
    OOFEM_LOG_INFO("SubspaceIteration :: solveYourselfAt: initial vectors for iteration:\n");
    r.printYourself();
# endif

    //ish = 0;
    a.factorized();
    //
    // start of iteration loop
    //
    for ( int nite = 0; ; ++nite ) {               // label 100
# ifdef DETAILED_REPORT
        printf("SubspaceIteration :: solveYourselfAt: Iteration loop no. %d\n", nite);
# endif
        //
        // compute projection ar and br of matrices a , b
        //
        for ( int j = 1; j <= nc; j++ ) {
            f.beColumnOf(r, j);

            solver->solve(a, f, tt);

            for ( int i = j; i <= nc; i++ ) {
                art = 0.;
                for ( int k = 1; k <= nn; k++ ) {
                    art += r.at(k, i) * tt.at(k);
                }

                ar.at(j, i) = art;
            }

            r.setColumn(tt, j);            // (r = xbar)
        }

        ar.symmetrized();        // label 110
#ifdef DETAILED_REPORT
        OOFEM_LOG_INFO("SubspaceIteration :: solveYourselfAt: Printing projection matrix ar\n");
        ar.printYourself();
#endif
        //
        for ( int j = 1; j <= nc; j++ ) {
            tt.beColumnOf(r, j);

            b.times(tt, temp);
            for ( int i = j; i <= nc; i++ ) {
                brt = 0.;
                for ( int k = 1; k <= nn; k++ ) {
                    brt += r.at(k, i) * temp.at(k);
                }

                br.at(j, i) = brt;
            }                   // label 180

            r.setColumn(temp, j);        // (r=zbar)
        }                       // label 160

        br.symmetrized();
#ifdef DETAILED_REPORT
        OOFEM_LOG_INFO("SubspaceIteration :: solveYourselfAt: Printing projection matrix br\n");
        br.printYourself();
#endif

        //
        // solution of reduced eigenvalue problem
        //
        mtd.solve(ar, br, eigv, vec);

        // START EXPERIMENTAL
#if 0
        // solve the reduced problem by Inverse iteration
        {
            FloatMatrix x(nc,nc), z(nc,nc), zz(nc,nc), arinv;
            FloatArray  w(nc), ww(nc), tt(nc), t(nc);
            double c;

            //  initial setting
            for ( int i = 1;i <= nc; i++ ) {
                ww.at(i)=1.0;
            }
            
            
            for ( int i = 1;i <= nc; i++ )
                for ( int j = 1; j <= nc;j++ )
                    z.at(i,j)=1.0;
            
            arinv.beInverseOf (ar);
            
            for ( int i = 0;i < nitem; i++ ) {
                //  copy zz=z
                zz = z;
                
                // solve matrix equation K.X = M.X
                x.beProductOf(arinv, z);
                //  evaluation of Rayleigh quotients
                for ( int j = 1;j <= nc; j++ ) {
                    w.at(j) = 0.0;
                    for (k = 1; k<= nc; k++) w.at(j) += zz.at(k,j) * x.at(k,j);
                }

                z.beProductOf (br, x);

                for ( int j = 1;j <= nc; j++ ) {
                    c = 0;
                    for ( int k = 1; k<= nc; k++ ) c += z.at(k,j) * x.at(k,j);
                    w.at(j) /= c;
                }

                //  check convergence
                int ac = 0;
                for ( int j = 1;j <= nc; j++ ) {
                    if (fabs((ww.at(j)-w.at(j))/w.at(j))< rtol)  ac++;
                    ww.at(j) = w.at(j);
                }

                //printf ("\n iterace cislo  %d   %d",i,ac);
                //w.printYourself();

                //  Gramm-Schmidt ortogonalization
                for ( int j = 1;j <= nc;j++ ) {
                    for ( int k = 1; k<= nc; k++ ) tt.at(k) = x.at(k,j);
                    t.beProductOf(br,tt) ;
                    for ( int ii = 1;ii < j; ii++ ) {
                        c = 0.0;
                        for ( int k = 1; k<= nc; k++ ) c += x.at(k,ii) * t.at(k);
                        for ( int k = 1; k<= nc; k++ ) x.at(k,j) -= x.at(k,ii) * c;
                    }
                    for ( int k = 1; k<= nc; k++) tt.at(k) = x.at(k,j);
                    t.beProductOf(br, tt);
                    c = 0.0;
                    for ( int k = 1; k<= nc; k++) c += x.at(k,j)*t.at(k);
                    for ( int k = 1; k<= nc; k++) x.at(k,j) /= sqrt(c);
                }

                if ( ac > nroot ) {
                    break;
                }

                //  compute new approximation of Z
                z.beProductOf(br,x);
            }
            
            eigv = w;
            vec = x;
        }
#endif


        //
        // sorting eigenvalues according to their values
        //
        do {
            is = 0; // label 350
            for ( int i = 1; i <= nc1; i++ ) {
                if ( fabs( eigv.at(i + 1) ) < fabs( eigv.at(i) ) ) {
                    is++;
                    eigvt = eigv.at(i + 1);
                    eigv.at(i + 1) = eigv.at(i);
                    eigv.at(i)   = eigvt;
                    for ( int k = 1; k <= nc; k++ ) {
                        rt = vec.at(k, i + 1);
                        vec.at(k, i + 1) = vec.at(k, i);
                        vec.at(k, i)   = rt;
                    }
                }
            }                   // label 360
        } while ( is != 0 );

# ifdef DETAILED_REPORT
        OOFEM_LOG_INFO("SubspaceIteration :: solveYourselfAt: current eigen values of reduced problem \n");
        eigv.printYourself();
        OOFEM_LOG_INFO("SubspaceIteration :: solveYourselfAt: current eigen vectors of reduced problem \n");
        vec.printYourself();
# endif
        //
        // compute eigenvectors
        //
        for ( int i = 1; i <= nn; i++ ) { // label 375
            for ( int j = 1; j <= nc; j++ ) {
                tt.at(j) = r.at(i, j);
            }

            for ( int k = 1; k <= nc; k++ ) {
                rt = 0.;
                for ( int j = 1; j <= nc; j++ ) {
                    rt += tt.at(j) * vec.at(j, k);
                }

                r.at(i, k) = rt;
            }
        }                       // label 420   (r = z)

        //
        // convergency check
        //
        for ( int i = 1; i <= nc; i++ ) {
            double dif = ( eigv.at(i) - d.at(i) );
            rtolv.at(i) = fabs( dif / eigv.at(i) );
        }

# ifdef DETAILED_REPORT
        OOFEM_LOG_INFO("SubspaceIteration :: solveYourselfAt: Reached precision of eigenvalues:\n");
        rtolv.printYourself();
# endif
        for ( int i = 1; i <= nroot; i++ ) {
            if ( rtolv.at(i) > rtol ) {
                goto label400;
            }
        }

        OOFEM_LOG_INFO("SubspaceIteration :: solveYourselfAt: Convergence reached for RTOL=%20.15f\n", rtol);
        break;
label400:
        if ( nite >= nitem ) {
            OOFEM_WARNING("SubspaceIteration :: solveYourselfAt: Convergence not reached in %d iteration - using current values", nitem);
            break;
        }

        d = eigv;                     // label 410 and 440

        continue;
    }


    // compute eigenvectors
    for ( int j = 1; j <= nc; j++ ) {
        tt.beColumnOf(r, j);

        a.backSubstitutionWith(tt);
        r.setColumn(tt, j);                          // r = xbar
    }

    // one cad add a normalization of eigen-vectors here

    // initialize original index locations
    _r.resize(nn, nroot);
    _eigv.resize(nroot);
    for ( int i = 1; i <= nroot; i++ ) {
        _eigv.at(i) = eigv.at(i);
        for ( int j = 1; j <= nn; j++ ) {
            _r.at(j, i) = r.at(j, i);
        }
    }

    return NM_Success;
}
Пример #14
0
NM_Status
InverseIteration :: solve(SparseMtrx &a, SparseMtrx &b, FloatArray &_eigv, FloatMatrix &_r, double rtol, int nroot)
{
	FILE *outStream;
    if ( a.giveNumberOfColumns() != b.giveNumberOfColumns() ) {
        OOFEM_ERROR("matrices size mismatch");
    }

    SparseLinearSystemNM *solver = GiveClassFactory().createSparseLinSolver(ST_Direct, domain, engngModel);
   
    int nn = a.giveNumberOfColumns();
    int nc = min(2 * nroot, nroot + 8);
    nc = min(nc, nn);

	//// control of diagonal zeroes in mass matrix, to be avoided
	//int i;
	//for (i = 1; i <= nn; i++) {
	//	if (b.at(i, i) == 0) {
	//		b.at(i, i) = 1.0e-12;
	//	}
	//}

    FloatArray w(nc), ww(nc), t;
    std :: vector< FloatArray > z(nc, nn), zz(nc, nn), x(nc, nn);
	outStream = domain->giveEngngModel()->giveOutputStream();

    /*  initial setting  */
#if 0
    ww.add(1.0);
    for ( int j = 0; j < nc; j++ ) {
        z[j].add(1.0);
    }
#else
	{
		FloatArray ad(nn), bd(nn);
		for (int i = 1; i <= nn; i++) {
			ad.at(i) = fabs(a.at(i, i));
			bd.at(i) = fabs(b.at(i, i));
			}
		IntArray order;
		order.enumerate(nn);
		std::sort(order.begin(), order.end(), [&ad, &bd](int a, int b) { return bd.at(a) * ad.at(b) > bd.at(b) * ad.at(a); });
		for (int i = 0; i < nc; i++) {
			x[i].at(order[i]) = 1.0;
			b.times(x[i], z[i]);
			ww.at(i + 1) = z[i].dotProduct(x[i]);
		}
	}
#endif

    int it;
    for ( it = 0; it < nitem; it++ ) {
        /*  copy zz=z  */
        for ( int j = 0; j < nc; j++ ) {
            zz[j] = z[j];
        }

        /*  solve matrix equation K.X = M.X  */
        for ( int j = 0; j < nc; j++ ) {
            solver->solve(a, z[j], x[j]);
        }

        /*  evaluation of Rayleigh quotients  */
        for ( int j = 0; j < nc; j++ ) {
            w.at(j + 1) = zz[j].dotProduct(x[j]);
        }

        for ( int j = 0; j < nc; j++ ) {
            b.times(x[j], z[j]);
        }

        for ( int j = 0; j < nc; j++ ) {
            w.at(j + 1) /= z[j].dotProduct(x[j]);
        }

        /*  check convergence  */
        int ac = 0;
        for ( int j = 1; j <= nc; j++ ) {
            if ( fabs( ww.at(j) - w.at(j) ) <= fabs( w.at(j) * rtol ) ) {
                ac++;
            }

            ww.at(j) = w.at(j);
        }

        //printf ("\n iteration  %d   %d",it,ac);
        //w.printYourself();

        /*  Gramm-Schmidt ortogonalization   */
        for ( int j = 0; j < nc; j++ ) {
            if ( j != 0 ) {
                b.times(x[j], t);
            }

            for ( int ii = 0; ii < j; ii++ ) {
                x[j].add( -x[ii].dotProduct(t), x[ii] );
            }

            b.times(x[j], t);
            x[j].times( 1.0 / sqrt( x[j].dotProduct(t) ) );
        }

        if ( ac > nroot ) {
            break;
        }

        /*  compute new approximation of Z  */
        for ( int j = 0; j < nc; j++ ) {
            b.times(x[j], z[j]);
        }
    }

    // copy results
    IntArray order;
    order.enumerate(w.giveSize());
    std :: sort(order.begin(), order.end(), [&w](int a, int b) { return w.at(a) < w.at(b); });

    _eigv.resize(nroot);
    _r.resize(nn, nroot);
    for ( int i = 1; i <= nroot; i++ ) {
        _eigv.at(i) = w.at(order.at(i));
        _r.setColumn(x[order.at(i) - 1], i);
    }

    if ( it < nitem ) {
		fprintf(outStream, "InverseIteration :: convergence reached in %d iterations\n", it);
    } else {
		fprintf(outStream, "InverseIteration :: convergence not reached after %d iterations\n", it);
    }

    return NM_Success;
}
Пример #15
0
void nZHplots(string chan, string btag, string rootfilename, string textfilename){

  readHist data1(Form("output_%s_%sbtag/Single%s-Run2015D-v1_mZHLimit.root",              chan.data(),btag.data(),(chan=="ele") ? "Electron" : "Muon"));
  readHist data2(Form("output_%s_%sbtag/Single%s-Run2015D-v4_mZHLimit.root",              chan.data(),btag.data(),(chan=="ele") ? "Electron" : "Muon"));
  readHist dy100(Form("output_%s_%sbtag/DYJetsToLL_M-50_HT-100to200_13TeV_mZHLimit.root", chan.data(),btag.data()));
  readHist dy200(Form("output_%s_%sbtag/DYJetsToLL_M-50_HT-200to400_13TeV_mZHLimit.root", chan.data(),btag.data()));
  readHist dy400(Form("output_%s_%sbtag/DYJetsToLL_M-50_HT-400to600_13TeV_mZHLimit.root", chan.data(),btag.data()));
  readHist dy600(Form("output_%s_%sbtag/DYJetsToLL_M-50_HT-600toInf_13TeV_mZHLimit.root", chan.data(),btag.data()));
  readHist tt   (Form("output_%s_%sbtag/TT_TuneCUETP8M1_13TeV_mZHLimit.root",             chan.data(),btag.data()));
  readHist ww   (Form("output_%s_%sbtag/WW_TuneCUETP8M1_13TeV_mZHLimit.root",             chan.data(),btag.data()));
  readHist wz   (Form("output_%s_%sbtag/WZ_TuneCUETP8M1_13TeV_mZHLimit.root",             chan.data(),btag.data()));
  readHist zz   (Form("output_%s_%sbtag/ZZ_TuneCUETP8M1_13TeV_mZHLimit.root",             chan.data(),btag.data()));
  readHist zh   (Form("output_%s_%sbtag/ZH_HToBB_ZToLL_M125_13TeV_mZHLimit.root",         chan.data(),btag.data()));
  readHist m800 (Form("output_%s_%sbtag/ZprimeToZhToZlephbb_M-800_13TeV_mZHLimit.root",   chan.data(),btag.data()));
  readHist m1000(Form("output_%s_%sbtag/ZprimeToZhToZlephbb_M-1000_13TeV_mZHLimit.root",  chan.data(),btag.data()));
  readHist m1200(Form("output_%s_%sbtag/ZprimeToZhToZlephbb_M-1200_13TeV_mZHLimit.root",  chan.data(),btag.data()));
  readHist m1400(Form("output_%s_%sbtag/ZprimeToZhToZlephbb_M-1400_13TeV_mZHLimit.root",  chan.data(),btag.data()));
  readHist m1600(Form("output_%s_%sbtag/ZprimeToZhToZlephbb_M-1600_13TeV_mZHLimit.root",  chan.data(),btag.data()));
  readHist m1800(Form("output_%s_%sbtag/ZprimeToZhToZlephbb_M-1800_13TeV_mZHLimit.root",  chan.data(),btag.data()));
  readHist m2000(Form("output_%s_%sbtag/ZprimeToZhToZlephbb_M-2000_13TeV_mZHLimit.root",  chan.data(),btag.data()));
  readHist m2500(Form("output_%s_%sbtag/ZprimeToZhToZlephbb_M-2500_13TeV_mZHLimit.root",  chan.data(),btag.data()));
  readHist m3000(Form("output_%s_%sbtag/ZprimeToZhToZlephbb_M-3000_13TeV_mZHLimit.root",  chan.data(),btag.data()));
  readHist m3500(Form("output_%s_%sbtag/ZprimeToZhToZlephbb_M-3500_13TeV_mZHLimit.root",  chan.data(),btag.data()));
  readHist m4000(Form("output_%s_%sbtag/ZprimeToZhToZlephbb_M-4000_13TeV_mZHLimit.root",  chan.data(),btag.data()));

  string histName = "mZH";

  TH1D* h_Data   = (TH1D*)(data1.getHist(histName.data()))->Clone("h_Data");
  TH1D* h_SubDom = (TH1D*)(tt.getHist(histName.data()))->Clone("h_SubDom");

  h_Data->Reset();
  h_SubDom->Reset();

  h_Data->Add(data1.getHist(histName.data()));
  h_Data->Add(data2.getHist(histName.data()));
    
  h_SubDom->Add(tt.getHist(histName.data()));
  h_SubDom->Add(ww.getHist(histName.data()));
  h_SubDom->Add(wz.getHist(histName.data()));
  h_SubDom->Add(zz.getHist(histName.data()));
  h_SubDom->Add(zh.getHist(histName.data()));

  TH1D* h_M800  = (TH1D*)(m800 .getHist(histName.data()));
  TH1D* h_M1000 = (TH1D*)(m1000.getHist(histName.data()));
  TH1D* h_M1200 = (TH1D*)(m1200.getHist(histName.data()));
  TH1D* h_M1400 = (TH1D*)(m1400.getHist(histName.data()));
  TH1D* h_M1600 = (TH1D*)(m1600.getHist(histName.data()));
  TH1D* h_M1800 = (TH1D*)(m1800.getHist(histName.data()));
  TH1D* h_M2000 = (TH1D*)(m2000.getHist(histName.data()));
  TH1D* h_M2500 = (TH1D*)(m2500.getHist(histName.data()));
  TH1D* h_M3000 = (TH1D*)(m3000.getHist(histName.data()));
  TH1D* h_M3500 = (TH1D*)(m3500.getHist(histName.data()));
  TH1D* h_M4000 = (TH1D*)(m4000.getHist(histName.data()));
        
  // dominant background is comming from alpha method

  TFile* f_Dom = TFile::Open(Form("systUncOnShapes/background_FitDev_root/background_FitDev_%s_cat%s.root",chan.data(),btag.data()));
  TH1D*  h_Dom = (TH1D*)(f_Dom->Get("background_FitDev"));

  TFile* outFile = new TFile(rootfilename.data(), "recreate");

  h_Data  ->Write("data_obs");		 
  h_Dom   ->Write("ZJETS");
  h_SubDom->Write("SUBDOM");
  h_M800  ->Write("SIGM800");
  h_M1000 ->Write("SIGM1000");
  h_M1200 ->Write("SIGM1200");
  h_M1400 ->Write("SIGM1400");
  h_M1600 ->Write("SIGM1600");
  h_M1800 ->Write("SIGM1800");
  h_M2000 ->Write("SIGM2000");
  h_M2500 ->Write("SIGM2500");
  h_M3000 ->Write("SIGM3000");
  h_M3500 ->Write("SIGM3500");
  h_M4000 ->Write("SIGM4000");

  outFile->Write();
  
  fstream ftext;
  ftext.open(textfilename.data(), ios::out);

  ftext << "DATA\t"   << h_Data  ->Integral() << "\n"; 
  ftext << "ZJETS\t"  << h_Dom   ->Integral() << "\n";
  ftext << "SUBDOM\t" << h_SubDom->Integral() << "\n";
  ftext << "M800\t"   << h_M800  ->Integral() << "\n";
  ftext << "M1000\t"  << h_M1000 ->Integral() << "\n";
  ftext << "M1200\t"  << h_M1200 ->Integral() << "\n";
  ftext << "M1400\t"  << h_M1400 ->Integral() << "\n";
  ftext << "M1600\t"  << h_M1600 ->Integral() << "\n";
  ftext << "M1800\t"  << h_M1800 ->Integral() << "\n";
  ftext << "M2000\t"  << h_M2000 ->Integral() << "\n";
  ftext << "M2500\t"  << h_M2500 ->Integral() << "\n";
  ftext << "M3000\t"  << h_M3000 ->Integral() << "\n";
  ftext << "M3500\t"  << h_M3500 ->Integral() << "\n";
  ftext << "M4000\t"  << h_M4000 ->Integral() << "\n";
  
  ftext.close();

}
Пример #16
0
// Find the minimum fitness value close to a discrete GA gene using
//  inverse hessian minimization
double US_MPI_Analysis::minimize_dmga( DGene& dgene, double fitness )
{
DbgLv(1) << my_rank << "dg:IHM:minimize dgene comps" << dgene.components.size() << fitness;
   int vsize     = nfloatc;
   US_Vector vv( vsize );  // Input values
   US_Vector uu( vsize );  // Vector of derivatives
   US_Vector zz( vsize );  // Vector of normalizing factors

   // Create hessian as identity matrix
   QVector< QVector< double > > hessian( vsize );

   for ( int ii = 0; ii < vsize; ii++ ) 
   {
      hessian[ ii ]       = QVector< double >( vsize, 0.0 );
      hessian[ ii ][ ii ] = 1.0;
   }

   dgmarker.resize( vsize );
   marker_from_dgene( dgmarker, dgene );

   // Convert gene to array of normalized doubles and save normalizing factors
   for ( int ii = 0; ii < vsize; ii++ )
   {
      double vval   = dgmarker[ ii ];
      double vpwr   = (double)qFloor( log10( vval ) );
      double vnorm  = pow( 10.0, -vpwr );
      vv.assign( ii, vval * vnorm );
      zz.assign( ii, vnorm );
DbgLv(1) << my_rank << "dg:IHM:  ii" << ii << "vval vnorm" << vval << vnorm
         << "vpwr" << vpwr << "vvi" << vv[ii];
   }

   lamm_gsm_df_dmga( vv, uu, zz );   // uu is vector of derivatives

   static const double epsilon_f      = 1.0e-7;
   static const int    max_iterations = 20;
   int    iteration      = 0;
   double epsilon        = epsilon_f * fitness * 4.0;
   bool   neg_cnstr      = ( vv[ 0 ] < 0.1 );  // Negative constraint?

   while ( uu.L2norm() >= epsilon_f  && iteration < max_iterations )
   {
      iteration++;
      if ( fitness == 0.0 ) break;

      US_Vector v_s1 = vv;
      double g_s1    = fitness;
      double s1      = 0.0;
      double s2      = 0.5;
      double s3      = 1.0;
DbgLv(1) << my_rank << "dg:IHM:   iteration" << iteration << "fitness" << fitness;

      // v_s2 = vv - uu * s2
      US_Vector v_s2( vsize );
      vector_scaled_sum( v_s2, uu, -s2, vv );

      if ( neg_cnstr  &&  v_s2[ 0 ] < 0.1 )
      {
         v_s2.assign( 0, 0.1 + u_random( 100 ) * 0.001 );
      }

      double g_s2 = get_fitness_v_dmga( v_s2, zz );
DbgLv(1) << my_rank << "dg:IHM: g_s2" << g_s2 << "s2" << s2 << "epsilon" << epsilon;

      // Cut down until we have a decrease
      while ( s2 > epsilon  &&  g_s2 > g_s1 )
      {
         s3  = s2;
         s2 *= 0.5;
         // v_s2 = vv - uu * s2
         vector_scaled_sum( v_s2, uu, -s2, vv );

         if ( neg_cnstr  &&  v_s2[ 0 ] < 0.1 )
         {
            v_s2.assign( 0, 0.1 + u_random( 100 ) * 0.001 );
         }

         g_s2 = get_fitness_v_dmga( v_s2, zz );
      }
DbgLv(1) << my_rank << "dg:IHM:  g_s2" << g_s2;

      // Test for initial decrease
      if ( s2 <= epsilon  ||  ( s3 - s2 ) < epsilon ) break;

      US_Vector v_s3( vsize );

      // v_s3 = vv - uu * s3
      vector_scaled_sum( v_s3, uu, -s3, vv );

      if ( neg_cnstr  &&  v_s3[ 0 ] < 0.1 )
      {
         v_s3.assign( 0, 0.1 + u_random( 100 ) * 0.001 );
      }

      double g_s3 = get_fitness_v_dmga( v_s3, zz );

      int              reps     = 0;
      static const int max_reps = 100;

      while ( ( ( s2 - s1 ) > epsilon )  &&
              ( ( s3 - s2 ) > epsilon )  &&
              ( reps++ < max_reps ) )
      {
         double s1_s2 = 1.0 / ( s1 - s2 );
         double s1_s3 = 1.0 / ( s1 - s3 );
         double s2_s3 = 1.0 / ( s2 - s3 );

         double s1_2 = sq( s1 );
         double s2_2 = sq( s2 );
         double s3_2 = sq( s3 );

         double aa = ( ( g_s1 - g_s3 ) * s1_s3 -
                       ( g_s2 - g_s3 ) * s2_s3
                     ) * s1_s2;

         double bb = ( g_s3 * ( s2_2 - s1_2 ) +
                       g_s2 * ( s1_2 - s3_2 ) +
                       g_s1 * ( s3_2 - s2_2 )
                     ) *
                     s1_s2 * s1_s3 * s2_s3;

         static const double max_a = 1.0e-25;

         if ( qAbs( aa ) < max_a )
         {
            // Restore gene from array of normalized doubles
            for ( int ii = 0; ii < vsize; ii++ )
            {
               dgmarker[ ii ] = vv[ ii ] / zz[ ii ];
            }

            dgene_from_marker( dgmarker, dgene );

            return fitness;
         }

         double xx        = -bb / ( 2.0 * aa );
         double prev_g_s2 = g_s2;

         if ( xx < s1 )
         {
            if ( xx < ( s1 + s1 - s2 ) ) // Keep it close
            {
               xx = s1 + s1 - s2;             // xx <- s1 + ds
               if ( xx < 0 ) xx = s1 / 2.0;
            }

            if ( xx < 0 )  //  Wrong direction!
            {
               if ( s1 < 0 ) s1 = 0.0;
               xx = 0;
            }

            // OK, take xx, s1, s2 
            v_s3  = v_s2;
            g_s3  = g_s2;                  // 3 <- 2
            s3    = s2;
            v_s2  = v_s1;
            g_s2  = g_s1;
            s2    = s1;                    // 2 <- 1
            s1    = xx;                    // 1 <- xx
 
            // v_s1 = vv - uu * s1
            vector_scaled_sum( v_s1, uu, -s1, vv );
 
            if ( neg_cnstr  &&  v_s1[ 0 ] < 0.1 )
            {
               v_s1.assign( 0, 0.1 + u_random( 100 ) * 0.001 );
            }

            g_s1 = get_fitness_v_dmga( v_s1, zz ); 
         }
         else if ( xx < s2 ) // Take s1, xx, s2
         {
            v_s3  = v_s2;
            g_s3  = g_s2;             // 3 <- 2
            s3    = s2;
            s2    = xx;               // 2 <- xx

            // v_s2 = vv - uu * s2
            vector_scaled_sum( v_s2, uu, -s2, vv );

            if ( neg_cnstr  &&  v_s2[ 0 ] < 0.1 )
            {
               v_s2.assign( 0, 0.1 + u_random( 100 ) * 0.001 );
            }

            g_s2 = get_fitness_v_dmga( v_s2, zz );
         }
         else if ( xx < s3 )  // Take s2, xx, s3
         {
            v_s1  = v_s2;
            g_s1  = g_s2;
            s1    = s2;              // 2 <- 1
            s2    = xx;              // 2 <- xx

            // v_s2 = vv - uu * s2
            vector_scaled_sum( v_s2, uu, -s2, vv );

            if ( neg_cnstr  &&  v_s2[ 0 ] < 0.1 )
            {
               v_s2.assign( 0, 0.1 + u_random( 100 ) * 0.001 );
            }

            g_s2 = get_fitness_v_dmga( v_s2, zz );
         }
         else  // xx >= s3
         {
            if ( xx > ( s3 + s3 - s2 ) ) // if xx > s3 + ds/2
            { 
               // v_s4 = vv - uu * xx
               US_Vector v_s4( vsize );
               vector_scaled_sum( v_s4, uu, -xx, vv );

               if ( neg_cnstr  &&  v_s4[ 0 ] < 0.1 )
               {
                  v_s4.assign( 0, 0.1 + u_random( 100 ) * 0.001 );
               }

               double g_s4 = get_fitness_v_dmga( v_s4, zz );

               if ( g_s4 > g_s2  &&  g_s4 > g_s3  &&  g_s4 > g_s1 ) 
               {
                  xx = s3 + s3 - s2;   // xx = s3 + ds/2
               }
            }

            // Take s2, s3, xx 
            v_s1  = v_s2;
            g_s1  = g_s2;            // 1 <- 2
            s1    = s2;
            v_s2  = v_s3;
            g_s2  = g_s3;
            s2    = s3;              // 2 <- 3
            s3    = xx;              // 3 <- xx

            // v_s3 = vv - uu * s3
            vector_scaled_sum( v_s3, uu, -s3, vv );

            if ( neg_cnstr  &&  v_s3[ 0 ] < 0.1 )
            {
               v_s3.assign( 0, 0.1 + u_random( 100 ) * 0.001 );
            }

            g_s3 = get_fitness_v_dmga( v_s3, zz );
         }

         if ( qAbs( prev_g_s2 - g_s2 ) < epsilon ) break;
      }  // end of inner loop

      US_Vector v_p( vsize );

      if ( g_s2 < g_s3  &&  g_s2 < g_s1 )
      {
         v_p     = v_s2;
         fitness = g_s2;
      }
      else if ( g_s1 < g_s3 )
      {
         v_p     = v_s1;
         fitness = g_s1;
      }
      else
      {
         v_p     = v_s3;
         fitness = g_s3;
      }
      
      US_Vector v_g( vsize );            // Vector of derivatives
      lamm_gsm_df_dmga( v_p, v_g, zz );  // New gradient in v_g (old in uu) 

      US_Vector v_dx( vsize );
      // v_dx = v_p - vv
      vector_scaled_sum( v_dx, vv, -1.0, v_p );


      vv = v_p;                      // vv   = v_p

      // dgradient  v_dg = v_g - uu
      US_Vector v_dg( vsize );
      vector_scaled_sum( v_dg, uu, -1.0, v_g );

      US_Vector v_hdg( vsize );

      // v_hdg = hessian * v_dg ( matrix * vector )
      for ( int ii = 0; ii < vsize; ii++ )
      {
         double dotprod = 0.0;

         for ( int jj = 0; jj < vsize; jj++ )
            dotprod += ( hessian[ ii ][ jj ] * v_dg[ jj ] );

         v_hdg.assign( ii, dotprod );
      }

      double fac   = v_dg.dot( v_dx  );
      double fae   = v_dg.dot( v_hdg );
      double sumdg = v_dg.dot( v_dg  );
      double sumxi = v_dx.dot( v_dx  );

      if ( fac > sqrt( epsilon * sumdg * sumxi ) )
      {
         fac        = 1.0 / fac;
         double fad = 1.0 / fae;

         for ( int ii = 0; ii < vsize; ii++ )
         {
            v_dg.assign( ii, fac * v_dx[ ii ] - fad * v_hdg[ ii ] );
         }

         for ( int ii = 0; ii < vsize; ii++ )
         {
            for ( int jj = ii; jj < vsize; jj++ )
            {
               hessian[ ii ][ jj ] +=
                  fac * v_dx [ ii ] * v_dx [ jj ] -
                  fad * v_hdg[ ii ] * v_hdg[ jj ] +
                  fae * v_dg [ ii ] * v_dg [ jj ];

                 // It's a symmetrical matrix
                 hessian[ jj ][ ii ] = hessian[ ii ][ jj ];
            }
         }
      }

      // uu = hessian * v_g ( matrix * vector )
      for ( int ii = 0; ii < vsize; ii++ )
      {
         double dotprod = 0.0;

         for ( int jj = 0; jj < vsize; jj++ )
            dotprod    += ( hessian[ ii ][ jj ] * v_g[ jj ] );

         uu.assign( ii, dotprod );
      }

   }  // end while ( uu.L2norm() > epsilon )

   // Restore gene from array of normalized doubles
   for ( int ii = 0; ii < vsize; ii++ )
   {
      dgmarker[ ii ] = vv[ ii ] / zz[ ii ];
DbgLv(1) << my_rank << "dg:IHM: ii" << ii << "vvi zzi dgmi"
         << vv[ii] << zz[ii] << dgmarker[ii];
   }

   dgene_from_marker( dgmarker, dgene );
DbgLv(1) << my_rank << "dg:IHM: FITNESS" << fitness;

   return fitness;
}