Exemple #1
0
void origNISim::initialize() {
    mat W_t(maxVertexId, maxVertexId, fill::zeros);
    for (int i = 0; i < maxVertexId; i++) {
        int e = origGraphSrc[i + 1], s = origGraphSrc[i];
        for (int j = s; j < e; j++) {
            W_t(i, origGraphDst[j]) = 1.0;
        }
    }
    double sumRow;
    double Degr = 0;
    for (int i = 0; i < maxVertexId; i++) {
        sumRow = 0;
        for (int j = 0; j < maxVertexId; j++)
            sumRow += W_t(i, j);
        if (sumRow == 0.0) {
            printf("node %d has no ingoing edges\n", i);
        } else {
            for (int j = 0; j < maxVertexId; j++)
                W_t(i, j) = W_t(i, j) / sumRow;
        }
        Degr += sumRow;
    }
    //start svd
    Mat<double> U;
    Col<double> s;
    Mat<double> V_t;
    svd(U, s, V_t, W_t);
    mat V = V_t.t();

    U = U.submat(0, 0, maxVertexId - 1, Rank - 1);
    V = V.submat(0, 0, Rank - 1, maxVertexId - 1);
    s = s.submat(0, 0, Rank - 1, 0);
    Ku = kron(U, U);//kronecker roduct
    mat sigma = kron(s, s);//one column
    mat K_sigma = diagmat(sigma);
    Kv = kron(V, V);

    mat K_vu = Kv * Ku;

    mat I(maxVertexId, maxVertexId);
    I.eye();
    A = inv(inv(K_sigma) - decayFactor * K_vu);
    V_r = Kv * vectorise(I);

    A.save(Apath);
    V_r.save(V_rpath);
    Kv.save(Kvpath);
    Ku.save(Kupath);
}
//*****************************************************************************
void CLevelSelectDialogWidget::PopulateLevelList()
//Populate list box with all active levels.
//List can be toggled between levels in this hold and all levels.
{
//!!
#ifdef AFTERVERSION1_6
	const bool bShowAllLevels = DYN_CAST(COptionButtonWidget*, CWidget*, 
         GetWidget(TAG_ALL_LEVELS_OPTIONBOX))->IsChecked();
#else
   const bool bShowAllLevels = false;
#endif

	this->pLevelListBoxWidget->Clear();

	BEGIN_DBREFCOUNT_CHECK;
	{
		//Default choice.
		this->pLevelListBoxWidget->AddItem(0L, g_pTheDB->GetMessageText(MID_DefaultExit));

		CDbHold *pHold;
		CDbLevel *pLevel;
		if (bShowAllLevels)
		{
			//Get all levels in DB.  Sort by hold.
         CDb db;
			pHold = db.Holds.GetFirst();
			while (pHold)
			{
            //Allow selecting levels from hold only if player has access rights.
            if (db.Holds.PlayerCanEditHold(pHold->dwHoldID))
            {
				   static const WCHAR wszHoldSep[] = {W_t(' '),W_t(':'),W_t(' '),W_t(0)};
				   WSTRING wHoldName = (WSTRING)pHold->NameText;
				   wHoldName += wszHoldSep;
				   db.Levels.FilterBy(pHold->dwHoldID);
				   pLevel = db.Levels.GetFirst();
				   while (pLevel)
				   {
					   ASSERT(pLevel->dwLevelID);

					   WSTRING wText = wHoldName;
					   wText += pLevel->NameText;
					   pLevelListBoxWidget->AddItem(pLevel->dwLevelID, wText.c_str());
					   delete pLevel;
					   pLevel = db.Levels.GetNext();
				   }
            }
				delete pHold;
				pHold = db.Holds.GetNext();
			}
		} else {
			//Get the levels in the current level's hold.
			if (!this->pSourceLevel) return;

			CDbHold *pHold = g_pTheDB->Holds.GetByID(this->pSourceLevel->dwHoldID);
			pLevel = pHold->Levels.GetFirst();
			while (pLevel)
			{
				ASSERT(pLevel->dwLevelID);
				pLevelListBoxWidget->AddItem(pLevel->dwLevelID, pLevel->NameText);
				delete pLevel;
				pLevel = pHold->Levels.GetNext();
			}
			delete pHold;
		}
	}
	END_DBREFCOUNT_CHECK;
}