Skip to content

Conversation

@ljwolf
Copy link
Member

@ljwolf ljwolf commented May 9, 2025

This adds trimmed_hull() and trim_pointset() to centrography.py. These are built on onion peeling theory.

The trimmed hull is a shape that covers p% of the points. Points are removed from the covered set by either paring or peeling.

For peeling,

  1. we calculate the hull for the point set.
  2. If p% of the points are inside of this hull (i.e. not on the boundary), we drop all points on the boundary and return to 1.
  3. Otherwise, we stop and return the hull.

For paring,

  1. We calculate the hull for the point set.
  2. We calculate the angle at each vertex on the hull.
  3. If we can drop one more point and still cover at least p%, we drop the point on the hull with the smallest angle.
  4. Otherwise, we stop and return the hull.

One reasonable next step would be to implement a final function like convex_depth(X, y=None) that calculates how far you have to peel to uncover y if provided, or the convex depth of each point X in the dataset. I think this could be done just by extending this strategy, but it would get slow quickly unless we use the Chazelle approach.

@ljwolf ljwolf requested a review from martinfleis May 9, 2025 15:35
@ljwolf ljwolf marked this pull request as draft May 9, 2025 15:35
@ljwolf ljwolf requested review from sjsrey and weikang9009 May 9, 2025 15:35
@ljwolf
Copy link
Member Author

ljwolf commented May 9, 2025

random normal

onionpeel-test-random

US counties

onionpeel-test-natregimes

Copy link
Member

@sjsrey sjsrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice.

A couple of ideas/comments given in-line.

current_knob_ix = points_hull_ixs[current_knob_on_hull]
# for the points on the hull, get the ith observation's full dataset index
trimmed.loc[current_knob_ix] = True
return ~trimmed
Copy link
Member

@sjsrey sjsrey May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another possible enhancement you might consider is optionally returning the sequence of hulls generated during the trimming process. A long while back, I explored the geometric and spatial properties of these nested hulls, and found that they can reveal interesting patterns in the point set structure. Never returned to this, but this excellent implementation reminded me of that. Capturing the intermediate hulls would make it possible to later analyze, visualize, or summarize the shape evolution of the dataset as it's pared down. This could be done with a simple flag likereturn_hulls=False, and if enabled, the function could return a tuple (~trimmed, hulls).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants