Skip to content

d3.medianIndex / d3.quantileIndex? #140

Description

@EE2dev

I suggest to also have a function d3.medianIndex(). E.g. it could return an array

  • with one element: the index of the corresponding element - in case the array.length is uneven
  • with two elements: the indices of the elements from which the mean was taken - in case the array.length is even

Activity

  1. Fil commented on Jun 15, 2020

    @Fil
    Member

    Related: #138; in both cases we're trying to get better access to the value we've located in the array.

  2. Fil commented on Jun 24, 2020

    @Fil
    Member

    I've tried to implement d3.quantileIndex in https://observablehq.com/d/c6c8a233930664d8 ; in order to keep track of the indices, we need to create an array of indices, then call quickselect on that array with a comparator that looks up the values in the original array. It's a quite bit more difficult to track, and implies the reservation of more memory.

    Another option is to seek the indices after determining the quantile, by running through the values to find the closest inferior and closest superior values (see the "Alternative" part of the notebook). This approach is leaner, and the added time is negligible.

    In terms of API I'd rather always return an array of two indices—which may be identical for odd lengths.

    Of course d3.medianIndex(values, valueof) would be d3.quantileIndex(values, 0.5, valueof)

  3. changed the title [-]d3.medianIndex()[/-] [+]d3.medianIndex / d3.quantileIndex?[/+] on Jun 24, 2020
  4. EE2dev commented on Jun 24, 2020

    @EE2dev
    Author

    Thanks Fil! Looks great to me, also agree on your suggestion for the cleaner API.

  5. added a commit that references this issue on Jun 25, 2020
    e1f2295
  6. added a commit that references this issue on Jun 30, 2022
    142f4e6
  7. added a commit that references this issue on Jul 3, 2022
    99fe7ae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions