示例#1
0
            v = walk
        walks.append(walk_sequence)
    return walks


c = get_config()
# init region
region_grid = RegionGrid(config=c)


def e_distance(d):
    import math
    return math.exp(-d * 1.5)


distance_matrix = region_grid.get_distance_mtx(transform=e_distance)

W, t = region_grid.create_flow_matrix(c['raw_flow_file'],
                                      region_name=c['city_name'],
                                      time=8)

size = region_grid.grid_size * region_grid.grid_size

distance_sequences = random_walk_distance(distance_matrix, size)
time_sequences = random_walk_time(t, size)

sequences = []
for seq in distance_sequences + time_sequences:
    sequences.append(" ".join([str(id) for id in seq]))

print(sequences)
    # Adjacency Average Model
    mse, mse_std, mae, mae_std, err_adj = cv_adj_mean(
        region_grid.regions, region_grid.matrix_idx_map, y_house)
    results.append(['adjacent avg', mse, mse_std, mae, mae_std])

    y_is_valid = np.where(~np.isnan(y_house))[0]
    y_house = y_house[y_is_valid]

    # Global Avg Model
    global_avg = SimilarityModel(y_house)
    mse, mse_std, mae, mae_std, err_euclidean = cv_naive_mean(y_house)
    results.append(['global avg', mse, mse_std, mae, mae_std])

    # euclidean model
    D_euclidean = region_grid.get_distance_mtx()
    D_euclidean = D_euclidean[y_is_valid, :]
    D_euclidean = D_euclidean[:, y_is_valid]
    mod_euclidean = SimilarityModel(y_house, D_euclidean)

    mse, mse_std, mae, mae_std, err_euclidean = mod_euclidean.cv_ols()
    results.append(['euclidean', mse, mse_std, mae, mae_std])

    # Run with Taxi flow as weighted edges
    W = region_grid.weighted_mtx
    W = W[y_is_valid, :]
    W = W[:, y_is_valid]

    mod_flow = SimilarityModel(y_house, W)

    mse, mse_std, mae, mae_std, err_flow = mod_flow.cv_ols()