示例#1
0
        temp_data, time_slice, train, cluster_radius = init_data(
            time_slice, train, region, cluster_radius, filter_count)

        axis_pois, axis_users, train_structure_data, poi_adjacent_list, recommends, unknow_poi_set = preprocess(
            temp_data, time_slice, train, cluster_radius, order)
        print "train_structure_data: ", train_structure_data
        print "poi_adjacent_list: ", poi_adjacent_list
        print "recommends: ", recommends
        print "unknow_poi_set: ", unknow_poi_set
        tensor = trans(train_structure_data, poi_adjacent_list, order,
                       len(axis_pois), len(axis_users), time_slice)
        # print "transition tensor: ", tensor

        U, S, D = HOSVD(numpy.array(tensor), 0.7)

        A = reconstruct(S, U)
        print "reconstruct tensor: ", A
        print frobenius_norm(tensor - A)

        avg_precision, avg_recall, avg_f1_score, availability = recommend(
            A, recommends, unknow_poi_set, time_slice, top_k, order)
        print "avg_precision, avg_recall, avg_f1_score, availability: ", avg_precision, avg_recall, avg_f1_score, availability

        # y_values1.append(sparsity(tensor))
        # y_values2.append(sparsity(A))
        y_values3.append(avg_precision)
        y_values4.append(avg_recall)
        y_values5.append(avg_f1_score)
        x_values.append(cluster_radius)
        cluster_radius += 0.05
示例#2
0
    filter_count = 30
    order = 2
    top_k = 1

    length, height, top_left = get_length_height(region)
    print "区域(长度,宽度):", length, height

    # pmpt
    temp_data, time_slice, train, cluster_radius = init_data(
        time_slice, train, region, cluster_radius, filter_count)
    axis_pois, axis_users, train_structure_data, poi_adjacent_list, recommends, unknow_poi_set = preprocess(
        temp_data, time_slice, train, cluster_radius, order)
    tensor = trans(train_structure_data, poi_adjacent_list, order,
                   len(axis_pois), len(axis_users), time_slice)
    U, S, D = HOSVD(numpy.array(tensor), 0.7)
    A = reconstruct(S, U)

    # factorized markov chain
    temp_data2, time_slice, train2 = init_data2(region, train, time_slice,
                                                filter_count)
    axis_pois2, axis_users2, train_structure_data2, recommends2, unknow_poi_set2 = preprocess2(
        temp_data2, time_slice, train2, order)
    A2 = trans2(train_structure_data2, order, len(axis_pois2), time_slice, 0.7)

    # tensor factorization
    temp_data3, time_slice, train3 = init_data3(time_slice, train, region,
                                                filter_count)
    axis_pois3, axis_users3, train_structure_data3, recommends3, unknow_poi_set3 = preprocess3(
        temp_data3, time_slice, train3, order)
    tensor3 = trans3(train_structure_data3, order, len(axis_pois3),
                     len(axis_users3), time_slice)
示例#3
0
    # region = (39.88, 40.05, 116.05, 116.26)
    region = (39.88, 40.05, 116.05, 116.26)
    cluster_radius = 1
    filter_count = 30
    order = 2
    top_k = 1

    length, height, top_left = get_length_height(region)
    print "区域(长度,宽度):", length, height

    # pmpt
    temp_data, time_slice, train, cluster_radius = init_data(time_slice, train, region, cluster_radius, filter_count)
    axis_pois, axis_users, train_structure_data, poi_adjacent_list, recommends, unknow_poi_set = preprocess(temp_data, time_slice, train, cluster_radius, order)
    tensor = trans(train_structure_data, poi_adjacent_list, order, len(axis_pois), len(axis_users), time_slice)
    U, S, D = HOSVD(numpy.array(tensor), 0.7)
    A = reconstruct(S, U)

    # factorized markov chain
    temp_data2, time_slice, train2 = init_data2(region, train, time_slice, filter_count)
    axis_pois2, axis_users2, train_structure_data2, recommends2, unknow_poi_set2 = preprocess2(temp_data2, time_slice, train2, order)
    A2 = trans2(train_structure_data2, order, len(axis_pois2), time_slice, 0.7)

    # tensor factorization
    temp_data3, time_slice, train3 = init_data3(time_slice, train, region, filter_count)
    axis_pois3, axis_users3, train_structure_data3, recommends3, unknow_poi_set3 = preprocess3(temp_data3, time_slice, train3, order)
    tensor3 = trans3(train_structure_data3, order, len(axis_pois3), len(axis_users3), time_slice)
    U3, S3, D3 = HOSVD(numpy.array(tensor3), 0.7)
    A3 = reconstruct(S3, U3)

    x_values = []
    y_values1 = []
示例#4
0
    # print frobenius_norm(tensor-A)

    # time_slice_range = (1, 2, 4, 6, 12)
    # index = 0

    x_values = []
    y_values1 = []
    y_values2 = []
    y_values3 = []
    y_values4 = []
    while step <= 4:
        res_tensor = n_step_tensor(tensor, step)

        U, S, D = HOSVD(numpy.array(res_tensor), 0.7)

        A = reconstruct(S, U)

        avg_precision, avg_recall, avg_f1_score, availability = recommend(A, recommends[step], unknow_poi_set, time_slice, top_k, order)
        print "avg_precision: ", avg_precision
        print "avg_recall: ", avg_recall
        print "avg_f1_score: ", avg_f1_score
        print "availability: ", availability

        y_values1.append(avg_precision)
        y_values2.append(avg_recall)
        y_values3.append(avg_f1_score)
        y_values4.append(availability)
        x_values.append(step)
        step += 1

    pylab.plot(x_values, y_values1, 'rs', linewidth=1, linestyle="-", label=u"准确率")