コード例 #1
0
def dimensionality_reduction(data_matrix,
                             image_ids,
                             args,
                             label=None,
                             viz=False):
    if args.lsa_model == "SVD":
        reduced_data = reduce_dimensions_svd(data_matrix, args.k_features,
                                             image_ids, viz)
    elif args.lsa_model == "PCA":
        reduced_data = reduce_dimensions_pca(data_matrix, args.k_features,
                                             image_ids, viz)
    elif args.lsa_model == "NMF":
        if args.model == "CM":
            print("NMF is not applicable to Color Moments")
            return
        reduced_data = reduce_dimensions_nmf(data_matrix, args.k_features,
                                             image_ids, viz)
    elif args.lsa_model == "LDA":
        if args.model == "CM":
            print("LDA is applicable only to a modified Color Moments.")
            data_matrix_cmlda = convert_data_matrix_cmlda(data_matrix)
            reduced_data = reduce_dimensions_lda(data_matrix_cmlda,
                                                 args.k_features, image_ids,
                                                 viz)
        else:
            reduced_data = reduce_dimensions_lda(data_matrix, args.k_features,
                                                 image_ids, viz)

    insert_reduced_features(args.model, reduced_data, image_ids, label)
    return reduced_data, image_ids
コード例 #2
0
def ex_dimensionality_reduction(data_matrix,
                                image_ids,
                                model,
                                lsa_model,
                                k_features,
                                label=None,
                                viz=False):
    if lsa_model == "SVD":
        reduced_data = reduce_dimensions_svd(data_matrix, k_features, viz)
    elif lsa_model == "PCA":
        reduced_data = reduce_dimensions_pca(data_matrix, k_features, viz)
    elif lsa_model == "NMF":
        if model == "CM":
            print("NMF is not applicable to Color Moments")
            return
        reduced_data = reduce_dimensions_nmf(data_matrix, k_features, viz)
    elif lsa_model == "LDA":
        if model == "CM":
            print("LDA is modified and applicable to Color Moments")
            data_matrix_cmlda = convert_data_matrix_cmlda(data_matrix)
            reduced_data = reduce_dimensions_lda(data_matrix_cmlda, k_features,
                                                 viz)
        else:
            reduced_data = reduce_dimensions_lda(data_matrix, k_features, viz)

    insert_reduced_features(model, reduced_data, image_ids, label)
    if extra_credit:
        return reduced_data, image_ids
コード例 #3
0
def get_V_matrix(data_matrix, image_ids, args, label=None, viz=False):
    if args.lsa_model == "SVD":
        reduced_data, V_matrix = reduce_dimensions_svd(data_matrix,
                                                       args.k_features,
                                                       get_v=True)
    elif args.lsa_model == "PCA":
        reduced_data, V_matrix = reduce_dimensions_pca(data_matrix,
                                                       args.k_features,
                                                       get_v=True)
    elif args.lsa_model == "NMF":
        if args.model == "CM":
            print("NMF is not applicable to Color Moments")
            return
        reduced_data, V_matrix = reduce_dimensions_nmf(data_matrix,
                                                       args.k_features,
                                                       get_v=True)
    elif args.lsa_model == "LDA":
        if args.model == "CM":
            print("LDA is NOT applicable because of the Bag Of Word model.")
            # data_matrix_cmlda = convert_data_matrix_cmlda(data_matrix)
            # V_matrix = reduce_dimensions_lda(data_matrix_cmlda, args.k_features, image_ids, viz, get_v=True)
            return
        else:
            reduced_data, V_matrix = reduce_dimensions_lda(data_matrix,
                                                           args.k_features,
                                                           get_v=True)

    # insert_reduced_features(args.model, reduced_data, image_ids, label)
    return reduced_data, V_matrix