public static IMatrix regularizedLaplacianMatrix(IMatrix m) { IMatrix tmp = MatrixOp.prod(m, MatrixOp.transpose(m)); int size = tmp.nCols(); IMatrix i = diagonal(1, size); IMatrix d = diagonal(rowSums(tmp)); IMatrix laplacian = new GuavaMatrix(); for (int ii = 0; ii < size; ii++) for (int ji = 0; ji < size; ji++) laplacian.set( ii, ji, (d.get(ii, ji) - tmp.get(ii, ji)) / Math.sqrt(d.get(ii, ii) * d.get(ji, ji))); return laplacian; }
public static double[] stationaryDistribution(IMatrix m) { int times = 6; IMatrix tmp = m; for (int i = 0; i < times; i++) tmp = MatrixOp.prod(tmp, m); return rowSums(tmp); /* Matrix tmp = MatrixFactory.toMatrix(m); int N = tmp.getColumnDimension(); Matrix B = tmp.minus(Matrix.identity(N, N)); for (int j = 0; j < N; j++) B.set(0, j, 1.0); Matrix b = new Matrix(N, 1); b.set(0, 0, 1.0); return MatrixFactory.toGMatrix(B.solve(b)); */ }