Move points to the boundaries

This is a discussion on Move points to the boundaries within the Tech Board forums, part of the Community Boards category; I have some code, which gives me uniformly distributed points in d dimensions, inside a cube from min to max. ...

  1. #1
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,681

    Move points to the boundaries

    I have some code, which gives me uniformly distributed points in d dimensions, inside a cube from min to max.

    Let's take D = 2, min = - 1 and max = 1. The cube is actually a unit square. Let's generate 5 points.
    Code:
    Generating 5 random points in a cube in 2D, coordinates from -1 to 1
    -0.109367 0.749923 
    0.151204 0.859457 
    0.364111 0.94229 
    -0.740006 -0.497918 
    -0.111803 0.289617
    What I would like to do, is to get, uniformly distributed, the points that lie in the boundaries of the D - cube.
    I thought about generating the points with the code I have unitl now and simply replacing a coordinate with min or max. This will produce boundary points, but are they uniformly distributed? Take as granted, that the points that are generated already are uniformly distributed!

    Thanks in advance
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,467
    If the RNG you are using is capable of generating uniformly distributed numbers between 0 and 1 (which most can, including language standard libraries), you can generate a uniformly distributed number in any range by simply using the supplied functions that operate with ranges. They are designed to not alter the distribution.

    If you language or library doesn't have such a function you can use the following formula:

    Code:
    min + random() * (max - min + 1)
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,681
    Tnx for the answer.
    However, what I have is a "black box" that will give me the numbers. So I have to do operations on the numbers already given. So assuming, that random() is the black box I am reffering to, I apply the rule you wrote and I got
    Code:
    //dimension x y
    2 -0.399516 0.87319 
    2 0.937221 -0.0146251 
    2 -0.412698 -0.476573 
    2 -0.871212 0.255872 
    2 -0.00647544 0.804864 
     then
    2 -2.19855 1.61957 
    2 1.81166 -1.04388 
    2 -2.23809 -2.42972 
    2 -3.61363 -0.232385 
    2 -1.01943 1.41459
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  4. #4
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    You could use your x-coord to indicate the side and the y-coord to be the coord on that side.
    Code:
    if (x < -.5) {      //Left side
        bx = -1;
        by = y;
    }else if (x < 0) { // Top
        bx = y;
        by = 1;
    }else if (x < .5) { // Right
        bx = 1;
        by = y;
    }else {             // Bottom
        bx = y;
        by = -1;
    }
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  5. #5
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,681
    Will the distribution remain uniform then?
    Moreover, I am interested in points in 17D, so I would like to generalize this.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  6. #6
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by std10093 View Post
    Will the distribution remain uniform then?
    Moreover, I am interested in points in 17D, so I would like to generalize this.
    It seems obvious that the distribution would remain uniform. If the 2D distro is uniform then each of it's two linear components must be uniform. With one of those uniform components (x), map an equal subset of its range to each side. The other uniform component (y) is used directly to choose a position on that side.

    For N dimensional hypercubes, use one dimension to choose an N-1 dimension hyper-side. Use the remaining N-1 dimension values to select a point within the chosen side.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  7. #7
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,681
    I see. Good.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory garbling across dll boundaries
    By m37h0d in forum C++ Programming
    Replies: 1
    Last Post: 04-26-2012, 09:48 AM
  2. C++ Plot Simple Points / Graph, X & Y array points
    By Khadafi in forum C++ Programming
    Replies: 9
    Last Post: 11-11-2011, 02:47 AM
  3. Word boundaries
    By slippy in forum C++ Programming
    Replies: 8
    Last Post: 12-02-2007, 02:00 PM
  4. DLL boundaries and delete.
    By aker_y3k in forum C++ Programming
    Replies: 2
    Last Post: 09-04-2004, 09:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21