Calculate co-occurrence matrix.