示例#1
0
    trips["MATCH"] = False

    # Match this segment with trips in the training set
    for idx, row in trips.iterrows():
        if match(end, row.GRID_POLYLINE, k):
            trips.set_value(idx, 'MATCH', True)

    # We are only really interested in the matched trips now
    trips = trips[trips.MATCH]

    # Compute the destination distribution
    trips_agg = trips.groupby(["DEST_CELL"],
                              as_index=False).aggregate({"MATCH": "sum"})
    trips_agg.MATCH = trips_agg.MATCH / np.sum(trips_agg.MATCH)

    # Store it in a DestinationGrid object
    grid = DestinationGrid(N, M)
    grid.setProbs(trips_agg.DEST_CELL.values, trips_agg.MATCH.values)

    # Plot the new distribution
    plt.subplot(1, 2, 1)
    plt.imshow(np.log(grid.as_array() +
                      trip_to_array(partial_trip.GRID_POLYLINE, N, M)),
               interpolation="nearest")
    plt.title("Complete trip superimposed")

    plt.subplot(1, 2, 2)
    plt.imshow(np.log(grid.as_array() +
                      trip_to_array(partial_trip.TRUNC_GRID_POLYLINE, N, M)),
               interpolation="nearest")
    plt.title("Partial trip superimposed")
 
 # Select the last segment of the partial trip
 end = partial_trip.TRUNC_GRID_POLYLINE[-k:]
 
 # Create a dummy flag to indicate if a trip matches or not
 trips["MATCH"] = False
 
 # Match this segment with trips in the training set
 for idx, row in trips.iterrows():
   if match(end, row.GRID_POLYLINE, k):
     trips.set_value(idx, 'MATCH', True)
   
 # We are only really interested in the matched trips now
 trips = trips[trips.MATCH]
 
 # Compute the destination distribution
 trips_agg = trips.groupby(["DEST_CELL"], as_index = False).aggregate({"MATCH": "sum"})
 trips_agg.MATCH = trips_agg.MATCH / np.sum(trips_agg.MATCH)
 
 # Store it in a DestinationGrid object
 grid = DestinationGrid(N, M)
 grid.setProbs(trips_agg.DEST_CELL.values, trips_agg.MATCH.values)
 
 # Plot the new distribution
 plt.subplot(1,2,1)
 plt.imshow(np.log(grid.as_array() + trip_to_array(partial_trip.GRID_POLYLINE, N, M)), interpolation = "nearest")
 plt.title("Complete trip superimposed")
 
 plt.subplot(1,2,2)
 plt.imshow(np.log(grid.as_array() + trip_to_array(partial_trip.TRUNC_GRID_POLYLINE, N, M)), interpolation = "nearest")
 plt.title("Partial trip superimposed")