Example #1
0
realtype CS_AreaOrPerem (int rivOrder, realtype rivDepth, realtype rivCoeff, realtype a_pBool)
{
    realtype        rivArea, rivPerem, eq_Wid;
    switch (rivOrder)
    {
        case 1:
            rivArea = rivDepth * rivCoeff;
            rivPerem = 2.0 * rivDepth + rivCoeff;
            eq_Wid = rivCoeff;
            return returnVal (rivArea, rivPerem, eq_Wid, a_pBool);
        case 2:
            rivArea = pow (rivDepth, 2) / rivCoeff;
            rivPerem = 2.0 * rivDepth * pow (1 + pow (rivCoeff, 2), 0.5) / rivCoeff;
            eq_Wid = 2.0 * pow (rivDepth + EPS, 1 / (rivOrder - 1)) / pow (rivCoeff, 1 / (rivOrder - 1));
            return returnVal (rivArea, rivPerem, eq_Wid, a_pBool);
        case 3:
            rivArea = 4 * pow (rivDepth, 1.5) / (3 * pow (rivCoeff, 0.5));
            rivPerem = (pow (rivDepth * (1 + 4 * rivCoeff * rivDepth) / rivCoeff, 0.5)) + (log (2 * pow (rivCoeff * rivDepth, 0.5) + pow (1 + 4 * rivCoeff * rivDepth, 0.5)) / (2 * rivCoeff));
            eq_Wid = 2.0 * pow (rivDepth + EPS, 1 / (rivOrder - 1)) / pow (rivCoeff, 1 / (rivOrder - 1));
            return returnVal (rivArea, rivPerem, eq_Wid, a_pBool);
        case 4:
            rivArea = 3 * pow (rivDepth, 4.0 / 3.0) / (2 * pow (rivCoeff, 1.0 / 3.0));
            rivPerem = 2 * ((pow (rivDepth * (1 + 9 * pow (rivCoeff, 2.0 / 3.0) * rivDepth), 0.5) / 3) + (log (3 * pow (rivCoeff, 1.0 / 3.0) * pow (rivDepth, 0.5) + pow (1 + 9 * pow (rivCoeff, 2.0 / 3.0) * rivDepth, 0.5)) / (9 * pow (rivCoeff, 1.0 / 3.0))));
            eq_Wid = 2.0 * pow (rivDepth + EPS, 1 / (rivOrder - 1)) / pow (rivCoeff, 1 / (rivOrder - 1));
            return returnVal (rivArea, rivPerem, eq_Wid, a_pBool);
        default:
            printf ("\n Relevant Values entered are wrong");
            printf ("\n Depth: %lf\tCoeff: %lf\tOrder: %d\t");
            return 0;
    }
}
Example #2
0
/*****************************************************************************************
 * vector< float > K_MeansPredict::PredictKey( const int PItype, const Coord< float >& Example, const float t_val )const
 *
 * Purpose: Find the key value and PI range of point P
 * Input:
 *	PI type: use cluster based PI's(0)/use global PI(1)
 *	Example: Example to predict
 *	t_val: T-test value for global PI (cluster based PI's not supported yet)
 * Output:
 *	Lower PI bound
 *	Prediction
 *	Upper Prediction bound
 *	(yes/no) is in prediction band
 *
 * 03.08.2006	djh	Replaced _totalUpper/_totalLowerConfBound with _totalBoundStub
 *			added t_val to parameter list
 *****************************************************************************************/
 vector< float > K_MeansPredict::PredictKey( const int PItype, const Coord< float >& Example, const float& t_val )const{
   vector< float > returnVal(4);
   // Find closest mean
   float minDist;
   int closestMean=0;
   for( int i=0; i< _means.size(); i++ )
   {
     float dist = Example.EuclideanDist( _means[i] );
     if( i==0 || dist<minDist)
     {
       minDist = dist;
       closestMean = i;
     }
   }
   returnVal[0] = float( KeySupport(closestMean) );
   if( PItype == 0 ){
     returnVal[1] = KeyMean(closestMean) - _upperConfBound[closestMean];
     returnVal[2] = KeyMean(closestMean) - _errMean[closestMean];
     returnVal[3] = KeyMean(closestMean) - _lowerConfBound[closestMean];
   }
   else{
     returnVal[1] = KeyMean(closestMean) - _totalErrMean - t_val*_totalBoundStub; //_totalUpperConfBound;
     returnVal[2] = KeyMean(closestMean) - _totalErrMean;
     returnVal[3] = KeyMean(closestMean) - _totalErrMean + t_val*_totalBoundStub; //_totalLowerConfBound;
   }
   return( returnVal );
 }
Example #3
0
// -----------------------------------------------------------------------------
// CNaviScrollTimer::UpdateNaviPaneL()
// Updates the Navigation pane. Every time when this function is called
// it moves the text to the left by one character.
// -----------------------------------------------------------------------------
//  
TBool CNaviScrollTimer::UpdateNaviPaneL()
    {
    TBool returnVal( EFalse );
    // Return ETrue if text is scrolled totally to left
    if( iCount == iNaviText->Des().Length() )
        returnVal = ETrue;
    
    // NaviLabel can only be updated by creating a new navidecorator.
    if( iDecorator )
        {
        iNaviPane->Pop( iDecorator );
        delete iDecorator;
        iDecorator = NULL;
        }
    // Create new decorator    
    iDecorator = iNaviPane->CreateNavigationLabelL();
    // Push decorator object to the navigation pane's object stack.
    iNaviPane->PushL( *iDecorator );    
    // Get the control inside of decorator object as CAknNaviLabel.
    CAknNaviLabel* naviLabel = 
            static_cast<CAknNaviLabel*>( iDecorator->DecoratedControl() );
    // Finally set label text
    naviLabel->SetTextL( iNaviText->Des().Right(iCount) ); 
    
    iCount--;
    if(iCount == 0) 
        iCount = iNaviText->Des().Length();
    
    return returnVal;    
    }
Example #4
0
/*!
  Receives a message once (in the limit of the Maximum message size value), from a specific emitter.
  This message can represent an entire request or not. Several calls to this function
  might be necessary to get the entire request.
  
  \warning Requests will be received but not decoded.
  
  \sa vpNetwork::receive()
  \sa vpNetwork::receiveRequestFrom()
  \sa vpNetwork::receiveRequest()
  \sa vpNetwork::receiveRequestOnce()
  \sa vpNetwork::receiveAndDecodeRequest()
  \sa vpNetwork::receiveAndDecodeRequestFrom()
  \sa vpNetwork::receiveAndDecodeRequestOnce()
  \sa vpNetwork::receiveAndDecodeRequestOnceFrom()
  
  \param receptorEmitting : Index of the receptor emitting the message.
  
  \return The number of bytes received, -1 if an error occured.
*/
int vpNetwork::_receiveRequestOnceFrom(const unsigned int &receptorEmitting)
{
  int size = (int)receptor_list.size();
  int sizeMinusOne = (int)receptor_list.size()-1;
  if(size == 0 || receptorEmitting > (unsigned)sizeMinusOne )
  {
    if(verboseMode)
      vpTRACE( "No receptor at the specified index!" );
    return -1;
  }
  
  tv.tv_sec = tv_sec;
  tv.tv_usec = tv_usec;
  
  FD_ZERO(&readFileDescriptor);        
  
  socketMax = receptor_list[receptorEmitting].socketFileDescriptorReceptor;
  FD_SET((unsigned int)receptor_list[receptorEmitting].socketFileDescriptorReceptor,&readFileDescriptor);

  int value = select((int)socketMax+1,&readFileDescriptor,NULL,NULL,&tv);
  int numbytes = 0;
  if(value == -1){
    if(verboseMode)
      vpERROR_TRACE( "Select error" );
    return -1;
  }
  else if(value == 0){
    //Timeout
    return 0;
  }
  else{
    if(FD_ISSET((unsigned int)receptor_list[receptorEmitting].socketFileDescriptorReceptor,&readFileDescriptor)){
      char *buf = new char [max_size_message];
#ifdef UNIX
      numbytes=recv(receptor_list[receptorEmitting].socketFileDescriptorReceptor, buf, max_size_message, 0);
#else
      numbytes=recv((unsigned int)receptor_list[receptorEmitting].socketFileDescriptorReceptor, buf, (int)max_size_message, 0);
#endif
      if(numbytes <= 0)
      {
        std::cout << "Disconnected : " << inet_ntoa(receptor_list[receptorEmitting].receptorAddress.sin_addr) << std::endl;
        receptor_list.erase(receptor_list.begin()+(int)receptorEmitting);
        return numbytes;
      }
      else if(numbytes > 0){
        std::string returnVal(buf, (unsigned int)numbytes);
        currentMessageReceived.append(returnVal);
      }
      delete [] buf;
    }
  }
  
  return numbytes;
}
// ---------------------------------------------------------
// CClockTimeZoneResolver::MCCFromTzIdL
// rest of the details are commented in the header
// ---------------------------------------------------------
//
EXPORT_C TInt CClockTimeZoneResolver::MCCFromTzIdL( const CTzId& aTzId )
	{
	__PRINTS( "CClockTimeZoneResolver::MCCFromTzIdL - Entry" );
	
	TInt returnVal( KErrNotFound );
	
	if( iTzResolverImpl )
		{
		returnVal = iTzResolverImpl->MCCFromTzIdL( aTzId );
		}
	
	__PRINTS( "CClockTimeZoneResolver::MCCFromTzIdL - Exit" );

	return returnVal;
	}
// ---------------------------------------------------------
// CClockTimeZoneResolver::GetTimeZoneL
// rest of the details are commented in the header
// ---------------------------------------------------------
//
EXPORT_C TInt CClockTimeZoneResolver::GetTimeZoneL( const STimeAttributes& aTimeInfo, 
		  									   		const RMobilePhone::TMobilePhoneNetworkCountryCode& aMcc,
		  									   		TInt& aTzId )
	{
	__PRINTS( "CClockTimeZoneResolver::GetTimeZoneL - Entry" );
	
	// Get the timezone information from the implementation.
	TInt returnVal( KErrNotFound );
	
	if( iTzResolverImpl )
		{
		returnVal = iTzResolverImpl->GetTimeZoneL( aTimeInfo, aMcc, aTzId );
		}

	__PRINTS( "CClockTimeZoneResolver::GetTimeZoneL - Exit" );

	return returnVal;
	}
Example #7
0
 vector< vector< float > > K_MeansPredict::Test( const int PItype, const vector< vector< float > >& Examples ) const
 {
  cout << "# Testing:\n";
  vector< vector< float > > returnVal( Examples.size() );
  for( int i=0; i<returnVal.size(); i++ )
  {
    returnVal[i] = vector< float >( 5 );
  }
  float sum_x=0.;
  float sum_xx=0.;
  for( int i=0; i<Examples.size(); i++ )
  {
    vector< float > temp( Examples[i].size()-1 );
    for( int j=0; j< temp.size(); j++ )
    {
      temp[j] = Examples[i][j+1];
    }
    Coord< float > newCoord( temp );
    vector< float > predVal = PredictKey( PItype, newCoord );
    returnVal[i][0] = Examples[i][0];
    returnVal[i][1] = predVal[1];
    returnVal[i][2] = predVal[2];
    returnVal[i][3] = predVal[3];
    //  Here is where I could add a support requirement (e.g. if( predVal[0] > threshold)
    // Calcu
    float err = returnVal[i][2]-returnVal[i][0];
    sum_x += err;
    sum_xx += pow( err, 2 );
    if( returnVal[i][1] <= returnVal[i][0] && returnVal[i][0] <= returnVal[i][3] )
    {
      returnVal[i][4] = 1.0;
    }
    else
    {
      returnVal[i][4] = 0.0;
    }
  }
  cout << "#   Error:\n";
  cout << "#     Mean of Squared Errors (MSE) is: " <<  sum_xx/float( returnVal.size() ) << endl;
  cout << "#     Error Mean is : " << sum_x/float( returnVal.size() ) << endl;
  cout << "#     Error Variance is: " << (sum_xx-pow(sum_x/float(returnVal.size()),2))/float( returnVal.size()-1 ) << endl;
  return( returnVal );
 }
Example #8
0
/****************************************************************************************
 * vector< float > TestHelper( const vector< float >& Ex, const float& t_val ) const
 * purpose:
 *   evaluates target value of pattern
 *   Inherently uses global error variance -- to work with k fold cross validation
 * Input:
 *	Ex: vector of examples
 *	t_val: T-test value
 * Output:
 *	Lower PI bound
 *	Prediction
 *	Upper Prediction bound
 *	(yes/no) is in prediction band	
 * 
 * 02.17.2006	djh	created
 * 03.08.2006	djh	added t_val to parameter list
 *****************************************************************************************/
 vector< float > K_MeansPredict::TestHelper( const vector< float >& Ex, const float& t_val ) const{
   vector< float > returnVal( 5 );
   vector< float > temp( Ex.size()-1 );
   for( int j=0; j< temp.size(); j++ ){
      temp[j] = Ex[j+1];
   }
   Coord< float > newCoord( temp );
   // Inherent use of global error variance
   vector< float > predVal = PredictKey( 1, newCoord, t_val );
   returnVal[0] = Ex[0];
   returnVal[1] = predVal[1];
   returnVal[2] = predVal[2];
   returnVal[3] = predVal[3];
   if( returnVal[1] <= returnVal[0] && returnVal[0] <= returnVal[3] ){
      returnVal[4] = 1.0;
   }
   else {
      returnVal[4] = 0.0;
   }
   return( returnVal );
 }
Example #9
0
bool
InterposeCall(JSContext* cx, JS::HandleObject target, const JS::CallArgs& args, bool* done)
{
    *done = false;
    XPCWrappedNativeScope* scope = ObjectScope(CurrentGlobalOrNull(cx));
    MOZ_ASSERT(scope->HasInterposition());

    nsCOMPtr<nsIAddonInterposition> interp = scope->GetInterposition();

    RootedObject unwrappedTarget(cx, UncheckedUnwrap(target));
    XPCWrappedNativeScope* targetScope = ObjectScope(unwrappedTarget);
    bool hasInterpostion = targetScope->HasCallInterposition();

    if (!hasInterpostion)
        return true;

    // If there is a call interpostion, we don't want to propogate the
    // call to Base:
    *done = true; 

    JSAddonId* addonId = AddonIdOfObject(target);
    RootedValue addonIdValue(cx, StringValue(StringOfAddonId(addonId)));
    RootedValue targetValue(cx, ObjectValue(*target));
    RootedValue thisValue(cx, args.thisv());
    RootedObject argsArray(cx, ConvertArgsToArray(cx, args));
    if (!argsArray)
        return false;

    RootedValue argsVal(cx, ObjectValue(*argsArray));
    RootedValue returnVal(cx);

    nsresult rv = interp->InterposeCall(addonIdValue, targetValue,
                                        thisValue, argsVal, args.rval());
    if (NS_FAILED(rv)) {
        xpc::Throw(cx, rv);
        return false;
    }

    return true;
}
Example #10
0
	//Function gets string representation of data
	std::string Datum::ToString(std::uint32_t index)
	{
		//Sanity check index
		if (index >= mSize)
		{
			throw std::exception("Out of bounds");
		}

		std::string returnVal("");
		char temp[10]; //This is size 10 because the maximum value of an int or float has 10 digits
		std::uint32_t i, j;

		switch (mType)
		{
		case Library::Datum::UNKNOWN:
			throw std::exception("Cannot represent unknown data");
			break;
		case Library::Datum::INTEGER:
			sprintf_s(temp, "%d", Get<int>(index));
			returnVal = temp;
			break;
		case Library::Datum::FLOAT:
			sprintf_s(temp, "%f", Get<float>(index));
			returnVal = temp;
			break;
		case Library::Datum::VECTOR:
			for (i = 0; i < 4; i++)
			{
				sprintf_s(temp, "%f", mValues.v[index][i]);
				returnVal += temp;
				if (i != 3)
				{
					returnVal += ',';
				}
			}

			break;
		case Library::Datum::MATRIX:
				for (i = 0; i < 4; i++)
				{
					for (j = 0; j < 4; j++)
					{
						sprintf_s(temp, "%f", mValues.m[index][i][j]);
						returnVal += temp;
						if (j != 3)
						{
							returnVal += ',';
						}
					}
					returnVal += '\n';
				}
			break;
		case Library::Datum::STRING:
			return mValues.s[index];
			break;
		case Library::Datum::POINTER:
			throw std::exception("Cannot conovert underlying data of pointer type to string");
			break;
		default:
			break;
		}

		return returnVal;

	}
Example #11
0
/*!
  Receives a message once (in the limit of the Maximum message size value).
  This message can represent an entire request or not. Several calls to this function
  might be necessary to get the entire request.
  
  \warning Requests will be received but not decoded.
  
  \sa vpNetwork::receive()
  \sa vpNetwork::receiveRequestFrom()
  \sa vpNetwork::receiveRequest()
  \sa vpNetwork::receiveRequestOnceFrom()
  \sa vpNetwork::receiveAndDecodeRequest()
  \sa vpNetwork::receiveAndDecodeRequestFrom()
  \sa vpNetwork::receiveAndDecodeRequestOnce()
  \sa vpNetwork::receiveAndDecodeRequestOnceFrom()
  
  \return The number of bytes received, -1 if an error occured.
*/
int vpNetwork::_receiveRequestOnce()
{
  if(receptor_list.size() == 0)
  {
    if(verboseMode)
      vpTRACE( "No Receptor!" );
    return -1;
  }
  
  tv.tv_sec = tv_sec;
  tv.tv_usec = tv_usec;
  
  FD_ZERO(&readFileDescriptor);        
  
  for(unsigned int i=0; i<receptor_list.size(); i++){ 
    if(i == 0)
      socketMax = receptor_list[i].socketFileDescriptorReceptor;
    
    FD_SET((unsigned)receptor_list[i].socketFileDescriptorReceptor,&readFileDescriptor); 
    if(socketMax < receptor_list[i].socketFileDescriptorReceptor) socketMax = receptor_list[i].socketFileDescriptorReceptor; 
  }

  int value = select((int)socketMax+1,&readFileDescriptor,NULL,NULL,&tv);
  int numbytes = 0;
  
  if(value == -1){
    if(verboseMode)
      vpERROR_TRACE( "Select error" );
    return -1;
  }
  else if(value == 0){
    //Timeout
    return 0;
  }
  else{
    for(unsigned int i=0; i<receptor_list.size(); i++){
      if(FD_ISSET((unsigned int)receptor_list[i].socketFileDescriptorReceptor,&readFileDescriptor)){
        char *buf = new char [max_size_message];
#ifdef UNIX
        numbytes=recv(receptor_list[i].socketFileDescriptorReceptor, buf, max_size_message, 0);
#else
        numbytes=recv((unsigned int)receptor_list[i].socketFileDescriptorReceptor, buf, (int)max_size_message, 0);
#endif
        
        
        if(numbytes <= 0)
        {
          std::cout << "Disconnected : " << inet_ntoa(receptor_list[i].receptorAddress.sin_addr) << std::endl;
          receptor_list.erase(receptor_list.begin()+(int)i);
          return numbytes;
        }
        else if(numbytes > 0){
          std::string returnVal(buf, (unsigned int)numbytes);
          currentMessageReceived.append(returnVal);
        }
        delete [] buf;
        break;
      }
    }
  }
  
  return numbytes;
}