Take Sample

john's Avatar

john

30 Sep, 2024 11:37 PM

Today's new node: take_sample

Take_sample takes an evenly distributed subset - or superset - from a list. The list can be anything: points, shapes, data table rows, numbers, whatever. If the list is shuffled you will get a random sample. If it sorted you'll get an even sample across whatever the list was sorted by.

Take_sample takes four parameters:

  • The list
  • Amount. This can be more than the number of items in the list.
  • Allow duplicates. If checked you are guaranteed to get the amount you asked for; if this is more than the number of items in the list, you will get a sample of duplicates to make up the difference. If not checked you will never get more than the number of items in the list.
  • Take all. If checked, the previous two settings will be ignored and you will get the whole list, just as if you had never added the take_sample node.

I developed this node when taking a random sample of fonts from my system, but you could use it for many other things. If given a shuffled list it will provide a random sample (though you could do the same thing with a slice node). It's really more useful when given an ordered list. Given a ordered list of cities and average temperatures you could use it to select a subset ranging from cold to hot.

The demo (attached) shows a shuffled grid of 64 stars of varying sizes. The goal is to pick nine of these at random but with steadily increasing sizes. I show arrows leading from the smallest to the largest star. You can keep changing the seed on the shuffle1 node to get different arrangements of stars. Each selection will be random but each of the nine stars picked will be bigger than the previous one.

I will also find this useful when debugging. When I am working on something that acts on a large list of items I will typically start by picking just one item and, then, when that is working, gradually add more. Often I will want these items to be sorted in some way and will want a sample cross section to test. Take_sample will make this easier.

Simple but, I hope, useful.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Already uploaded files

  • take_sample_screenshot.png 724 KB
  • take_sample_demo.ndbx.zip 51.3 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

01 Oct, 2024 07:59 AM
30 Sep, 2024 11:37 PM
30 Sep, 2024 11:11 AM
30 Sep, 2024 02:37 AM
28 Sep, 2024 10:33 AM

 

26 Sep, 2024 06:41 AM
24 Sep, 2024 12:32 AM
24 Sep, 2024 12:27 AM
13 Sep, 2024 12:07 AM
12 Sep, 2024 11:54 PM
07 Sep, 2024 05:16 AM