Calculating co-occurrence matrix.