// high-level method for setting the specified pin as an input with the specified input state.
// An inputState value of 0 will cause the pin to be a high-impedance input; a value of 1 will enable the
// pin's internal pull-up resistor, which weakly pulls it to Vcc.  A value of 0xFF (255) will toggle the
// input state.
inline void setDigitalInput(uint8_t pin, uint8_t inputState)
{
	struct IOStructure registers;
	getIORegisters(&registers, pin);
	setDataDirection(&registers, 0);
	setOutputValue(&registers, inputState);
}
Beispiel #2
0
void Mean::finish(){
  setOutputValue( getFinalValue(0) / getFinalValue(1) ); 
  double denom=getFinalValue(1);
  std::vector<double> df(2); 
  df[0] = 1.0 / denom; 
  if(diffweight) df[1] = -getFinalValue(0) / (denom*denom); 
  else df[1]=0.0;
  mergeFinalDerivatives( df );
}
Beispiel #3
0
void DHEnergy::finish(){
  setOutputValue( getFinalValue(0) ); 
  df[0]=1.0; df[1]=0.0;
  mergeFinalDerivatives( df );
}
Beispiel #4
0
void ZpathVessel::finish(){
  double sum = getFinalValue(0); std::vector<double> df(2);
  setOutputValue( -invlambda*std::log( sum ) );
  df[0] = -invlambda / sum; df[1] = 0.0;
  mergeFinalDerivatives( df );
}
Beispiel #5
0
void Max::finish(){
  double valin=getFinalValue(0); double dist=beta*std::log( valin );
  setOutputValue( dist ); df[0]=beta/valin; df[1]=0.0;  
  mergeFinalDerivatives( df );
}
void GradientVessel::finish(){
  der_interm=0;  // Clear all interim derivatives
  unsigned nder = getAction()->getNumberOfDerivatives();

  if( isdens ){
      for(unsigned iw=0;iw<nweights;++iw){
          val_interm[iw] = getFinalValue( 2*iw );
          if( getAction()->derivativesAreRequired() ){
              unsigned wstart = 2*iw*(nder+1) + 1;
              for(unsigned jder=0;jder<nder;++jder) der_interm( iw, jder ) += getBufferElement( wstart + jder );
          }
      }
  } else {
      for(unsigned iw=0;iw<nweights;++iw){
          unsigned xx = (ncomponents+1)*iw;
          double sum=0, ww=getFinalValue( xx );
          for(unsigned jc=0;jc<ncomponents;++jc) val_interm[ iw*ncomponents + jc ] = getFinalValue( xx + 1 + jc ) / ww;
          if( getAction()->derivativesAreRequired() ){
              unsigned wstart = xx*(nder+1) + 1;
              for(unsigned jc=0;jc<ncomponents;++jc){
                  unsigned bstart = ( xx + 1 + jc )*(nder+1) + 1;
                  double val = getFinalValue( xx + 1 + jc );
                  for(unsigned jder=0;jder<nder;++jder) 
                     der_interm( iw*ncomponents + jc, jder ) = (1.0/ww)*getBufferElement( bstart + jder ) - (val/(ww*ww))*getBufferElement( wstart + jder );
              }
          }
      }
  }

  double tmp, diff2=0.0; 

  if( getAction()->derivativesAreRequired() ){
     for(unsigned j=0;j<starts.size()-1;++j){
        for(unsigned bin=starts[j];bin<starts[j+1];++bin){
           for(unsigned jc=0;jc<ncomponents;++jc){
               if( bin==starts[j] ){
                  tmp=val_interm[(starts[j+1]-1)*ncomponents + jc] - val_interm[bin*ncomponents + jc];
                  for(unsigned jder=0;jder<nder;++jder){
                      addDerivativeToFinalValue( jder, +2.0*tmp*der_interm( (starts[j+1]-1)*ncomponents + jc, jder) );
                      addDerivativeToFinalValue( jder, -2.0*tmp*der_interm( bin*ncomponents + jc, jder ) );
                  }
               } else {
                  tmp=val_interm[(bin-1)*ncomponents + jc] - val_interm[bin*ncomponents + jc];
                  for(unsigned jder=0;jder<nder;++jder){
                      addDerivativeToFinalValue( jder, +2.0*tmp*der_interm( (bin-1)*ncomponents + jc, jder) );
                      addDerivativeToFinalValue( jder, -2.0*tmp*der_interm( bin*ncomponents + jc, jder ) );
                  }
               }
               diff2+=tmp*tmp;
           }
        }
     }
  } else {
     for(unsigned j=0;j<starts.size()-1;++j){
        for(unsigned bin=starts[j];bin<starts[j+1];++bin){
           for(unsigned jc=0;jc<ncomponents;++jc){
               if( bin==starts[j] ) tmp=val_interm[(starts[j+1]-1)*ncomponents + jc] - val_interm[bin*ncomponents + jc];
               else tmp=val_interm[(bin-1)*ncomponents + jc] - val_interm[bin*ncomponents + jc];
               diff2+=tmp*tmp;
           }
        }
     }
  }
  setOutputValue( diff2 );  
}