コード例 #1
0
void addMatrixRow(MatDoub U, int row, MatDoub &out) {

    int dummy = -1000;

    for(int i=0; i<out.nrows(); i++) {
        out[i][row] = dummy;
        out[row][i] = dummy;
    }

    datain   = U.getMatrixArray();
    datainO  = out.getMatrixArray();
    int k            = 0;

    data     [out.nrows()*out.nrows()];

    for(int i=0; i < out.nrows()*out.ncols(); i++) {

        if( datainO[i] == dummy )
            data[i] = 0;
        else
            data[i] = datain[k++];

    }

    out = MatDoub( out.nrows(), out.nrows(), data );

}
コード例 #2
0
ファイル: eigsym.cpp プロジェクト: LijieTu/hfcxx
void Eigsym::eig(const MatDoub &A, MatDoub &V, VecDoub &lambda) {
	unsigned int n = A.ncols();	/* size of the matrix */
	double a[n*n]; 	/* store initial matrix */
	double w[n];		/* store eigenvalues */
	int matz = 1;		/* return both eigenvalues as well as eigenvectors */
	double x[n*n]; 	/* store eigenvectors */

	for(unsigned int i=0; i<n; i++) {
		for(unsigned int j=0; j<n; j++) {
			a[i*n+j] = A[i][j];
		}
	}

	unsigned int ierr = 0;

	ierr = rs ( n, a, w, matz, x );

	V.assign(n,n,0.0);
	lambda.resize(n);
	for(unsigned int i=0; i<n; i++) {
		lambda[i] = w[i];
		for(unsigned int j=0; j<n; j++) {
			V[j][i] = x[i*n+j];
		}
	}
}
コード例 #3
0
ファイル: zmat_nr3.cpp プロジェクト: zsimpson/zbslib
void dump_nrmat( MatDoub &m ) {
	for( int r=0; r<m.nrows(); r++ ) {
		for( int c=0; c<m.ncols(); c++ ) {
			printf( "%+3.2le ", m[r][c] );
		}
		printf( "\n" );
	}	
}
コード例 #4
0
/*
 Calculte the Modularity matrix when split
 into more than two communities, see [2]
 in method declarations above.
 */
void calculateB(MatDoub B, MatDoub &Bg) {

    int Ng = B.ncols();

    if( Bg.ncols() != Ng )
        Bg.resize(Ng,Ng);

    for(int i=0; i<Ng; i++) {
        for(int j=0; j<Ng; j++) {
            double sum = 0.0;
            for(int k=0; k<Ng; k++)
                sum += B[i][k];

            Bg[i][j] = B[i][j] -1.0 * delta(i,j) * sum;
        }
    }

}
コード例 #5
0
ファイル: zmat_nr3.cpp プロジェクト: zsimpson/zbslib
void copyNRMatToZMat( MatDoub &m, ZMat &z ) {
	// account for NR3 is rowmajor, ZMat is colmajor.
	int rows = m.nrows();
	int cols = m.ncols();
	if( z.rows != rows || z.cols != cols ) {
		z.alloc( rows, cols, zmatF64 );
	}
	for( int r=0; r<rows; r++ ) {
		for( int c=0; c<cols; c++ ) {
			z.putD( r, c, m[r][c] );
		}
	}
}
コード例 #6
0
/*
 Calculate the eigenvalues, betai, and eigenvectors, u, for
 the current Modularity matrix Bgi.
 */
void calculateEigenVectors() {

    int Ng = Bgi.ncols();

    if(u.ncols() != Ng) {
        u.resize(Ng,Ng);
        betai.resize(Ng);
    }

    u.resize(Ng,Ng);
    betai.resize(Ng);

    Symmeig h(Bgi, true);

    for(int i=0; i<Ng; i++) {
        betai[i] = h.d[i];
        for(int j=0; j<Ng; j++) {
            u[j][i] = h.z[j][i];
        }
    }


}
コード例 #7
0
void removeMatrixRow( MatDoub &out ) {

    int dummy = -1000;

    datain = Ri.getMatrixArray();
    data  [Ri.nrows()*Ri.nrows()];
    int k=0;

    for(int i=0; i < Ri.nrows()*Ri.ncols(); i++) {

        double ele = datain[i];
        if(ele != dummy)
            data[k++] = ele;

    }

    out = MatDoub( out.nrows(), out.nrows(), data );


}
コード例 #8
0
/*
 Find the leading eigenvector, i.e.
 the one which corresponds to the most positive
 eigenvalue.
 */
void findLeadingEigenVectors(int &ind) {


    int Ng = Bgi.ncols();

    int ind_max = 0;
    int ind_min = 0;

    double max  = betai[ind_max];
    double min  = betai[ind_min];

    for(int i=0; i<Ng-1; i++) {
        if( betai[i] > max ) {
            max     = betai[i];
            ind_max = i;
        }
    }

    ind = ind_max;

}
コード例 #9
0
/*
 Utility method used by RandomWalk algorithm to
 resize the Graph Laplacian for each community, com,
 within the network.
 */
void getSubMatrix(int com, vector<node> &Nodes) {

    int dummy = -1000;
    int rows  = 0;

    Rh.resize(R.nrows(), R.nrows());
    Rh = R;

    //--- NR style
    for( int i=0; i< C.size(); i++) {

        if( C[i] == com )
            Nodes.push_back(node(rows++,0.0,0.0));
        else {
            for( int k=0; k<Rh.nrows(); k++) {
                Rh[i][k] = dummy;
                Rh[k][i] = dummy;
            }
        }

    }

    datain = Rh.getMatrixArray();
    data   [Rh.nrows()*Rh.nrows()];
    int ind = 0;

    for(int i=0; i < Rh.nrows()*Rh.ncols(); i++) {

        double ele = datain[i];
        if(ele != dummy)
            data[ind++] = ele;

    }

    Ri.resize(rows,rows);
    Ri = MatDoub( rows, rows, data );

}
コード例 #10
0
/*
 Update the index vectors, si and SI, for each node in the
 current split such that:

 si(i) =  1 if eigenvector_max(i) > 0
       = -1 if eigenvector_max(i) < 0

 SI(i,0) = 1
 SI(i,1) = 0 if eigenvector_max(i) > 0
         = 0
         = 1 if eigenvector_max(i) < 0
 */
void maximiseIndexVectors( int ind ) {

    int Ng = u.ncols();

    si.resize(Ng);

    SI.resize(Ng,2);

    for(int i=0; i<Ng; i++) {

        if(u[i][ind] < 0) {
            si[i]    = -1;
            SI[i][0] =  0;
            SI[i][1] =  1;
        } else {
            si[i]    =  1;
            SI[i][0] =  1;
            SI[i][1] =  0;
        }

    }

}