示例#1
0
 void update(const vectord &x)
 {
   ProbabilityDistribution* d = mProc->prediction(x);
   double mu = d->getMean();
   double sigma2 = d->getStd() * d->getStd();
   mGamma += sigma2; 
 }
示例#2
0
 double operator() (const vectord &x) 
 { 
   ProbabilityDistribution* d = mProc->prediction(x);
   double mu = d->getMean();
   double sigma2 = d->getStd() * d->getStd();
   return mu + mSqAlpha * (sqrt(sigma2+mGamma) - sqrt(mGamma));
 };
示例#3
0
CPROBDISTLIST CProbDistManager::getItemListByType(ProbTypes probType)
{
    CPROBDISTLIST vResult;
    size_t nCount = m_vProbDist.size();
    for(size_t i=0; i<nCount; i++)
    {
        ProbabilityDistribution* pProb = m_vProbDist[i]->m_pProbDist;
        if(pProb->getProbabilityType() == probType)
            vResult.push_back(m_vProbDist[i]);
    }
    return vResult;
}
示例#4
0
    void DisplayProblem1D::DISPLAY()
    {
      if (status != NOT_READY)
	{
	  size_t nruns = bopt_model->getParameters()->n_iterations;
	  if ((status != STOP) && (state_ii < nruns))
	    {
	      // We are moving. Next iteration
	      ++state_ii;
	      bopt_model->stepOptimization(); 
	      const double res = bopt_model->getData()->getLastSampleY();
	      const vectord last = bopt_model->getData()->getLastSampleX();
	      ly.push_back(res);
	      lx.push_back(last(0));
	      
	      if (status == STEP) { status = STOP; }
	    }
	  
	  // We compute the prediction, true value and criteria at 1000 points
	  int n=1000;
	  std::vector<double> x,y,z,su,sl,c;
	  x = linspace(0,1,n);
	  y = x; z = x; su = x; sl = x; c = x;
	  
	  // Query functions at the 1000 points
	  vectord q(1);
	  for(size_t i=0; i<n; ++i)
	    {
	      q(0) = x[i];                                                 // Query
	      ProbabilityDistribution* pd = bopt_model->getPrediction(q);
	      y[i] = pd->getMean();                                //Expected value
	      su[i] = y[i] + 2*pd->getStd();                       //Upper bound (95 %)
	      sl[i] = y[i] - 2*pd->getStd();                       //Lower bound (95 %)
	      c[i] = -bopt_model->evaluateCriteria(q);             //Criteria value
	      z[i] = bopt_model->evaluateSample(q);                //Target function true value
	    }
 
	  //GP subplot
	  subplot(2,1,1);
	  title("Press r to run and stop, s to run a step and q to quit.");
	  plot(x,y); set(3);                            // Expected value in default color (blue)
	  plot(lx,ly);set("k");set("o");set(4);         // Data points as black star
	  plot(x,su);set("g"); set(2);                  // Uncertainty as green lines
	  plot(x,sl);set("g"); set(2);
	  plot(x,z);set("r"); set(3);                   // True function as red line
	  
	  //Criterion subplot
	  subplot(2,1,2);
	  plot(x,c); set(3);
	}
    };
示例#5
0
PGPEPolicy::PGPEPolicy(Policy const &policy_,
                       ProbabilityDistribution const &distribution_,
                       double resamplingProbability_)
    : StochasticPolicy(policy_.getDimObservation(), policy_.getDimAction()),
      policyPtr(policy_.clone()),
      distributionPtr(distribution_.clone()),
      resamplingProbability(resamplingProbability_),
      generator(456),
      randDistr(0.0, 1.0)
{
    /* Nothing to do */
}
示例#6
0
  double ConditionalBayesProcess::negativeCrossValidation()
  {
    // This is highly ineffient implementation for comparison purposes.
    Dataset data(mData);

    size_t n = data.getNSamples();
    double sum = 0.0;

    matrixd tempF(mMean.mFeatM);


    // We take the first element, use it for validation and then paste
    // it at the end. Thus, after every iteration, the first element
    // is different and, at the end, all the elements should have
    // rotated.
    for(size_t i = 0; i<n; ++i)
      {
	// Take the first element
	const double y = data.getSampleY(0);
	const vectord x = data.getSampleX(0);

	// Remove it for cross validation
	data.mX.erase(data.mX.begin()); 
	utils::erase(data.mY,data.mY.begin());
	utils::erase_column(mMean.mFeatM,0);

	// Compute the cross validation
	computeCholeskyCorrelation();
	precomputePrediction(); 
	ProbabilityDistribution* pd = prediction(x);
	sum += std::log(pd->pdf(y));

	//Paste it back at the end
	data.addSample(x,y);
	mMean.mFeatM.resize(mMean.mFeatM.size1(),mMean.mFeatM.size2()+1);  
	mMean.mFeatM = tempF;
      }
    std::cout << "End" << data.getNSamples();
    return -sum;   //Because we are minimizing.
  }
LRESULT CServiceRequirementDlg::OnMsgComboChange(WPARAM wParam, LPARAM lParam)
{
	int nComboxSel = (int)wParam;
	if (nComboxSel == LB_ERR)
		return 0;

	if (NULL == m_pServicingRequirement)
	{
		return 0;
	}


	LV_DISPINFO* pDispInfo = (LV_DISPINFO*)lParam;
	LV_ITEM* plvItem = &pDispInfo->item;

	int nItem = plvItem->iItem;
	int nSubItem = plvItem->iSubItem;
	if (nItem < 0)
		return 0;

	switch(nSubItem)
	{
	case 2:
		{
			ProbabilityDistribution* pProbDist = NULL;
			CProbDistManager* pProbDistMan = m_pInputAirside->m_pAirportDB->getProbDistMan();

			//if select the first item
			if( nComboxSel == 0 )
			{
				CProbDistEntry* pPDEntry = NULL;
				pPDEntry = (*m_pSelectProbDistEntry)(NULL, m_pInputAirside);
				if(pPDEntry == NULL)
					return 0;
				pProbDist = pPDEntry->m_pProbDist;
				assert( pProbDist );

				CString strDistName = pPDEntry->m_csName;
				//if(strDistName == m_strDistName)
				//	return;

				//m_strDistName = strDistName;
				char szBuffer[1024] = {0};
				pProbDist->screenPrint(szBuffer);
				m_pServicingRequirement->SetDistScreenPrint(szBuffer);
				m_pServicingRequirement->SetProbTypes((ProbTypes)pProbDist->getProbabilityType());
				pProbDist->printDistribution(szBuffer);
				m_pServicingRequirement->SetPrintDist(szBuffer);

				//m_strDistScreenPrint = szBuffer;
				//----------------
				//int nIndex = 0;
				//if ((nIndex=m_ComBoDistribution.FindString(nIndex, m_strDistName)) != CB_ERR)
				//	m_ComBoDistribution.SetCurSel( nIndex );	
				//else
				//{
				//	nIndex = m_ComBoDistribution.AddString(m_strDistName);
				//	m_ComBoDistribution.SetCurSel(nIndex);
				//}
				InitServiceTimeList();

				m_ListFltTypeServiceRequirement.SetItemText(plvItem->iItem, plvItem->iSubItem, strDistName);
				m_pServicingRequirement->SetServiceTime(strDistName);

			}
			else
			{
				map<int, CString>::const_iterator iter = m_ServiceTimeMap.find(nComboxSel);
				CString strServiceTime = iter->second;
				m_pServicingRequirement->SetServiceTime(strServiceTime);

				CProbDistEntry* pPDEntry = NULL;
				int nCount = pProbDistMan->getCount();
				for( int i=0; i<nCount; i++ )
				{
					pPDEntry = pProbDistMan->getItem( i );
					if( strcmp( pPDEntry->m_csName, strServiceTime ) == 0 )
						break;
				}
				//assert( i < nCount );
				pProbDist = pPDEntry->m_pProbDist;
				assert( pProbDist );
				char szBuffer[1024] = {0};
				pProbDist->screenPrint(szBuffer);
				m_pServicingRequirement->SetDistScreenPrint(szBuffer);
				m_pServicingRequirement->SetProbTypes((ProbTypes)pProbDist->getProbabilityType());
				pProbDist->printDistribution(szBuffer);
				m_pServicingRequirement->SetPrintDist(szBuffer);
			}
		}
		break;

	case 3:
		{
			ProbabilityDistribution* pProbDist = NULL;
			CProbDistManager* pProbDistMan = m_pInputAirside->m_pAirportDB->getProbDistMan();

			//if select the first item
			if( nComboxSel == 0 )
			{
				CProbDistEntry* pPDEntry = NULL;
				pPDEntry = (*m_pSelectProbDistEntry)(NULL, m_pInputAirside);
				if(pPDEntry == NULL)
					return 0;
				pProbDist = pPDEntry->m_pProbDist;
				assert( pProbDist );

				CString strDistName = pPDEntry->m_csName;
				//if(strDistName == m_strDistName)
				//	return;

				//m_strDistName = strDistName;
				char szBuffer[1024] = {0};
				pProbDist->screenPrint(szBuffer);
				m_pServicingRequirement->SetSubDistScreenPrint(szBuffer);
				m_pServicingRequirement->SetSubProbTypes((ProbTypes)pProbDist->getProbabilityType());
				pProbDist->printDistribution(szBuffer);
				m_pServicingRequirement->SetSubPrintDist(szBuffer);

				//m_strDistScreenPrint = szBuffer;
				//----------------
				//int nIndex = 0;
				//if ((nIndex=m_ComBoDistribution.FindString(nIndex, m_strDistName)) != CB_ERR)
				//	m_ComBoDistribution.SetCurSel( nIndex );	
				//else
				//{
				//	nIndex = m_ComBoDistribution.AddString(m_strDistName);
				//	m_ComBoDistribution.SetCurSel(nIndex);
				//}
				InitServiceTimeList();

				m_ListFltTypeServiceRequirement.SetItemText(plvItem->iItem, plvItem->iSubItem, strDistName);
				m_pServicingRequirement->SetSubServiceTime(strDistName);

			}
			else
			{
				map<int, CString>::const_iterator iter = m_ServiceTimeMap.find(nComboxSel);
				CString strServiceTime = iter->second;
				m_pServicingRequirement->SetSubServiceTime(strServiceTime);

				CProbDistEntry* pPDEntry = NULL;
				int nCount = pProbDistMan->getCount();
				for( int i=0; i<nCount; i++ )
				{
					pPDEntry = pProbDistMan->getItem( i );
					if( strcmp( pPDEntry->m_csName, strServiceTime ) == 0 )
						break;
				}
				//assert( i < nCount );
				pProbDist = pPDEntry->m_pProbDist;
				assert( pProbDist );
				char szBuffer[1024] = {0};
				pProbDist->screenPrint(szBuffer);
				m_pServicingRequirement->SetSubDistScreenPrint(szBuffer);
				m_pServicingRequirement->SetSubProbTypes((ProbTypes)pProbDist->getProbabilityType());
				pProbDist->printDistribution(szBuffer);
				m_pServicingRequirement->SetSubPrintDist(szBuffer);
			}
		}
		break;
	//condition
	case 4:
		{
			enumVehicleTypeCondition nConditionType = enumVehicleTypeCondition_Per100Liters;
			if (nComboxSel >= enumVehicleTypeCondition_Per100Liters && nComboxSel < enumVehicleTypeCondition_Count)
			{
				nConditionType = (enumVehicleTypeCondition)nComboxSel;
			}

			m_pServicingRequirement->SetConditionType(nConditionType);
		}
	    break;

	default:
	    break;
	}

	//InitListCtrl();
	SetListContent(false);

	GetDlgItem(IDC_BUTTON_SAVE)->EnableWindow(TRUE);

	return 0;
}
void   CDlgDepartureSlotSpec::OnSelComboBox(NMHDR*   pNMHDR,   LRESULT*   pResult)     
{     	
	
	LV_DISPINFO* dispinfo = (LV_DISPINFO * )pNMHDR;
	if(m_nColumnSel == 1)
		return;
	*pResult = 0;
	if(!dispinfo)
		return;

	if(!m_pDepSlotSpec)return;	
	DepartureSlotItem* pItem = m_pDepSlotSpec->GetItem(m_nRowSel);
	if(!pItem)return;
	// TODO: Add your control notification handler code here	 
	CString strSel;
	strSel = dispinfo->item.pszText;

	char szBuffer[1024] = {0};
	ProbabilityDistribution* pProbDist = NULL;
	CProbDistManager* pProbDistMan = m_pInputAirside->m_pAirportDB->getProbDistMan();
	if(strSel == _T("New Probability Distribution..." ) )
	{
		CProbDistEntry* pPDEntry = NULL;
		pPDEntry = (*m_pSelectProbDistEntry)(NULL, m_pInputAirside);
		if(pPDEntry == NULL)
		{
			if(m_nColumnSel == 3)
				m_wndListCtrl.SetItemText(m_nRowSel,m_nColumnSel,pItem->GetFirstSlotDelayProDisName());
			else if(m_nColumnSel == 4)
				m_wndListCtrl.SetItemText(m_nRowSel,m_nColumnSel,pItem->GetInterSlotDelayProDisName());
			return;
		}
		pProbDist = pPDEntry->m_pProbDist;
		assert( pProbDist );
		CString strDistName = pPDEntry->m_csName;

		pProbDist->printDistribution(szBuffer);
		if(m_nColumnSel == 3)//First Slot Delay
		{
			pItem->SetFirstSlotDelayProDisName(strDistName);
			pItem->SetFirstSlotDelayProDisType((ProbTypes)pProbDist->getProbabilityType());
			pItem->SetFirstSlotDelayPrintDis(szBuffer);
			m_wndListCtrl.SetItemText(m_nRowSel,m_nColumnSel,strDistName);
		}
		else if(m_nColumnSel == 4)//Inter Slot Delay
		{
			pItem->SetInterSlotDelayProDisName(strDistName); 
			pItem->SetInterSlotDelayProDisType((ProbTypes)pProbDist->getProbabilityType());
			pItem->SetInterSlotDelayPrintDis(szBuffer);
			m_wndListCtrl.SetItemText(m_nRowSel,m_nColumnSel,strDistName);
		}  	
	}
	else
	{
		//if(m_strDistName == strSel)
		//	return;
		CProbDistEntry* pPDEntry = NULL;

		int nCount = pProbDistMan->getCount();
		for( int i=0; i<nCount; i++ )
		{
			pPDEntry = pProbDistMan->getItem( i );
			if(pPDEntry->m_csName == strSel)
				break;
		}
		//assert( i < nCount );
		pProbDist = pPDEntry->m_pProbDist;
		assert( pProbDist );

		CString strDistName = pPDEntry->m_csName;	
		pProbDist->printDistribution(szBuffer);
		if(m_nColumnSel == 3)//First Slot Delay
		{
			pItem->SetFirstSlotDelayProDisName(strDistName);
			pItem->SetFirstSlotDelayProDisType((ProbTypes)pProbDist->getProbabilityType());
			pItem->SetFirstSlotDelayPrintDis(szBuffer);
			m_wndListCtrl.SetItemText(m_nRowSel,m_nColumnSel,strDistName);
		}
		else if(m_nColumnSel == 4)//Inter Slot Delay
		{
			pItem->SetInterSlotDelayProDisName(strDistName); 
			pItem->SetInterSlotDelayProDisType((ProbTypes)pProbDist->getProbabilityType());
			pItem->SetInterSlotDelayPrintDis(szBuffer);
			m_wndListCtrl.SetItemText(m_nRowSel,m_nColumnSel,strDistName);
		}  			 
	} 
}
void CDlgItinerantTraffic::GenerateItinerantFlightSchedule()
{
	int nItinerantFltID = 0;
	size_t nCount = m_pItinerantFlightList->GetElementCount();
	for (size_t i = 0; i < nCount; i++)
	{
		ItinerantFlight* pItem = m_pItinerantFlightList->GetItem( i );

		ProbabilityDistribution *pProbDist = pItem->GetArrProbDistribution();
		double dArrInteValue = pProbDist->getRandomValue() *60;

		pProbDist = pItem->GetDepProbDistribution();
		double dDepInteValue = pProbDist->getRandomValue() * 60;

		std::vector<ALTObject> vEntryObject;
		std::vector<ALTObject> vExitObject;

		ALTObjectGroup objectGroupEntry;
		objectGroupEntry.ReadData(pItem->GetEntryID());
		if(-1 != objectGroupEntry.getID() 
			&& -1 != objectGroupEntry.GetProjID() 
			&& objectGroupEntry.getType() != ALT_UNKNOWN)
			objectGroupEntry.GetObjects(vEntryObject);

		ALTObjectGroup objectGroupExit;
		objectGroupExit.ReadData(pItem->GetExitID());
		if(-1 != objectGroupExit.getID() 
			&& -1 != objectGroupExit.GetProjID() 
			&& objectGroupExit.getType() != ALT_UNKNOWN)
			objectGroupExit.GetObjects(vExitObject);
		
		int nFltCount = pItem->GetFltCount();
		for (int j = 0; j < nFltCount; j++)
		{
			nItinerantFltID++;
			ItinerantFlightScheduleItem* pNewItem = new ItinerantFlightScheduleItem;
		//	pNewItem->SetFltType( pItem->GetFltType() );
			pNewItem->setACType(pItem->GetACType());
			pNewItem->setAirline( pItem->GetName() );
			pNewItem->SetEnRoute(pItem->GetEnRoute());
			CString strTemp = _T("");
			strTemp.Format(_T("%d"),nItinerantFltID);
			if (pItem->GetEntryID() != -1)
			{
				pNewItem->setFlightID( strTemp ,'A');
			}
			if (pItem->GetExitID() != -1)
			{
				pNewItem->setFlightID(strTemp,'D');
			}
			size_t nEntrySize = vEntryObject.size();
			int nEntryID = nEntrySize > 0 ? vEntryObject[rand()%nEntrySize].getID() : pItem->GetEntryID();

			size_t nExitSize = vExitObject.size();
			int nExitID = nExitSize > 0 ? vExitObject[rand()%nExitSize].getID() : pItem->GetExitID();

			pNewItem->SetEntryID( nEntryID );
			pNewItem->SetEntryFlag( pItem->GetEntryFlag() );
			pNewItem->SetExitID( nExitID );
			pNewItem->SetExitFlag( pItem->GetExitFlag() );
			pNewItem->setOrigin(pItem->GetOrig());
			pNewItem->setDestination(pItem->GetDest());

			//Arrival time
			ElapsedTime arrTime = *pItem->GetArrStartTime() + ElapsedTime(dArrInteValue)*(long(j+1));
			if (arrTime < 0L)
				arrTime = *pItem->GetArrStartTime();

			pNewItem->setArrTime( arrTime);

			ElapsedTime depTime = *pItem->GetDepStartTime() + ElapsedTime(dDepInteValue)*(long(j+1));
			if (depTime < 0L)
			{
				depTime = *pItem->GetDepStartTime();
			}
			pNewItem->setDepTime(depTime);
			//make sure in time window
			if (pNewItem->getArrTime() > pNewItem->getDepTime() || pNewItem->getArrTime() == pNewItem->getDepTime())
			{
				pNewItem->setDepTime(pNewItem->getArrTime()+ElapsedTime(dArrInteValue)*(long(j+1)));
			}
			m_pItinerantFlightSchedule->AddNewItem( pNewItem );
		}
	}
}