# genSample: Generate a sample of points in dimension \$p\$. In gMOIP: Tools for 2D and 3D Plots of Single and Multi-Objective Linear/Integer Programming Models

## Description

Generate a sample of points in dimension \$p\$.

## Usage

 ```1 2 3 4 5 6 7 8 9``` ```genSample( p, n, range = c(1, 100), random = FALSE, sphere = TRUE, box = FALSE, ... ) ```

## Arguments

 `p` Dimension of the points. `n` Number of samples generated. `range` The range of the points in each dimension (a vector or matrix with `p` rows). `random` Random sampling. `sphere` Generate points on a sphere. `box` Generate points in boxes. `...` Further arguments passed on to the method for generating points. This must be done as lists (see examples). Currently the following arguments are supported: `argsSphere`: A list of arguments for generating points on a sphere: `radius`: The radius of the sphere. `center`: The center of the sphere. `plane`: The plane used. `below`: Either true (generate points below the plane), false (generate points above the plane) or `NULL` (generated on the whole sphere). `factor`: If using a plane. Then the factor to multiply `n` with, so generate enough points below/above the plane. `closeToPlane`: If TRUE only return points close to the plane. `argsBox`: A list of arguments for generating points inside boxes: `intervals`: Number of intervals to split the length of the range into. That is, each range is divided into `intervals` (sub)intervals and only the lowest/highest subrange is used. `cor`: How to correlate indices. If `'idxAlt'` then alternate the intervals (high/low) for each dimension. For instance if `p = 3` and the first dimension is in the high interval range then the second will be in the low interval range and third in the high interval range again. If `idxRand` then choose the low/high interval range for each dimension based on `prHigh`. If `idxSplit` then select `floor(p/2):ceiling(p/2)` dimensions for the high interval range and the other for the low interval range. `prHigh`: Probability for choosing the high interval range in each dimension.

## Details

Note having ranges with different length when using the sphere method, doesn't make sense. The best option is properly to use a center and radius here. Moreover, as for higher `p` you may have to use a larger radius than half of the desired interval range.

## Value

A data frame with `p` columns

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155``` ```### Using random ## p = 2 range <- matrix(c(1,100, 50,100), ncol = 2, byrow = TRUE ) pts <- genSample(2, 1000, range = range, random = TRUE) head(pts) Rfast::colMinsMaxs(as.matrix(pts)) plot(pts) ## p = 3 range <- matrix(c(1,100, 50,100, 10,50), ncol = 2, byrow = TRUE ) ini3D() pts <- genSample(3, 1000, range = range, random = TRUE) head(pts) Rfast::colMinsMaxs(as.matrix(pts)) plotPoints3D(pts) finalize3D() ## other p p <- 10 range <- c(1,100) pts <- genSample(p, 1000, range = range, random = TRUE) head(pts) Rfast::colMinsMaxs(as.matrix(pts)) ### Using sphere ## p = 2 range <- c(1,100) cent <- rep(range[1] + (range[2]-range[1])/2, 2) pts <- genSample(2, 1000, range = range) dim(pts) Rfast::colMinsMaxs(as.matrix(pts)) plot(pts, asp=1) abline(sum(cent^2)/cent[1], -cent[2]/cent[1]) cent <- c(100,100) r <- 75 planeC <- c(cent+r/3) planeC <- c(planeC, -sum(planeC^2)) pts <- genSample(2, 100, argsSphere = list(center = cent, radius = r, below = FALSE, plane = planeC, factor = 6)) dim(pts) Rfast::colMinsMaxs(as.matrix(pts)) plot(pts, asp=1) abline(-planeC[3]/planeC[1], -planeC[2]/planeC[1]) pts <- genSample(2, 100, argsSphere = list(center = cent, radius = r, below = NULL)) dim(pts) Rfast::colMinsMaxs(as.matrix(pts)) plot(pts, asp=1) ## p = 3 ini3D() range <- c(1,100) cent <- rep(range[1] + (range[2]-range[1])/2, 3) pts <- genSample(3, 1000, range = range) dim(pts) Rfast::colMinsMaxs(as.matrix(pts)) rgl::spheres3d(cent, radius=49.5, color = "grey100", alpha=0.1) plotPoints3D(pts) rgl::planes3d(cent[1],cent[2],cent[3],-sum(cent^2), alpha = 0.5, col = "red") finalize3D() ini3D() cent <- c(100,100,100) r <- 75 planeC <- c(cent+r/3) planeC <- c(planeC, -sum(planeC^2)) pts <- genSample(3, 100, argsSphere = list(center = cent, radius = r, below = FALSE, plane = planeC, factor = 6)) rgl::spheres3d(cent, radius=r, color = "grey100", alpha=0.1) plotPoints3D(pts) rgl::planes3d(planeC[1],planeC[2],planeC[3],planeC[4], alpha = 0.5, col = "red") finalize3D() ini3D() pts <- genSample(3, 10000, argsSphere = list(center = cent, radius = r, below = NULL)) Rfast::colMinsMaxs(as.matrix(pts)) rgl::spheres3d(cent, radius=r, color = "grey100", alpha=0.1) plotPoints3D(pts) finalize3D() ## Other p p <- 10 cent <- rep(0,p) r <- 100 pts <- genSample(p, 100000, argsSphere = list(center = cent, radius = r, below = NULL)) head(pts) Rfast::colMinsMaxs(as.matrix(pts)) apply(pts,1, function(x){sqrt(sum((x-cent)^2))}) # test should be approx. equal to radius ### Using box ## p = 2 range <- matrix(c(1,100, 50,100), ncol = 2, byrow = TRUE ) pts <- genSample(2, 1000, range = range, box = TRUE, argsBox = list(cor = "idxAlt")) head(pts) Rfast::colMinsMaxs(as.matrix(pts)) plot(pts) pts <- genSample(2, 1000, range = range, box = TRUE, argsBox = list(cor = "idxAlt", intervals = 6)) plot(pts) pts <- genSample(2, 1000, range = range, box = TRUE, argsBox = list(cor = "idxRand")) plot(pts) pts <- genSample(2, 1000, range = range, box = TRUE, argsBox = list(cor = "idxRand", prHigh = c(0.1,0.6))) points(pts, pch = 3, col = "red") pts <- genSample(2, 1000, range = range, box = TRUE, argsBox = list(cor = "idxRand", prHigh = c(0,0))) points(pts, pch = 4, col = "blue") pts <- genSample(2, 1000, range = range, box = TRUE, argsBox = list(cor = "idxSplit")) plot(pts) ## p = 3 range <- matrix(c(1,100, 1,200, 1,50), ncol = 2, byrow = TRUE ) ini3D(argsPlot3d = list(box = TRUE, axes = TRUE)) pts <- genSample(3, 1000, range = range, box = TRUE, , argsBox = list(cor = "idxAlt")) head(pts) Rfast::colMinsMaxs(as.matrix(pts)) plotPoints3D(pts) finalize3D() ini3D(argsPlot3d = list(box = TRUE, axes = TRUE)) pts <- genSample(3, 1000, range = range, box = TRUE, , argsBox = list(cor = "idxAlt", intervals = 6)) plotPoints3D(pts) finalize3D() ini3D(argsPlot3d = list(box = TRUE, axes = TRUE)) pts <- genSample(3, 1000, range = range, box = TRUE, , argsBox = list(cor = "idxRand")) plotPoints3D(pts) pts <- genSample(3, 1000, range = range, box = TRUE, , argsBox = list(cor = "idxRand", prHigh = c(0.1,0.6,0.1))) plotPoints3D(pts, argsPlot3d = list(col="red")) finalize3D() ini3D(argsPlot3d = list(box = TRUE, axes = TRUE)) pts <- genSample(3, 1000, range = range, box = TRUE, , argsBox = list(cor = "idxSplit")) plotPoints3D(pts) finalize3D() ## other p p <- 10 range <- c(1,100) pts <- genSample(p, 1000, range = range, box = TRUE, argsBox = list(cor = "idxSplit")) head(pts) Rfast::colMinsMaxs(as.matrix(pts)) ```

gMOIP documentation built on Aug. 23, 2021, 5:09 p.m.