void InducedCostHeuristicLight::setPermanent(const Edge e) {
  if (graph.getWeight(e) == LightCompleteGraph::Permanent) {
    return;
  }
  NodeId u = e.u;
  NodeId v = e.v;
  EdgeWeight uv = graph.getWeight(e);
  for (NodeId w : graph.getUnprunedNeighbours(u)) {
    if (w == v)
      continue;
    Edge uw(u, w);
    Edge vw(v, w);
    updateTriplePermanentUW(uv, uw, graph.getWeight(vw));
  }
  for (NodeId w : graph.getUnprunedNeighbours(v)) {
    if (w == u)
      continue;
    Edge uw(u, w);
    Edge vw(v, w);
    updateTriplePermanentUW(uv, vw, graph.getWeight(uw));
  }
  if (graph.getWeight(e) < 0)
    totalCost -= graph.getWeight(e);
  graph.setWeight(e, LightCompleteGraph::Permanent);
}
Esempio n. 2
0
void MMD_Polynomial::Normalize( void )
{
	if( getNewMaxPow() > MMD_Polynomial_MAX_POW_VALUE )
		throw "Power value is too big in the operation with polynom";
	switch( getType() )
	{
	case DSRDATA_TYPE_INTEGER:
		_getNormalCoef_integer();
		break;
	case DSRDATA_TYPE_REAL:  
		_getNormalCoef_real();
		break;
	case DSRDATA_TYPE_COMPLEX:
		_getNormalCoef_complex();
		break;
	default:
		break;
	}
	term_pow.Flush();
	for( long i = 0; i < getTermCount(); i++ )
	{
		CDSRInteger iV( i );
		UniWord uw( iV );
		term_pow.Add( uw );
	}
	is_normal = true;
}
Esempio n. 3
0
void MMD_Polynomial::_getNormalCoef_integer( void )
{
	if( !term_coef.ArrayDim() ) return;

	MArray<UniWord> tmp( term_coef.ArrayDim(), 0, term_coef.ArrayDim() );
	tmp.Copy( term_coef );
	term_coef.Flush();

	long i, mp;
	UniWord n( CDSRInteger( 0 ) );
	for( i = 0; i < getMaxPow() + 1; i++ )
		term_coef.Add( n );
	for( i = 0; i < (long) term_pow.ArrayDim(); i++ )
		_dsrop_Add_integer( term_coef[ term_pow[ i ].getInteger() ], term_coef[ term_pow[ i ].getInteger() ], tmp[ i ] );
	mp = getMaxPow();
	for( i = mp; i >= 0; i-- )
	{
		UniWord uw( CDSRInteger( 0 ) );
		if( _dsrop_Equal_integer( uw, getCoef( i ), UniWord( CDSRInteger( 0 ) ) ).getInteger() )
		{
			term_coef.erase( term_coef.begin() + i );
			mp--;
		}
		else
			break;
	}
	if( mp < getMaxPow() )
		max_pow = mp;
}
Esempio n. 4
0
  void 
  CSPolymerEstimator::accumulate(WalkerIterator first, WalkerIterator last, RealType wgt)
  {
    //Directionless=2
    for(int i=0,ii=0; i<NumCopies; i++) 
    {
      RealType uw(Reptile->UmbrellaWeight[i]);
      RealType ehead=Reptile->front()->Action(i,2);
      RealType etail=Reptile->back()->Action(i,2);
      scalars[ii]((ehead+etail)*OneOverTau,uw);
      //d_data[ii++] += uw*(ehead+etail)*OneOverTau;
      //d_data[ii++] += uw*(ehead*ehead+etail*etail)*OneOverTau;
      //d_data[ii++] += uw;
    }
    //d_wgt += 1.0;
    //TinyVector<RealType,4> e,uw;
    //for(int i=0; i<NumCopies; i++) 
    //{
    //  //get the pointer to the i-th row
    //  const RealType* restrict prop=awalker.getPropertyBase(i);
    //  uw[i] = prop[UMBRELLAWEIGHT];
    //  e[i] = prop[LOCALENERGY];
    //  d_data[ii++]+=uw[i]*e[i];
    //  d_data[ii++]+=uw[i]*e[i]*e[i];
    //  d_data[ii++]+=uw[i];
    //}

    //for(int i=0; i<NumCopies-1; i++) 
    //  for(int j=i+1; j<NumCopies; j++)
    //    d_data[ii++]+=uw[i]*e[i]-uw[j]*e[j];
  }
Esempio n. 5
0
double CCoons:: y(double u,double w)
{
	double temp;
	
	double M[4];

	/*double R[4][4]={
		
        {0,0,0,0},
        {0,-0.75,0.75,-0.75},
        {0,0.75,-0.75,0.75},
        {0,0,-0.75,0}
		
    };*/

	double Matrix[4][4];

	uw(CMy,Matrix);

	for (int i=0;i<4;i++)
	{
		//M[i]=u*u*u*R[i][0]+u*u*R[i][1]+u*R[i][2]+R[i][3];
		M[i]=u*u*u*Matrix[i][0]+u*u*Matrix[i][1]+u*Matrix[i][2]+Matrix[i][3];
	}
	
	
	temp=w*w*w*M[0]+w*w*M[1]+w*M[2]+M[3];
	
	return temp;
}
Esempio n. 6
0
MMD_Polynomial::MMD_Polynomial( CParseDsrSymbolTable& _smbtable,
								enum CDsrDataTypes nested_type, 
								long term_c ) :
	MMD_Object( 
		_smbtable, 
		_smbtable.getTypeTable().makeDataTypeNode( 
			new CDsrDataType_Polynomial( 
				_smbtable.getTypeTable().makeDataTypeNode( nested_type ) 
			) ) ),
	term_pow( 8, 0, 8 ), term_coef( 8, 0, 8 )
{
	var_name = _T("");
	if( term_c > 0 )
	{
		long i;
		CDSRInteger iV( 0 );
		CDSRReal rV( 0 );
		CDSRComplex cV( 0 );
		switch( getType() )
		{
		case DSRDATA_TYPE_INTEGER:
			for( i = 0; i < term_c; i++ )
			{
				UniWord uw( iV );
				term_pow.Add( uw );
				term_coef.Add( uw );
			}
			break;
		case DSRDATA_TYPE_REAL:
			for( i = 0; i < term_c; i++ )
			{
				UniWord uw1( iV );
				UniWord uw2( rV );
				term_pow.Add( uw1 );
				term_coef.Add( uw2 );
			}
			break;
		case DSRDATA_TYPE_COMPLEX:
			for( i = 0; i < term_c; i++ )
			{
				UniWord uw1( iV );
				UniWord uw2( cV );
				term_pow.Add( uw1 );
				term_coef.Add( uw2 );
			}
			break;
		default:
			break;
		}
	}
	max_pow = -1;
	is_normal = 0;
}
  void HFDHE2PolymerEstimator::accumulate(WalkerIterator first, WalkerIterator last, RealType wgt)
  {
    for(int i=0; i<NumCopies; i++) 
    {
      RealType uw(Reptile->UmbrellaWeight[i]);
      //Adding all parts from the Hamiltonian
      RealType* restrict HeadProp(Reptile->front()->getPropertyBase(i));
      RealType* restrict TailProp(Reptile->back()->getPropertyBase(i));
      RealType eloc = 0.5*( HeadProp[LOCALENERGY] + TailProp[LOCALENERGY]);
      scalars[0](eloc,uw);
      for(int obsi=0;obsi<SizeOfHamiltonians ;obsi++){
        scalars[obsi+1]( 0.5*( HeadProp[obsi+FirstHamiltonian] + TailProp[obsi+FirstHamiltonian]) , uw);
      };
      //Center Pressure
      RealType* restrict CenProp(Reptile->center()->getPropertyBase(i));
      scalars[SizeOfHamiltonians+3]( (2.0*eloc-2.0*CenProp[LOCALPOTENTIAL])*pNorm + CenProp[Pindex+1+FirstHamiltonian] ,uw);
      
      int Rage(Reptile->Age);
      int Bage=Rage;

      RealType tmpV=0.0;
      RealType tmpP=0.0;
      KEconst = (*(Reptile->begin()))->Drift.size()  * 1.5 * OneOverTau;
      for( MultiChain::iterator Bit = Reptile->begin();Bit != (Reptile->end());Bit++){
        tmpP+= (*Bit)->getPropertyBase(i)[Pindex+1+FirstHamiltonian];
        tmpV+=(*Bit)->getPropertyBase(i)[LOCALPOTENTIAL];
        Bage=min((*Bit)->stepmade,Bage);
      };

      tmpP-=0.5*Reptile->back()->getPropertyBase(i)[Pindex+1+FirstHamiltonian];
      tmpP-=0.5*Reptile->front()->getPropertyBase(i)[Pindex+1+FirstHamiltonian];
      tmpV-=0.5*Reptile->back()->getPropertyBase(i)[LOCALPOTENTIAL];
      tmpV-=0.5*Reptile->front()->getPropertyBase(i)[LOCALPOTENTIAL];
      tmpV *= -2.0*pNorm*Tau;
      tmpP *= Tau;

      scalars[SizeOfHamiltonians+1](tmpV+tmpP,uw);
      scalars[SizeOfHamiltonians+2](eloc*(tmpV+tmpP),uw);
      scalars[SizeOfHamiltonians+4](Rage-Bage,1.0);

    }
  }
Esempio n. 8
0
void PenWindow::layout()
{
   CEGUI::UDim ux(0,10);
   CEGUI::UDim uy(0,0);
   CEGUI::UDim uw(0,0);
   CEGUI::UDim uh(0,0);

   CEGUI::Size size = getPixelSize();

   {
      CEGUI::UVector2 bsize;
      bsize.d_x = CEGUI::UDim(0,BUTTON_SIZE);
      bsize.d_y = CEGUI::UDim(0,BUTTON_SIZE);

      const int cellsize = (BUTTON_SIZE + SPACE_SIZE);
      int nx = (int)(size.d_width - (2*MARGIN_SIZE)) / cellsize;
      if (nx < 1) { nx = 1; }

      int xi = 0;
      int yi = 0;
      CEGUI::UDim x(0,0),y(0,0);
      for (size_t i=0; i<_button.size(); ++i) {
         for (size_t j=0; j<_button[i].size(); ++j) {
            x.d_offset = MARGIN_SIZE + (0.5f * SPACE_SIZE) + xi*cellsize;
            y.d_offset = MARGIN_SIZE + (0.5f * SPACE_SIZE) + yi*cellsize;
            _button[i][j]->setSize(bsize);
            _button[i][j]->setPosition(CEGUI::UVector2(x,y));

            xi++;
            if (xi == nx) {
               xi = 0;
               yi++;
            }
         }
         yi++;
         xi = 0;
      }
   }
}
Esempio n. 9
0
  void CSVMCUpdatePbyP::advanceWalkers(WalkerIter_t it, WalkerIter_t it_end, bool measure)
  {
    int iwalker=0; 
    //only used locally
    vector<RealType> ratio(nPsi), uw(nPsi);
    while(it != it_end) 
    {  //Walkers loop

      Walker_t& thisWalker(**it);
      Walker_t::Buffer_t& w_buffer(thisWalker.DataSet);

      W.R = thisWalker.R;
      w_buffer.rewind();

      // Copy walker info in W
      W.copyFromBuffer(w_buffer);
      for(int ipsi=0; ipsi<nPsi; ipsi++){
        // Copy wave function info in W and Psi1
        Psi1[ipsi]->copyFromBuffer(W,w_buffer);  
        Psi1[ipsi]->G=W.G;
        Psi1[ipsi]->L=W.L;
      }

      makeGaussRandomWithEngine(deltaR,RandomGen);

      for(int ipsi=0; ipsi<nPsi; ipsi++)
      {
        uw[ipsi]= thisWalker.Properties(ipsi,UMBRELLAWEIGHT);
      }

      // Point to the correct walker in the ratioij buffer
      RealType* restrict ratioijPtr=ratioIJ[iwalker];

      bool moved = false;
      for(int iat=0; iat<W.getTotalNum(); iat++) {  //Particles loop

        PosType dr = m_sqrttau*deltaR[iat];
        PosType newpos = W.makeMove(iat,dr);

        RealType ratio_check=1.0;
        for(int ipsi=0; ipsi<nPsi; ipsi++)
        {
         // Compute ratios before and after the move
          ratio_check *= ratio[ipsi] = Psi1[ipsi]->ratio(W,iat,*G1[ipsi],*L1[ipsi]); 
          logpsi[ipsi]=std::log(ratio[ipsi]*ratio[ipsi]);
          // Compute Gradient in new position
          //*G1[ipsi]=Psi1[ipsi]->G + dG;
          // Initialize: sumratio[i]=(Psi[i]/Psi[i])^2=1.0
          sumratio[ipsi]=1.0;
        }

        bool accept_move=false;
        if(ratio_check>1e-12)//if any ratio is too small, reject the move automatically
        {
          int indexij(0);
          // Compute new (Psi[i]/Psi[j])^2 and their sum
          for(int ipsi=0; ipsi< nPsi-1; ipsi++)
          {
            for(int jpsi=ipsi+1; jpsi < nPsi; jpsi++, indexij++)
            {
              // Ratio between norms is already included in ratioijPtr from initialize.
              RealType rji=std::exp(logpsi[jpsi]-logpsi[ipsi])*ratioijPtr[indexij];
              instRij[indexij]=rji;
              //ratioij[indexij]=rji;
              sumratio[ipsi] += rji;
              sumratio[jpsi] += 1.0/rji;
            }
          }

          // Evaluate new Umbrella Weight
          for(int ipsi=0; ipsi< nPsi ;ipsi++) invsumratio[ipsi]=1.0/sumratio[ipsi];

          RealType td=ratio[0]*ratio[0]*sumratio[0]/(*it)->Multiplicity;
          accept_move=Random()<std::min(1.0,td);
        }
        //RealType prob = std::min(1.0,td);
        //if(Random() < prob) 
        if(accept_move)
        { 
          /* Electron move is accepted. Update:
             -ratio (Psi[i]/Psi[j])^2 for this walker
             -Gradient and laplacian for each Psi1[i]
             -Drift
             -buffered info for each Psi1[i]*/
          moved = true;
          ++nAccept;
          W.acceptMove(iat);
          // Update Buffer for (Psi[i]/Psi[j])^2 
          std::copy(instRij.begin(),instRij.end(),ratioijPtr);
          // copy new Umbrella weight for averages
          uw=invsumratio;

          // Store sumratio for next Accept/Reject step to Multiplicity
          //thisWalker.Properties(SUMRATIO)=sumratio[0];
          thisWalker.Multiplicity=sumratio[0];
          for(int ipsi=0; ipsi< nPsi; ipsi++)
          {
            //Update local Psi1[i] buffer for the next move
            Psi1[ipsi]->acceptMove(W,iat);  
            //Update G and L in Psi1[i]
            //Psi1[ipsi]->G = *G1[ipsi];
            Psi1[ipsi]->G += *G1[ipsi];
            Psi1[ipsi]->L += *L1[ipsi];
            thisWalker.Properties(ipsi,LOGPSI)+=std::log(abs(ratio[ipsi]));
          }
        } else {
          ++nReject;
          W.rejectMove(iat);
          for(int ipsi=0; ipsi< nPsi; ipsi++)
            Psi1[ipsi]->rejectMove(iat);
        }
      }

      if(moved) {
        /* The walker moved: Info are copied back to buffers:
           -copy (Psi[i]/Psi[j])^2 to ratioijBuffer
           -Gradient and laplacian for each Psi1[i]
           -Drift
           -buffered info for each Psi1[i]
           Physical properties are updated */
        (*it)->Age=0;
        (*it)->R = W.R;
        w_buffer.rewind();
        W.copyToBuffer(w_buffer);
        for(int ipsi=0; ipsi< nPsi; ipsi++){
          W.G=Psi1[ipsi]->G;
          W.L=Psi1[ipsi]->L;
          //ValueType psi = Psi1[ipsi]->evaluate(W,w_buffer);
          ValueType logpsi = Psi1[ipsi]->evaluateLog(W,w_buffer);
          RealType et = H1[ipsi]->evaluate(W);

          //multiEstimator->updateSample(iwalker,ipsi,et,UmbrellaWeight[ipsi]);
          //Properties is used for UmbrellaWeight and UmbrellaEnergy
          thisWalker.Properties(ipsi,UMBRELLAWEIGHT)=uw[ipsi];
          thisWalker.Properties(ipsi,LOCALENERGY)=et;
          H1[ipsi]->saveProperty(thisWalker.getPropertyBase(ipsi));
        }
      }
      else 
      {
        ++nAllRejected;
      }
      ++it; ++iwalker;
    }
  }
Esempio n. 10
0
void MJPolymerEstimator::accumulate(const MCWalkerConfiguration& W
                                    , WalkerIterator first, WalkerIterator last, RealType wgt)
{
    for(int i=0; i<NumCopies; i++)
    {
        RealType uw(Reptile->UmbrellaWeight[i]);
        //Adding all parts from the Hamiltonian
        RealType* restrict HeadProp(Reptile->front()->getPropertyBase(i));
        RealType* restrict TailProp(Reptile->back()->getPropertyBase(i));
        RealType eloc = 0.5*( HeadProp[LOCALENERGY] + TailProp[LOCALENERGY]);
        scalars[0](eloc,uw);
        for(int obsi=0; obsi<SizeOfHamiltonians ; obsi++) {
            scalars[obsi+1]( 0.5*( HeadProp[obsi+FirstHamiltonian] + TailProp[obsi+FirstHamiltonian]) , uw);
        };
        //Center Pressure
        RealType* restrict CenProp(Reptile->center()->getPropertyBase(i));
        scalars[SizeOfHamiltonians+6]( (2.0*eloc-CenProp[LOCALPOTENTIAL])*pNorm ,uw);
        scalars[SizeOfHamiltonians+9]( CenProp[LOCALPOTENTIAL] ,uw);
        scalars[SizeOfHamiltonians+10]( HeadProp[LOCALENERGY] * TailProp[LOCALENERGY] ,uw);
        RealType energy_head = HeadProp[LOCALENERGY];
        RealType energy_tail = TailProp[LOCALENERGY];
        scalars[SizeOfHamiltonians+11]( HeadProp[LOCALENERGY] ,uw);
        scalars[SizeOfHamiltonians+12]( TailProp[LOCALENERGY] ,uw);

//       int Rage(Reptile->Age);
//       int Bage=Rage;
//
// //       RealType tmpE=0.0;
//       RealType tmpV=0.0;
// //       RealType tmpF=0.0;
// //       RealType localE=0.0;
// //       KEconst = (*(Reptile->begin()))->Drift.size()  * 1.5 * OneOverTau;
//       for( MultiChain::iterator Bit = Reptile->begin();Bit != (Reptile->end());Bit++){
// //         localE += 0.5*( (*Bit)->deltaRSquared[0] + (*Bit)->deltaRSquared[1]);
// //         tmpF+= 0.5*(*Bit)->deltaRSquared[2];
// //         tmpE+=(*Bit)->getPropertyBase(i)[LOCALENERGY];
//         tmpV+=(*Bit)->getPropertyBase(i)[LOCALPOTENTIAL];
//         Bage=min((*Bit)->stepmade,Bage);
//       };
//
// //       tmpF-=0.25*Reptile->back()->deltaRSquared[2];
// //       tmpF-=0.25*Reptile->front()->deltaRSquared[2];
// //       tmpE-=0.5*Reptile->back()->getPropertyBase(i)[LOCALENERGY];
// //       tmpE-=0.5*Reptile->front()->getPropertyBase(i)[LOCALENERGY];
//       tmpV-=0.5*Reptile->back()->getPropertyBase(i)[LOCALPOTENTIAL];
//       tmpV-=0.5*Reptile->front()->getPropertyBase(i)[LOCALPOTENTIAL];
//       tmpV *= -pNorm*Tau;
//
// //       localE *= -0.5*OneOverTau*OneOverTau;
// //       localE += KEconst* (Reptile->Last) + tmpF ;
// //       localE += tmpE;
//
//       scalars[SizeOfHamiltonians+1](tmpV,uw);
//       scalars[SizeOfHamiltonians+2](eloc*tmpV,uw);
//
//       scalars[SizeOfHamiltonians+4](Rage-Bage,1.0);

        ///This is the center bead energy using PIMC stuff.
//       localE *= 1.0/(Reptile->Last);
//       scalars[SizeOfHamiltonians+5]( localE ,uw);

        int Rage(Reptile->Age);
        int Bage=Rage;

        RealType tmpV_head=0.0;
        RealType tmpV_tail=0.0;
        RealType tmpF=0.0;
        int maxtouch=0;
        MultiChain::iterator Bit = Reptile->begin();
        MultiChain::iterator Lit = Reptile->end();
        MultiChain::iterator Endit = Reptile->end();
        Endit--;

        //truncated version of estimator
        Lit--;
        for(int j=0 ; ( (j<truncLength[0]) && (Bit != Endit) ); Bit++,Lit--,j++) {
            tmpV_head+= (*Bit)->getPropertyBase(i)[LOCALPOTENTIAL];
            tmpV_tail+= (*Lit)->getPropertyBase(i)[LOCALPOTENTIAL];
            if ((*Bit)->timesTouched>maxtouch) maxtouch = (*Bit)->timesTouched;
            if ((*Bit)->stepmade < Bage) Bage = (*Bit)->stepmade;
        };
        RealType Ppref = (-pNorm*Tau);





        RealType tmpVsum = (energy_tail*tmpV_head + energy_head*tmpV_tail)*Ppref;
        scalars[SizeOfHamiltonians+3]((tmpV_head+tmpV_tail)*Ppref,uw);
        scalars[SizeOfHamiltonians+4](0.0,uw);
        scalars[SizeOfHamiltonians+5]( tmpVsum,uw);

        //continue sum for comparison to truncated version
        for( ; Bit != Endit; Bit++ ) {
            tmpV_head+= (*Bit)->getPropertyBase(i)[LOCALPOTENTIAL];
//         tmpV_tail+= (*Lit)->getPropertyBase(i)[LOCALPOTENTIAL];
            if ((*Bit)->timesTouched>maxtouch) maxtouch = (*Bit)->timesTouched;
            if ((*Bit)->stepmade < Bage) Bage = (*Bit)->stepmade;
        };

        RealType tmpV = tmpV_head*Ppref;
        RealType tmpEVsum = 0.5*(energy_head  + energy_tail)*tmpV;
        scalars[SizeOfHamiltonians+1](tmpV,uw);
        scalars[SizeOfHamiltonians+2](tmpEVsum,uw);


        scalars[SizeOfHamiltonians+7](Rage-Bage,1.0);
        scalars[SizeOfHamiltonians+8](maxtouch,1.0);

        //calculate correlation between head energy and energy at some point in chain to truncate correctly
        Bit= Reptile->begin();

        ObsEvals+=1.0;
        RealType Opf=1.0/ObsEvals;
        for(int j=0; Bit != (Reptile->end()); Bit++,j++) {
            ObsCont[j]+=(*Bit)->getPropertyBase(i)[LOCALENERGY];
            ObsContAvg[j]=ObsCont[j]*Opf;
            ObsCont2[j]+=(*Bit)->getPropertyBase(i)[LOCALPOTENTIAL];
            ObsContAvg2[j]=ObsCont[j]*Opf;
        };
        int AC(-1);
        RealType tmpE=1.0;
        RealType Hac=HeadProp[LOCALENERGY]-ObsContAvg[0];

        Bit = Reptile->begin();
        Bit++;
        for(int j=1; (Bit!=(Reptile->end()))&&(tmpE>=0.0) ; Bit++,j++) {
            tmpE=Hac*( (*Bit)->getPropertyBase(i)[LOCALENERGY]-ObsContAvg[j] );
            AC+=1;
        };
        scalars[SizeOfHamiltonians+13](AC,uw);

        int AC2(-1);
        tmpE= -1.0;
        Bit = Reptile->begin();
        if (Hac*((*Bit)->getPropertyBase(i)[LOCALPOTENTIAL]-ObsContAvg2[0]) >0) tmpE=1.0;
        Bit++;
        for(int j=1; (Bit!=(Reptile->end()))&&(tmpE>=0.0) ; Bit++,j++)
        {
            tmpE=Hac*( (*Bit)->getPropertyBase(i)[LOCALPOTENTIAL]-ObsContAvg2[j] );
            AC2+=1;
        }

        scalars[SizeOfHamiltonians+14](AC2,uw);
        scalars[SizeOfHamiltonians+15](CenProp[Findex+FirstHamiltonian],uw);
        scalars[SizeOfHamiltonians+16](CenProp[Findex+1+FirstHamiltonian],uw);
    }
}
void HFDHE2PolymerEstimator::accumulate(const MCWalkerConfiguration& W
                                        , WalkerIterator first, WalkerIterator last, RealType wgt)
{
  for(int i=0; i<NumCopies; i++)
  {
    RealType uw(Reptile->UmbrellaWeight[i]);
    //Adding all parts from the Hamiltonian
    RealType* restrict HeadProp(Reptile->front()->getPropertyBase(i));
    RealType* restrict TailProp(Reptile->back()->getPropertyBase(i));
    RealType eloc = 0.5*( HeadProp[LOCALENERGY] + TailProp[LOCALENERGY]);
    scalars[0](eloc,uw);
    for(int obsi=0; obsi<SizeOfHamiltonians ; obsi++)
    {
      scalars[obsi+1]( 0.5*( HeadProp[obsi+FirstHamiltonian] + TailProp[obsi+FirstHamiltonian]) , uw);
    };
    //Center Pressure
    RealType* restrict CenProp(Reptile->center()->getPropertyBase(i));
    scalars[SizeOfHamiltonians+5]( (2.0*eloc-2.0*CenProp[LOCALPOTENTIAL])*pNorm + CenProp[Pindex+1+FirstHamiltonian] ,uw);
    int Rage(Reptile->Age);
    int Bage=Rage;
    RealType tmpV=0.0;
    RealType tmpF=0.0;
//       if (truncLength<0){
//         for( MultiChain::iterator Bit = Reptile->begin();Bit != (Reptile->end());Bit++){
//           tmpF+= (*Bit)->getPropertyBase(i)[Pindex+2+FirstHamiltonian];
//           tmpV+=(*Bit)->getPropertyBase(i)[LOCALPOTENTIAL];
//           Bage=min((*Bit)->stepmade,Bage);
//         };
//
//       tmpF-=0.5*Reptile->back()->getPropertyBase(i)[Pindex+2+FirstHamiltonian];
//       tmpF-=0.5*Reptile->front()->getPropertyBase(i)[Pindex+2+FirstHamiltonian];
//       tmpV-=0.5*Reptile->back()->getPropertyBase(i)[LOCALPOTENTIAL];
//       tmpV-=0.5*Reptile->front()->getPropertyBase(i)[LOCALPOTENTIAL];
//       tmpV *= -2.0*pNorm*Tau;
//       tmpF *= Tau;
//
//       scalars[SizeOfHamiltonians+1](tmpV+tmpF,uw);
//       scalars[SizeOfHamiltonians+2](eloc*(tmpV+tmpF),uw);
//       scalars[SizeOfHamiltonians+3](tmpV+tmpF,uw);
//       scalars[SizeOfHamiltonians+4](eloc*(tmpV+tmpF),uw);
//       } else {
    int maxtouch=0;
    MultiChain::iterator Bit = Reptile->begin();
    MultiChain::iterator Lit = Reptile->end();
    MultiChain::iterator Endit = Reptile->end();
    Endit--;
    //truncated version of estimator
    Lit--;
    for(int j=0 ; ( (j<truncLength) && (Bit != Endit) ); Bit++,Lit--,j++)
    {
      tmpF+= 0.5*(*Bit)->getPropertyBase(i)[Pindex+2+FirstHamiltonian];
      tmpV+= 0.5*(*Bit)->getPropertyBase(i)[LOCALPOTENTIAL];
      tmpF+= 0.5*(*Lit)->getPropertyBase(i)[Pindex+2+FirstHamiltonian];
      tmpV+= 0.5*(*Lit)->getPropertyBase(i)[LOCALPOTENTIAL];
      if ((*Bit)->timesTouched>maxtouch)
        maxtouch = (*Bit)->timesTouched;
      if ((*Bit)->stepmade < Bage)
        Bage = (*Bit)->stepmade;
    };
    RealType tmpval = (tmpV*(-2.0*pNorm) + tmpF)*Tau;
    scalars[SizeOfHamiltonians+3](tmpval,uw);
    scalars[SizeOfHamiltonians+4](eloc*tmpval,uw);
    //continue sum for comparison to truncated version
    for( ; Bit != Endit; Bit++,Lit--)
    {
      tmpF+= 0.5*(*Bit)->getPropertyBase(i)[Pindex+2+FirstHamiltonian];
      tmpV+= 0.5*(*Bit)->getPropertyBase(i)[LOCALPOTENTIAL];
      tmpF+= 0.5*(*Lit)->getPropertyBase(i)[Pindex+2+FirstHamiltonian];
      tmpV+= 0.5*(*Lit)->getPropertyBase(i)[LOCALPOTENTIAL];
      if ((*Bit)->timesTouched>maxtouch)
        maxtouch = (*Bit)->timesTouched;
      if ((*Bit)->stepmade < Bage)
        Bage = (*Bit)->stepmade;
    };
    tmpV *= -2.0*pNorm*Tau;
    tmpF *= Tau;
    scalars[SizeOfHamiltonians+1](tmpV+tmpF,uw);
    scalars[SizeOfHamiltonians+2](eloc*(tmpV+tmpF),uw);
    scalars[SizeOfHamiltonians+6](Rage-Bage,1.0);
    scalars[SizeOfHamiltonians+7](maxtouch,1.0);
    scalars[SizeOfHamiltonians+8](CenProp[LOCALPOTENTIAL] ,uw);
    //calculate correlation between head energy and energy at some point in chain to truncate correctly
    Bit= Reptile->begin();
    ObsEvals+=1.0;
    RealType Opf=1.0/ObsEvals;
    for(int j=0; Bit != (Reptile->end()); Bit++,j++)
    {
      ObsCont[j]+=(*Bit)->getPropertyBase(i)[LOCALENERGY];
      ObsContAvg[j]=ObsCont[j]*Opf;
      ObsCont2[j]+=(*Bit)->getPropertyBase(i)[LOCALPOTENTIAL];
      ObsContAvg2[j]=ObsCont[j]*Opf;
    };
    int AC(-1);
    RealType tmpE=1.0;
    RealType Hac=HeadProp[LOCALENERGY]-ObsContAvg[0];
    Bit = Reptile->begin();
    Bit++;
    for(int j=1; (Bit!=(Reptile->end()))&&(tmpE>=0.0) ; Bit++,j++)
    {
      tmpE=Hac*( (*Bit)->getPropertyBase(i)[LOCALENERGY]-ObsContAvg[j] );
      AC+=1;
    };
    scalars[SizeOfHamiltonians+9](AC,uw);
    int AC2(-1);
    tmpE= -1.0;
    Bit = Reptile->begin();
    if (Hac*((*Bit)->getPropertyBase(i)[LOCALPOTENTIAL]-ObsContAvg2[0]) >0)
      tmpE=1.0;
    Bit++;
    for(int j=1; (Bit!=(Reptile->end()))&&(tmpE>=0.0) ; Bit++,j++)
    {
      tmpE=Hac*( (*Bit)->getPropertyBase(i)[LOCALPOTENTIAL]-ObsContAvg2[j] );
      AC2+=1;
    };
    scalars[SizeOfHamiltonians+10](AC2,uw);
  }
}