+ Reply to Thread
Results 1 to 5 of 5

Thread: Math notation break set into n length groups

  1. #1
    ggplot2orBust
    Points: 71,220, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,417
    Thanks
    1,811
    Thanked 928 Times in 809 Posts

    Math notation break set into n length groups




    I have a vector of length 26 and want to split it into groups of length 5. I can write it in code but what's the math notation for breaking a set up into n length groups keeping the elements consecutively ordered?

    Using what Bryan Goodrich wrote here: http://www.talkstats.com/showthread....l=1#post178934

    I know I have a set of length 26 which I could write as:

    d = {x_1, x_2, ..., x_26}

    How can I say split d in to groups of 5? It seems d/5 isn't really what I'm doing so I don't think that's the right notation (especially since the sub groups need to be consecutive).

    Code: 
    w <- LETTERS
    groups <- rep(1:(ceiling(length(w)/5)), each = ceiling(length(w)/(ceiling(length(w)/5))))#[1:length(w)]
    split(w, groups)
    Code: 
    > LETTERS
     [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S"
    [20] "T" "U" "V" "W" "X" "Y" "Z"
    Code: 
    > split(w, groups)
    $`1`
    [1] "A" "B" "C" "D" "E"
    
    $`2`
    [1] "F" "G" "H" "I" "J"
    
    $`3`
    [1] "K" "L" "M" "N" "O"
    
    $`4`
    [1] "P" "Q" "R" "S" "T"
    
    $`5`
    [1] "U" "V" "W" "X" "Y"
    
    $`6`
    [1] "Z"
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  2. #2
    Probably A Mammal
    Points: 31,087, Level: 100
    Level completed: 0%, Points required for next Level: 0
    bryangoodrich's Avatar
    Location
    Sacramento, California, United States
    Posts
    2,564
    Thanks
    398
    Thanked 618 Times in 551 Posts

    Re: Math notation break set into n length groups

    Functionally, I'd make this function

    Code: 
    n_groups <- function(x, n)
    {
        N <- length(x)
        groups <- rep(1:ceiling(N/n), each = n, length.out = N)
        split(x, groups)
    }
    The notation I would use might be something like you have a domain defined as a sequence {a}_n = {a_1, a_2, ..., a_n}. From this you're partitioning (see calculus/real analysis notation for partitioning with regards integration) this domain into sub-sequences {b}_m. Here the relationship of n and m correspond to my code as n := N and m := ceiling(N/n), but we're still missing which group it is. Maybe a j parameter like {b_j}_m, where b_1 is the first group partitioned by m {A, B, C, D, E), and b_6 is the last group {Z} with m=1.

    https://en.wikipedia.org/wiki/Partition_of_an_interval <-- Helpful, and an interval is just a continuous version of a sequence
    You should definitely use jQuery. It's really great and does all things.

  3. The Following User Says Thank You to bryangoodrich For This Useful Post:

    trinker (04-12-2016)

  4. #3
    Cookie Scientist
    Points: 13,431, Level: 75
    Level completed: 46%, Points required for next Level: 219
    Jake's Avatar
    Location
    Austin, TX
    Posts
    1,293
    Thanks
    66
    Thanked 584 Times in 438 Posts

    Re: Math notation break set into n length groups

    Well 26 isn't divisible by 5, so splitting d into groups of length 5 is not possible... (note that this is not exactly what your code does, since one of the resulting groups has length 1)
    “In God we trust. All others must bring data.”
    ~W. Edwards Deming

  5. #4
    Probably A Mammal
    Points: 31,087, Level: 100
    Level completed: 0%, Points required for next Level: 0
    bryangoodrich's Avatar
    Location
    Sacramento, California, United States
    Posts
    2,564
    Thanks
    398
    Thanked 618 Times in 551 Posts

    Re: Math notation break set into n length groups

    Another way to think of the notation is how Wolfram denotes sequences

    http://mathworld.wolfram.com/Subsequence.html

    Arbitrarily, you have some sequence (vector) {a} = a_n for n in 1...N. What you want is to define subsequences {b} = b_k for k in sub intervals of 1...n which we can denote b_k = a_(n_k) where the (n_k) is picking out the elements in the 1...n interval that belong to this {b}. Thus, my previous point, we're defining multiple {b} that we might want to flag with some index j, maybe {b^j}. Thus, we would have

    \{b^j\} = b^j_k = a_{n_k}
    You should definitely use jQuery. It's really great and does all things.

  6. The Following User Says Thank You to bryangoodrich For This Useful Post:

    trinker (04-12-2016)

  7. #5
    Cookie Scientist
    Points: 13,431, Level: 75
    Level completed: 46%, Points required for next Level: 219
    Jake's Avatar
    Location
    Austin, TX
    Posts
    1,293
    Thanks
    66
    Thanked 584 Times in 438 Posts

    Re: Math notation break set into n length groups


    I'm not sure what this is for, but if the point is just to describe what some algorithm is doing in a more general/abstract way than giving the actual syntax, then it might make more sense to use pseudocode rather than more formal math notation.

    But a mathy way to say this might be: we define a sequence s of subsequences s_i such that s_i = x_{5(i-1)+1}, ..., x_{5(i-1)+5}. And you could refer to the individual elements of the s_i using s_{ij}.
    “In God we trust. All others must bring data.”
    ~W. Edwards Deming

  8. The Following User Says Thank You to Jake For This Useful Post:

    trinker (04-12-2016)

+ Reply to Thread

           




Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts






Advertise on Talk Stats