Exemplo n.º 1
0
def noticeability_for_regions(grid, database):
    area_of_region = grid.area_of_region()
    regions = grid.calculate_regions(database)
    n = noticeability.Noticeability(grid, database, regions)
    n_regions = []
    for region in regions:
        n_regions.append(n.calculate(region[0], region[1]))
    return n_regions
Exemplo n.º 2
0
def draw_heatmap(database, grid):
    """Heatmap for noticeability.

    See: http://matplotlib.org/examples/pylab_examples/hexbin_demo.html
    """
    n = noticeability_for_regions(grid, database)

    # Replace all NOT_APPLICABLE with zero.
    # TODO: There's GOT to be a cleaner way!
    for i,x in enumerate(n):
        if n[i][0] == globals.NOT_APPLICABLE:
            n[i][0] = 0
        if n[i][1] == globals.NOT_APPLICABLE:
            n[i][1] = 0

    # Create a two-dimensional array to hold values for non-deceptive agent's
    # noticeability. Rearrange for a {(0,0),(0,1),(0,2)...} layout instead of
    # the region (top-to-bottom, left-to-right).
    #
    # TODO: This is upside down.
    data = []
    n_obj = noticeability.Noticeability(grid, database,
                                        grid.calculate_regions(database))

    for y in range(0, grid.num_divisions):
        row = []
        for x in range(0, grid.num_divisions):
            top_left = point.Point(grid.bounding_box[0].x + (x * grid.divide.x),
                                   grid.bounding_box[0].y - (y * grid.divide.y))
            bottom_right = point.Point(grid.bounding_box[0].x + ((x + 1) * grid.divide.x),
                                       grid.bounding_box[0].y - ((y + 1) * grid.divide.y))
            n = n_obj.calculate(top_left, bottom_right)
            if n[0] == globals.NOT_APPLICABLE:
                n[0] = 0
            if n[1] == globals.NOT_APPLICABLE:
                n[1] = 0

            row.append(n[1])
        data.append(row)

    # Swap color map for either BuGn or OrRd.

    fig = pyplot.figure()
    ax1 = fig.add_subplot(111)
    cmap = cm.get_cmap('OrRd', 10)
    ax1.imshow(data, interpolation='nearest', cmap=cmap)
    pyplot.show()
Exemplo n.º 3
0
if __name__ == '__main__':
    if len(sys.argv) != 2:
        print 'Requires path to data file'
        sys.exit()

    # Only process regions in this list. Leave empty to process all regions.
    restrict_to_regions = []

    # Read in database of agents from Kinect.
    database = setup_database(sys.argv[1])

    # Set up bounding box around agent positions.
    grid = grid.Grid(database)

    # Prepare all regions within bounding box.
    regions = grid.calculate_regions(database)

    n = noticeability.Noticeability(grid, database, regions)
    s = suspiciousness.Suspiciousness(database, regions)

    print 'n(region) = [non-deceptive, deceptive]'
    print

    if len(restrict_to_regions) > 0:
        for region_num in restrict_to_regions:
            print 'Region', str(region_num),
            print n.calculate(regions[region_num][0], regions[region_num][1])
    else:
        for i, region in enumerate(regions):
            print 'Region', str(i),
            print n.calculate(region[0], region[1])