示例#1
0
#!/usr/bin/env python
# coding: UTF-8
from __future__ import division
from poirank.transition import init_data, trans
import pylab

poi_axis, axis_poi, data = init_data(tuple(range(2, 30)))
#tensor = trans(data, len(axis_poi))
# print "data: ", data
data_length = len(data)
print "data_length: ", data_length


def poi_coorelation(order):
    esum = 0.0
    for i in range(data_length):
        esum = esum + data[i]
    expectation = esum / data_length
    print "expectation: ", expectation

    vsum = 0.0
    for j in range(data_length):
        vsum += pow((data[j] - expectation), 2)
    print "vsum: ", vsum
    variance = vsum / data_length

    tsum = 0.0
    for k in range(data_length - order):
        tsum += (data[k] - expectation) * (data[k + order] - expectation)
    print "tsum: ", tsum
    ar = tsum / vsum
示例#2
0
#!/usr/bin/env python
# coding: UTF-8
from __future__ import division
from poirank.transition import init_data
import pylab
import numpy as np

'''
贝叶斯信息准则
在实际中不太好操作,对于状态数很大的马尔科夫链,极大似然值小而惩罚值过大,容易过拟合,从而阶数始终为1。
'''

poi_axis, axis_poi, data = init_data((6,))
#poi_axis, axis_poi, data = init_data(tuple(range(0, 182)))
data_length = len(data)
state_num = len(axis_poi)
print "key: ", axis_poi.keys()
print "state_num: ", state_num
# tensor = []
# tensor[1] = [[0 for i in range(state_num)] for j in range(state_num)]
# tensor[2] = [[[0 for i in range(state_num)] for j in range(state_num)] for k in range(state_num)]
# tensor[3] = [[[[0 for i in range(state_num)] for j in range(state_num)] for k in range(state_num)] for l in range(state_num)]
# tensor[4] = [[[[[0 for i in range(state_num)] for j in range(state_num)] for k in range(state_num)] for l in range(state_num)] for m in range(state_num)]

def bic_1(data):
    tensor1 = [0 for i in range(state_num)]
    tensor2 = [[0 for l in range(state_num)] for m in range(state_num)]
    for index in range(0, data_length-1):
        check_list = data[index:index+1]
        check_list_plus_one = data[index:index+2]
        # print check_list, check_list_plus_one
示例#3
0
#!/usr/bin/env python
# coding: UTF-8
from __future__ import division
import math
import numpy as np
from poirank.transition import init_data, trans
import pylab
from numpy import *

# 以紫荆园为中心
z_latitude = 40.010428
z_longtitude = 116.322341


poi_axis, axis_poi, data = init_data(tuple(range(0, 182)), return_gps=True)
data_length = len(data)
print "data_length: ", data_length
#print data


# 计算两个经纬度之间的距离,单位千米
def calculate_distance(lat1, lng1, lat2, lng2):
    earth_radius = 6378.137
    rad_lat1 = rad(lat1)
    rad_lat2 = rad(lat2)
    a = rad_lat1 - rad_lat2
    b = rad(lng1) - rad(lng2)
    s = 2 * math.asin(
        math.sqrt(math.pow(math.sin(a / 2), 2) + math.cos(rad_lat1) * math.cos(rad_lat2) * math.pow(math.sin(b / 2), 2)))
    s *= earth_radius
    if s < 0:
示例#4
0
        meta_data = (index, x[index])
        sort_data.append(meta_data)
    sort_data.sort(key=lambda x: x[1], reverse=True)
    res = []
    for i in range(0, len(sort_data)):
        res.append(
            (i + 1, axis_poi[axis_poi2[sort_data[i][0]]], sort_data[i][1]))

    return res


if __name__ == '__main__':
    i_distance = 2
    current_position = (116.361684, 39.951409)  # poi为1231
    poi_axis, axis_poi, data, name2type = init_data(
        tuple(range(0,
                    182)), return_gps=True, return_poi_type=True)  # (0, 182)
    print "当前位置: ", axis_poi[1231]
    print "name2type: ", name2type
    count_list = []
    count_set = set()

    for i in range(0, len(data)):
        distance = calculate_distance(data[i][2], data[i][1],
                                      current_position[1], current_position[0])
        if distance <= i_distance:
            count_list.append(data[i])
            count_set.add(data[i][0])

    print "count_list: ", len(count_list)
    print count_set
示例#5
0
    sort_data = []
    for index in range(0, len(x)):
        meta_data = (index, x[index])
        sort_data.append(meta_data)
    sort_data.sort(key=lambda x: x[1], reverse=True)
    res = []
    for i in range(0, len(sort_data)):
        res.append((i+1, axis_poi[axis_poi2[sort_data[i][0]]], sort_data[i][1]))

    return res


if __name__ == '__main__':
    i_distance = 2
    current_position = (116.361684, 39.951409)  # poi为1231
    poi_axis, axis_poi, data, name2type = init_data(tuple(range(0, 182)), return_gps=True, return_poi_type=True)   # (0, 182)
    print "当前位置: ", axis_poi[1231]
    print "name2type: ", name2type
    count_list = []
    count_set = set()

    for i in range(0, len(data)):
        distance = calculate_distance(data[i][2], data[i][1], current_position[1], current_position[0])
        if distance <= i_distance:
            count_list.append(data[i])
            count_set.add(data[i][0])

    print "count_list: ", len(count_list)
    print count_set
    print len(count_set)
    dimensionality = len(count_set)
示例#6
0
#!/usr/bin/env python
# coding: UTF-8
from __future__ import division
from poirank.transition import init_data
import pylab
import numpy as np
'''
贝叶斯信息准则
在实际中不太好操作,对于状态数很大的马尔科夫链,极大似然值小而惩罚值过大,容易过拟合,从而阶数始终为1。
'''

poi_axis, axis_poi, data = init_data((6, ))
#poi_axis, axis_poi, data = init_data(tuple(range(0, 182)))
data_length = len(data)
state_num = len(axis_poi)
print "key: ", axis_poi.keys()
print "state_num: ", state_num
# tensor = []
# tensor[1] = [[0 for i in range(state_num)] for j in range(state_num)]
# tensor[2] = [[[0 for i in range(state_num)] for j in range(state_num)] for k in range(state_num)]
# tensor[3] = [[[[0 for i in range(state_num)] for j in range(state_num)] for k in range(state_num)] for l in range(state_num)]
# tensor[4] = [[[[[0 for i in range(state_num)] for j in range(state_num)] for k in range(state_num)] for l in range(state_num)] for m in range(state_num)]


def bic_1(data):
    tensor1 = [0 for i in range(state_num)]
    tensor2 = [[0 for l in range(state_num)] for m in range(state_num)]
    for index in range(0, data_length - 1):
        check_list = data[index:index + 1]
        check_list_plus_one = data[index:index + 2]
        # print check_list, check_list_plus_one
#!/usr/bin/env python
# coding: UTF-8
from __future__ import division
from poirank.transition import init_data, trans
import pylab

poi_axis, axis_poi, data = init_data(tuple(range(2,30)))
#tensor = trans(data, len(axis_poi))
# print "data: ", data
data_length = len(data)
print "data_length: ", data_length


def poi_coorelation(order):
    esum = 0.0
    for i in range(data_length):
        esum = esum + data[i]
    expectation = esum / data_length
    print "expectation: ", expectation

    vsum = 0.0
    for j in range(data_length):
        vsum += pow((data[j] - expectation), 2)
    print "vsum: ", vsum
    variance = vsum / data_length

    tsum = 0.0
    for k in range(data_length - order):
        tsum += (data[k] - expectation) * (data[k + order] - expectation)
    print "tsum: ", tsum
    ar = tsum / vsum
示例#8
0
    x_values = []
    while (block_width < 3):
        block_num = int(30 // block_width)
        block_matrix = [[
            i + 1 for i in range(j * block_num, (j + 1) * block_num)
        ] for j in range(0, block_num)]
        block_transition = [[0 for i in range(0, block_num * block_num)]
                            for j in range(0, block_num * block_num)]
        print block_matrix
        print block_transition

        block_array_list = {}
        for i in range(1, block_num * block_num + 1):
            block_array_list[i] = []

        poi_axis, axis_poi, data = init_data(tuple(range(0, 182)),
                                             return_gps=True)  # (0, 182)
        max_latitude = 0
        min_latitude = data[0][2]
        max_longtitude = 0
        min_longtitude = data[0][1]

        for i in range(len(data)):
            if data[i][2] > max_latitude:
                max_latitude = data[i][2]
            if data[i][2] < min_latitude:
                min_latitude = data[i][2]
            if data[i][1] > max_longtitude:
                max_longtitude = data[i][1]
            if data[i][1] < min_longtitude:
                min_longtitude = data[i][1]