def aggregate_norm_comparison(factor_df, M_matrix):
    """
    Aggregate factor information with cosine similarity matrix, which contains the
    true norm.
    """
    return factor_df.groupby(['kernel', 'factor', 'iter']).agg('sum').merge(
        M_matrix.set_index(['kernel', 'factor', 'iter']),
        left_index=True,
        right_index=True,
        suffixes=('_linear', '_factor')
    )