Split interval into random regions

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I'm having troubles comming up with algorithm, that would split interval of integers (lets say from 0 to 1000000) with these parameters :



  1. There are N kinds of regions. Neighboring regions cannot have same kind, otherwise, they would be considered same region. N is going to be relatively small compared to whole interval, in this of interval 0-1000000 it won't be higher than 10.

  2. Each kind has "ratio", where ratios of all kinds add up to 1. This If I were to average total size of each region of single kind across multiple execution, I would expect them to have this ratio.

  3. "cohesion" for either whole interval or specific kinds (not sure which is possible). If the "cohesion" is high, then regions would be big, continuous blocks. If the "cohesion" is low, then regions would be small pieces strewn all around.

The total number of regions is not set beforehand. It is emergent based on kind number and cohesion.



I know how to split interval into regions, but I don't know how to apply above parameters to control it's output.



Example:



The ratio parameter would cause, if there were 3 kinds of regions with ratios of 50% A, 40% B and 10% C, then I would expect, for interval from 0 to 10, something like BBBBCAAAAA or ABBACAABAB depending on cohesion. That means if I were to add up all A, B and C, I would get the above ratios, on average.



Lets say we have interval from 0 to 10 and 3 kinds (A, B, C) and low cohesion. I would expect something like : ABACCBBABC . If instead cohesion was high, I would expect BBBBBAACCC.



In above example, characters of same kind would form single region.



Another way to look at it. Imagine the algorithm would randomly generate what kind each number in the region is, based on the defined ratios. Then intervals with same kind would be aggregated into regions. But that would result in low cohesion, as each region would be 1-2 values wide. Instead, I want regions to be big areas. Eg. have high cohesion.



Image to better illustrate what I mean by "cohesion". N is 3 for Red, Green, Blue and interval is 0-50:



Cohesion example



Low cohesion, produces lots of small, scattered regions. High cohesion creates few, big regions.







share|cite|improve this question





















  • Without a precise formal definition of your "cohesion" this problem can never be solved.
    – David G. Stork
    Jul 27 at 7:51










  • @DavidG.Stork I don't have that definition, which is why I included examples. I agree that it is most unclear part of the algorithm.
    – Euphoric
    Jul 27 at 7:53










  • An example is insufficient, as I mentioned.
    – David G. Stork
    Jul 27 at 7:54










  • @MartinRoberts N is going to be relatively small compared to the total range.
    – Euphoric
    Jul 27 at 8:43










  • @MartinRoberts To make it clear, N is not number of regions. It is number of kinds of regions. In the above image the N is 3 (Red, Green, Blue) for all 3 cohesion levels.
    – Euphoric
    Jul 27 at 8:45














up vote
0
down vote

favorite












I'm having troubles comming up with algorithm, that would split interval of integers (lets say from 0 to 1000000) with these parameters :



  1. There are N kinds of regions. Neighboring regions cannot have same kind, otherwise, they would be considered same region. N is going to be relatively small compared to whole interval, in this of interval 0-1000000 it won't be higher than 10.

  2. Each kind has "ratio", where ratios of all kinds add up to 1. This If I were to average total size of each region of single kind across multiple execution, I would expect them to have this ratio.

  3. "cohesion" for either whole interval or specific kinds (not sure which is possible). If the "cohesion" is high, then regions would be big, continuous blocks. If the "cohesion" is low, then regions would be small pieces strewn all around.

The total number of regions is not set beforehand. It is emergent based on kind number and cohesion.



I know how to split interval into regions, but I don't know how to apply above parameters to control it's output.



Example:



The ratio parameter would cause, if there were 3 kinds of regions with ratios of 50% A, 40% B and 10% C, then I would expect, for interval from 0 to 10, something like BBBBCAAAAA or ABBACAABAB depending on cohesion. That means if I were to add up all A, B and C, I would get the above ratios, on average.



Lets say we have interval from 0 to 10 and 3 kinds (A, B, C) and low cohesion. I would expect something like : ABACCBBABC . If instead cohesion was high, I would expect BBBBBAACCC.



In above example, characters of same kind would form single region.



Another way to look at it. Imagine the algorithm would randomly generate what kind each number in the region is, based on the defined ratios. Then intervals with same kind would be aggregated into regions. But that would result in low cohesion, as each region would be 1-2 values wide. Instead, I want regions to be big areas. Eg. have high cohesion.



Image to better illustrate what I mean by "cohesion". N is 3 for Red, Green, Blue and interval is 0-50:



Cohesion example



Low cohesion, produces lots of small, scattered regions. High cohesion creates few, big regions.







share|cite|improve this question





















  • Without a precise formal definition of your "cohesion" this problem can never be solved.
    – David G. Stork
    Jul 27 at 7:51










  • @DavidG.Stork I don't have that definition, which is why I included examples. I agree that it is most unclear part of the algorithm.
    – Euphoric
    Jul 27 at 7:53










  • An example is insufficient, as I mentioned.
    – David G. Stork
    Jul 27 at 7:54










  • @MartinRoberts N is going to be relatively small compared to the total range.
    – Euphoric
    Jul 27 at 8:43










  • @MartinRoberts To make it clear, N is not number of regions. It is number of kinds of regions. In the above image the N is 3 (Red, Green, Blue) for all 3 cohesion levels.
    – Euphoric
    Jul 27 at 8:45












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm having troubles comming up with algorithm, that would split interval of integers (lets say from 0 to 1000000) with these parameters :



  1. There are N kinds of regions. Neighboring regions cannot have same kind, otherwise, they would be considered same region. N is going to be relatively small compared to whole interval, in this of interval 0-1000000 it won't be higher than 10.

  2. Each kind has "ratio", where ratios of all kinds add up to 1. This If I were to average total size of each region of single kind across multiple execution, I would expect them to have this ratio.

  3. "cohesion" for either whole interval or specific kinds (not sure which is possible). If the "cohesion" is high, then regions would be big, continuous blocks. If the "cohesion" is low, then regions would be small pieces strewn all around.

The total number of regions is not set beforehand. It is emergent based on kind number and cohesion.



I know how to split interval into regions, but I don't know how to apply above parameters to control it's output.



Example:



The ratio parameter would cause, if there were 3 kinds of regions with ratios of 50% A, 40% B and 10% C, then I would expect, for interval from 0 to 10, something like BBBBCAAAAA or ABBACAABAB depending on cohesion. That means if I were to add up all A, B and C, I would get the above ratios, on average.



Lets say we have interval from 0 to 10 and 3 kinds (A, B, C) and low cohesion. I would expect something like : ABACCBBABC . If instead cohesion was high, I would expect BBBBBAACCC.



In above example, characters of same kind would form single region.



Another way to look at it. Imagine the algorithm would randomly generate what kind each number in the region is, based on the defined ratios. Then intervals with same kind would be aggregated into regions. But that would result in low cohesion, as each region would be 1-2 values wide. Instead, I want regions to be big areas. Eg. have high cohesion.



Image to better illustrate what I mean by "cohesion". N is 3 for Red, Green, Blue and interval is 0-50:



Cohesion example



Low cohesion, produces lots of small, scattered regions. High cohesion creates few, big regions.







share|cite|improve this question













I'm having troubles comming up with algorithm, that would split interval of integers (lets say from 0 to 1000000) with these parameters :



  1. There are N kinds of regions. Neighboring regions cannot have same kind, otherwise, they would be considered same region. N is going to be relatively small compared to whole interval, in this of interval 0-1000000 it won't be higher than 10.

  2. Each kind has "ratio", where ratios of all kinds add up to 1. This If I were to average total size of each region of single kind across multiple execution, I would expect them to have this ratio.

  3. "cohesion" for either whole interval or specific kinds (not sure which is possible). If the "cohesion" is high, then regions would be big, continuous blocks. If the "cohesion" is low, then regions would be small pieces strewn all around.

The total number of regions is not set beforehand. It is emergent based on kind number and cohesion.



I know how to split interval into regions, but I don't know how to apply above parameters to control it's output.



Example:



The ratio parameter would cause, if there were 3 kinds of regions with ratios of 50% A, 40% B and 10% C, then I would expect, for interval from 0 to 10, something like BBBBCAAAAA or ABBACAABAB depending on cohesion. That means if I were to add up all A, B and C, I would get the above ratios, on average.



Lets say we have interval from 0 to 10 and 3 kinds (A, B, C) and low cohesion. I would expect something like : ABACCBBABC . If instead cohesion was high, I would expect BBBBBAACCC.



In above example, characters of same kind would form single region.



Another way to look at it. Imagine the algorithm would randomly generate what kind each number in the region is, based on the defined ratios. Then intervals with same kind would be aggregated into regions. But that would result in low cohesion, as each region would be 1-2 values wide. Instead, I want regions to be big areas. Eg. have high cohesion.



Image to better illustrate what I mean by "cohesion". N is 3 for Red, Green, Blue and interval is 0-50:



Cohesion example



Low cohesion, produces lots of small, scattered regions. High cohesion creates few, big regions.









share|cite|improve this question












share|cite|improve this question




share|cite|improve this question








edited Jul 27 at 8:49
























asked Jul 27 at 7:46









Euphoric

1113




1113











  • Without a precise formal definition of your "cohesion" this problem can never be solved.
    – David G. Stork
    Jul 27 at 7:51










  • @DavidG.Stork I don't have that definition, which is why I included examples. I agree that it is most unclear part of the algorithm.
    – Euphoric
    Jul 27 at 7:53










  • An example is insufficient, as I mentioned.
    – David G. Stork
    Jul 27 at 7:54










  • @MartinRoberts N is going to be relatively small compared to the total range.
    – Euphoric
    Jul 27 at 8:43










  • @MartinRoberts To make it clear, N is not number of regions. It is number of kinds of regions. In the above image the N is 3 (Red, Green, Blue) for all 3 cohesion levels.
    – Euphoric
    Jul 27 at 8:45
















  • Without a precise formal definition of your "cohesion" this problem can never be solved.
    – David G. Stork
    Jul 27 at 7:51










  • @DavidG.Stork I don't have that definition, which is why I included examples. I agree that it is most unclear part of the algorithm.
    – Euphoric
    Jul 27 at 7:53










  • An example is insufficient, as I mentioned.
    – David G. Stork
    Jul 27 at 7:54










  • @MartinRoberts N is going to be relatively small compared to the total range.
    – Euphoric
    Jul 27 at 8:43










  • @MartinRoberts To make it clear, N is not number of regions. It is number of kinds of regions. In the above image the N is 3 (Red, Green, Blue) for all 3 cohesion levels.
    – Euphoric
    Jul 27 at 8:45















Without a precise formal definition of your "cohesion" this problem can never be solved.
– David G. Stork
Jul 27 at 7:51




Without a precise formal definition of your "cohesion" this problem can never be solved.
– David G. Stork
Jul 27 at 7:51












@DavidG.Stork I don't have that definition, which is why I included examples. I agree that it is most unclear part of the algorithm.
– Euphoric
Jul 27 at 7:53




@DavidG.Stork I don't have that definition, which is why I included examples. I agree that it is most unclear part of the algorithm.
– Euphoric
Jul 27 at 7:53












An example is insufficient, as I mentioned.
– David G. Stork
Jul 27 at 7:54




An example is insufficient, as I mentioned.
– David G. Stork
Jul 27 at 7:54












@MartinRoberts N is going to be relatively small compared to the total range.
– Euphoric
Jul 27 at 8:43




@MartinRoberts N is going to be relatively small compared to the total range.
– Euphoric
Jul 27 at 8:43












@MartinRoberts To make it clear, N is not number of regions. It is number of kinds of regions. In the above image the N is 3 (Red, Green, Blue) for all 3 cohesion levels.
– Euphoric
Jul 27 at 8:45




@MartinRoberts To make it clear, N is not number of regions. It is number of kinds of regions. In the above image the N is 3 (Red, Green, Blue) for all 3 cohesion levels.
– Euphoric
Jul 27 at 8:45










2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










You could try a modified Poisson process. I will assume you are dividing up the continuous interval $[0,1]$ for simplicity, this can be discretized later.



There will be a series of borders, at positions $0=X_0<X_1<dots<X_n<1$ to be randomly chosen. To the right of each border $X_i$ is a region whose kind is $n(i)$.



Associated to each kind $n$ is a parameter $lambda_n$. These should be chosen so that



  1. $lambda_n^-1/(sum_m=1^N lambda_m^-1)$ is equal to the desired "ratio" for the $n^textth$ kind.


  2. $frac1Nsum_m=1^Nlambda_m$ is equal to the desired expected number of borders. More borders $implies$ less cohesion.


Here is the process: for each $i=0,1,2,dots$, $n(i)$ is uniformly randomly chosen from the set of $N-1$ kinds, all except for $n(i-1)$ (to prevent adjacent repeats). Then, $X_i$ is set to be $X_i + Y_i$, where $Y_i$ is exponentially distributed with parameter $lambda_n(i)$. This continues until $X_n+1>1$ for some border $X_n+1$.






share|cite|improve this answer





















  • Thanks for answer. I based my solution on it. Biggest problem for me was figuring out how to calculate the lambdas and weights, because my algorithm doesn't pick i uniformly, but weighted it to get good final results. But general structure is same as in answer.
    – Euphoric
    Jul 31 at 8:35

















up vote
1
down vote













Although there is still quite a lot of ambiguity and imprecision in the wording of your question, I believe that the following method is what you required.



This method partitions the interval of integers $[0,10^6]$ into intervals, where each interval is one of N=3 colors (red, green or blue) and so that the total number of integers in the red, green and blue intervals is 50%,40% and 10%, respectively.



  1. Select an integer $k$.


  2. Randomly divide the interval into $k$ regions. This can be achieved by first choosing $k-1$ random real numbers between [0,10^6]. This defines the boundary between two regions. So suppose that, when sorted in ascending order, these random numbers are:
    $ x_1,x_2,x_3,...,x_k-1 $.


  3. Then the desired $k$ intervals are:
    $$ (0, x_1), (x1, x2), (x2, x3),.....left( x_k-2,x_k-1right), left(x_k-1, 1right) $$


  4. For each interval, select a random number $x$, in the interval [0,1]. Then if:



    • $ 0.0 leq x < 0.5$, then color it red,

    • $ 0.5 leq x < 0.9$, then color it blue,

    • $ 0.9 leq x < 1.0$, then color is green.


Notes:



This will divide the interval into a maximum of $k$ intervals. However, as some adjacent intervals will be allocated the same color, the effective number of regions will usually typically be $ simeq (1-1/N^2)k$.



A low value of $k$ will result in high cohesion, and a high value of $k$ will results in low cohesion.
- On average, each interval will be colored red 50% of the time, blue 40% = 90%-50%, and green 10% = 100%-90% of the time.



If you had 6 colors with desired proportions of $30%,10%,4%,20%,1%,35%$ then the color allocation would be as follows:



  • $ 0.00 leq x < 0.30$, then color it red,

  • $ 0.30 leq x < 0.40$, then color it blue,

  • $ 0.40 leq x < 0.44$, then color is green.

  • $ 0.44 leq x < 0.64$, then color is orange.

  • $ 0.64 leq x < 0.65$, then color is pink.

  • $ 0.65 leq x < 1.00$, then color is brown.





share|cite|improve this answer























    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "69"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    noCode: true, onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2864153%2fsplit-interval-into-random-regions%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    You could try a modified Poisson process. I will assume you are dividing up the continuous interval $[0,1]$ for simplicity, this can be discretized later.



    There will be a series of borders, at positions $0=X_0<X_1<dots<X_n<1$ to be randomly chosen. To the right of each border $X_i$ is a region whose kind is $n(i)$.



    Associated to each kind $n$ is a parameter $lambda_n$. These should be chosen so that



    1. $lambda_n^-1/(sum_m=1^N lambda_m^-1)$ is equal to the desired "ratio" for the $n^textth$ kind.


    2. $frac1Nsum_m=1^Nlambda_m$ is equal to the desired expected number of borders. More borders $implies$ less cohesion.


    Here is the process: for each $i=0,1,2,dots$, $n(i)$ is uniformly randomly chosen from the set of $N-1$ kinds, all except for $n(i-1)$ (to prevent adjacent repeats). Then, $X_i$ is set to be $X_i + Y_i$, where $Y_i$ is exponentially distributed with parameter $lambda_n(i)$. This continues until $X_n+1>1$ for some border $X_n+1$.






    share|cite|improve this answer





















    • Thanks for answer. I based my solution on it. Biggest problem for me was figuring out how to calculate the lambdas and weights, because my algorithm doesn't pick i uniformly, but weighted it to get good final results. But general structure is same as in answer.
      – Euphoric
      Jul 31 at 8:35














    up vote
    1
    down vote



    accepted










    You could try a modified Poisson process. I will assume you are dividing up the continuous interval $[0,1]$ for simplicity, this can be discretized later.



    There will be a series of borders, at positions $0=X_0<X_1<dots<X_n<1$ to be randomly chosen. To the right of each border $X_i$ is a region whose kind is $n(i)$.



    Associated to each kind $n$ is a parameter $lambda_n$. These should be chosen so that



    1. $lambda_n^-1/(sum_m=1^N lambda_m^-1)$ is equal to the desired "ratio" for the $n^textth$ kind.


    2. $frac1Nsum_m=1^Nlambda_m$ is equal to the desired expected number of borders. More borders $implies$ less cohesion.


    Here is the process: for each $i=0,1,2,dots$, $n(i)$ is uniformly randomly chosen from the set of $N-1$ kinds, all except for $n(i-1)$ (to prevent adjacent repeats). Then, $X_i$ is set to be $X_i + Y_i$, where $Y_i$ is exponentially distributed with parameter $lambda_n(i)$. This continues until $X_n+1>1$ for some border $X_n+1$.






    share|cite|improve this answer





















    • Thanks for answer. I based my solution on it. Biggest problem for me was figuring out how to calculate the lambdas and weights, because my algorithm doesn't pick i uniformly, but weighted it to get good final results. But general structure is same as in answer.
      – Euphoric
      Jul 31 at 8:35












    up vote
    1
    down vote



    accepted







    up vote
    1
    down vote



    accepted






    You could try a modified Poisson process. I will assume you are dividing up the continuous interval $[0,1]$ for simplicity, this can be discretized later.



    There will be a series of borders, at positions $0=X_0<X_1<dots<X_n<1$ to be randomly chosen. To the right of each border $X_i$ is a region whose kind is $n(i)$.



    Associated to each kind $n$ is a parameter $lambda_n$. These should be chosen so that



    1. $lambda_n^-1/(sum_m=1^N lambda_m^-1)$ is equal to the desired "ratio" for the $n^textth$ kind.


    2. $frac1Nsum_m=1^Nlambda_m$ is equal to the desired expected number of borders. More borders $implies$ less cohesion.


    Here is the process: for each $i=0,1,2,dots$, $n(i)$ is uniformly randomly chosen from the set of $N-1$ kinds, all except for $n(i-1)$ (to prevent adjacent repeats). Then, $X_i$ is set to be $X_i + Y_i$, where $Y_i$ is exponentially distributed with parameter $lambda_n(i)$. This continues until $X_n+1>1$ for some border $X_n+1$.






    share|cite|improve this answer













    You could try a modified Poisson process. I will assume you are dividing up the continuous interval $[0,1]$ for simplicity, this can be discretized later.



    There will be a series of borders, at positions $0=X_0<X_1<dots<X_n<1$ to be randomly chosen. To the right of each border $X_i$ is a region whose kind is $n(i)$.



    Associated to each kind $n$ is a parameter $lambda_n$. These should be chosen so that



    1. $lambda_n^-1/(sum_m=1^N lambda_m^-1)$ is equal to the desired "ratio" for the $n^textth$ kind.


    2. $frac1Nsum_m=1^Nlambda_m$ is equal to the desired expected number of borders. More borders $implies$ less cohesion.


    Here is the process: for each $i=0,1,2,dots$, $n(i)$ is uniformly randomly chosen from the set of $N-1$ kinds, all except for $n(i-1)$ (to prevent adjacent repeats). Then, $X_i$ is set to be $X_i + Y_i$, where $Y_i$ is exponentially distributed with parameter $lambda_n(i)$. This continues until $X_n+1>1$ for some border $X_n+1$.







    share|cite|improve this answer













    share|cite|improve this answer



    share|cite|improve this answer











    answered Jul 27 at 8:58









    Mike Earnest

    14.9k11644




    14.9k11644











    • Thanks for answer. I based my solution on it. Biggest problem for me was figuring out how to calculate the lambdas and weights, because my algorithm doesn't pick i uniformly, but weighted it to get good final results. But general structure is same as in answer.
      – Euphoric
      Jul 31 at 8:35
















    • Thanks for answer. I based my solution on it. Biggest problem for me was figuring out how to calculate the lambdas and weights, because my algorithm doesn't pick i uniformly, but weighted it to get good final results. But general structure is same as in answer.
      – Euphoric
      Jul 31 at 8:35















    Thanks for answer. I based my solution on it. Biggest problem for me was figuring out how to calculate the lambdas and weights, because my algorithm doesn't pick i uniformly, but weighted it to get good final results. But general structure is same as in answer.
    – Euphoric
    Jul 31 at 8:35




    Thanks for answer. I based my solution on it. Biggest problem for me was figuring out how to calculate the lambdas and weights, because my algorithm doesn't pick i uniformly, but weighted it to get good final results. But general structure is same as in answer.
    – Euphoric
    Jul 31 at 8:35










    up vote
    1
    down vote













    Although there is still quite a lot of ambiguity and imprecision in the wording of your question, I believe that the following method is what you required.



    This method partitions the interval of integers $[0,10^6]$ into intervals, where each interval is one of N=3 colors (red, green or blue) and so that the total number of integers in the red, green and blue intervals is 50%,40% and 10%, respectively.



    1. Select an integer $k$.


    2. Randomly divide the interval into $k$ regions. This can be achieved by first choosing $k-1$ random real numbers between [0,10^6]. This defines the boundary between two regions. So suppose that, when sorted in ascending order, these random numbers are:
      $ x_1,x_2,x_3,...,x_k-1 $.


    3. Then the desired $k$ intervals are:
      $$ (0, x_1), (x1, x2), (x2, x3),.....left( x_k-2,x_k-1right), left(x_k-1, 1right) $$


    4. For each interval, select a random number $x$, in the interval [0,1]. Then if:



      • $ 0.0 leq x < 0.5$, then color it red,

      • $ 0.5 leq x < 0.9$, then color it blue,

      • $ 0.9 leq x < 1.0$, then color is green.


    Notes:



    This will divide the interval into a maximum of $k$ intervals. However, as some adjacent intervals will be allocated the same color, the effective number of regions will usually typically be $ simeq (1-1/N^2)k$.



    A low value of $k$ will result in high cohesion, and a high value of $k$ will results in low cohesion.
    - On average, each interval will be colored red 50% of the time, blue 40% = 90%-50%, and green 10% = 100%-90% of the time.



    If you had 6 colors with desired proportions of $30%,10%,4%,20%,1%,35%$ then the color allocation would be as follows:



    • $ 0.00 leq x < 0.30$, then color it red,

    • $ 0.30 leq x < 0.40$, then color it blue,

    • $ 0.40 leq x < 0.44$, then color is green.

    • $ 0.44 leq x < 0.64$, then color is orange.

    • $ 0.64 leq x < 0.65$, then color is pink.

    • $ 0.65 leq x < 1.00$, then color is brown.





    share|cite|improve this answer



























      up vote
      1
      down vote













      Although there is still quite a lot of ambiguity and imprecision in the wording of your question, I believe that the following method is what you required.



      This method partitions the interval of integers $[0,10^6]$ into intervals, where each interval is one of N=3 colors (red, green or blue) and so that the total number of integers in the red, green and blue intervals is 50%,40% and 10%, respectively.



      1. Select an integer $k$.


      2. Randomly divide the interval into $k$ regions. This can be achieved by first choosing $k-1$ random real numbers between [0,10^6]. This defines the boundary between two regions. So suppose that, when sorted in ascending order, these random numbers are:
        $ x_1,x_2,x_3,...,x_k-1 $.


      3. Then the desired $k$ intervals are:
        $$ (0, x_1), (x1, x2), (x2, x3),.....left( x_k-2,x_k-1right), left(x_k-1, 1right) $$


      4. For each interval, select a random number $x$, in the interval [0,1]. Then if:



        • $ 0.0 leq x < 0.5$, then color it red,

        • $ 0.5 leq x < 0.9$, then color it blue,

        • $ 0.9 leq x < 1.0$, then color is green.


      Notes:



      This will divide the interval into a maximum of $k$ intervals. However, as some adjacent intervals will be allocated the same color, the effective number of regions will usually typically be $ simeq (1-1/N^2)k$.



      A low value of $k$ will result in high cohesion, and a high value of $k$ will results in low cohesion.
      - On average, each interval will be colored red 50% of the time, blue 40% = 90%-50%, and green 10% = 100%-90% of the time.



      If you had 6 colors with desired proportions of $30%,10%,4%,20%,1%,35%$ then the color allocation would be as follows:



      • $ 0.00 leq x < 0.30$, then color it red,

      • $ 0.30 leq x < 0.40$, then color it blue,

      • $ 0.40 leq x < 0.44$, then color is green.

      • $ 0.44 leq x < 0.64$, then color is orange.

      • $ 0.64 leq x < 0.65$, then color is pink.

      • $ 0.65 leq x < 1.00$, then color is brown.





      share|cite|improve this answer

























        up vote
        1
        down vote










        up vote
        1
        down vote









        Although there is still quite a lot of ambiguity and imprecision in the wording of your question, I believe that the following method is what you required.



        This method partitions the interval of integers $[0,10^6]$ into intervals, where each interval is one of N=3 colors (red, green or blue) and so that the total number of integers in the red, green and blue intervals is 50%,40% and 10%, respectively.



        1. Select an integer $k$.


        2. Randomly divide the interval into $k$ regions. This can be achieved by first choosing $k-1$ random real numbers between [0,10^6]. This defines the boundary between two regions. So suppose that, when sorted in ascending order, these random numbers are:
          $ x_1,x_2,x_3,...,x_k-1 $.


        3. Then the desired $k$ intervals are:
          $$ (0, x_1), (x1, x2), (x2, x3),.....left( x_k-2,x_k-1right), left(x_k-1, 1right) $$


        4. For each interval, select a random number $x$, in the interval [0,1]. Then if:



          • $ 0.0 leq x < 0.5$, then color it red,

          • $ 0.5 leq x < 0.9$, then color it blue,

          • $ 0.9 leq x < 1.0$, then color is green.


        Notes:



        This will divide the interval into a maximum of $k$ intervals. However, as some adjacent intervals will be allocated the same color, the effective number of regions will usually typically be $ simeq (1-1/N^2)k$.



        A low value of $k$ will result in high cohesion, and a high value of $k$ will results in low cohesion.
        - On average, each interval will be colored red 50% of the time, blue 40% = 90%-50%, and green 10% = 100%-90% of the time.



        If you had 6 colors with desired proportions of $30%,10%,4%,20%,1%,35%$ then the color allocation would be as follows:



        • $ 0.00 leq x < 0.30$, then color it red,

        • $ 0.30 leq x < 0.40$, then color it blue,

        • $ 0.40 leq x < 0.44$, then color is green.

        • $ 0.44 leq x < 0.64$, then color is orange.

        • $ 0.64 leq x < 0.65$, then color is pink.

        • $ 0.65 leq x < 1.00$, then color is brown.





        share|cite|improve this answer















        Although there is still quite a lot of ambiguity and imprecision in the wording of your question, I believe that the following method is what you required.



        This method partitions the interval of integers $[0,10^6]$ into intervals, where each interval is one of N=3 colors (red, green or blue) and so that the total number of integers in the red, green and blue intervals is 50%,40% and 10%, respectively.



        1. Select an integer $k$.


        2. Randomly divide the interval into $k$ regions. This can be achieved by first choosing $k-1$ random real numbers between [0,10^6]. This defines the boundary between two regions. So suppose that, when sorted in ascending order, these random numbers are:
          $ x_1,x_2,x_3,...,x_k-1 $.


        3. Then the desired $k$ intervals are:
          $$ (0, x_1), (x1, x2), (x2, x3),.....left( x_k-2,x_k-1right), left(x_k-1, 1right) $$


        4. For each interval, select a random number $x$, in the interval [0,1]. Then if:



          • $ 0.0 leq x < 0.5$, then color it red,

          • $ 0.5 leq x < 0.9$, then color it blue,

          • $ 0.9 leq x < 1.0$, then color is green.


        Notes:



        This will divide the interval into a maximum of $k$ intervals. However, as some adjacent intervals will be allocated the same color, the effective number of regions will usually typically be $ simeq (1-1/N^2)k$.



        A low value of $k$ will result in high cohesion, and a high value of $k$ will results in low cohesion.
        - On average, each interval will be colored red 50% of the time, blue 40% = 90%-50%, and green 10% = 100%-90% of the time.



        If you had 6 colors with desired proportions of $30%,10%,4%,20%,1%,35%$ then the color allocation would be as follows:



        • $ 0.00 leq x < 0.30$, then color it red,

        • $ 0.30 leq x < 0.40$, then color it blue,

        • $ 0.40 leq x < 0.44$, then color is green.

        • $ 0.44 leq x < 0.64$, then color is orange.

        • $ 0.64 leq x < 0.65$, then color is pink.

        • $ 0.65 leq x < 1.00$, then color is brown.






        share|cite|improve this answer















        share|cite|improve this answer



        share|cite|improve this answer








        edited Jul 27 at 9:50


























        answered Jul 27 at 9:32









        Martin Roberts

        1,204318




        1,204318






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2864153%2fsplit-interval-into-random-regions%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What is the equation of a 3D cone with generalised tilt?

            Color the edges and diagonals of a regular polygon

            Relationship between determinant of matrix and determinant of adjoint?