@Test public void getGaussianTest() { long factor = 6000; double stdDeviation = 0.7; double variance = 1; double mean = 4; LinkedList<Integer> gaussian = RandomUtils.getGaussian(0, 15, 15, factor, stdDeviation, variance, mean); int total = 0; for (Integer g : gaussian) total += g; _log.info("Param: {}/{}/{}, Total: {}", 0, 15, 15, total); _log.info(JSON.toJSONString(gaussian)); assertEquals("[62,461,1919,4512,6000,4512,1919,461,62,4,0,0,0,0,0]", JSON.toJSONString(gaussian)); Assert.assertEquals(19912, total); gaussian = RandomUtils.getGaussian(0, 9, 9, factor, stdDeviation, variance, mean); total = 0; for (Integer g : gaussian) total += g; _log.info("Param: {}/{}/{}, Total: {}", 0, 9, 9, total); _log.info(JSON.toJSONString(gaussian)); assertEquals("[62,461,1919,4512,6000,4512,1919,461,62]", JSON.toJSONString(gaussian)); Assert.assertEquals(19908, total); gaussian = RandomUtils.getGaussian(0, 15, 71, factor, stdDeviation, variance, mean); total = 0; for (Integer g : gaussian) total += g; _log.info("Param: {}/{}/{}, Total: {}", 0, 15, 71, total); _log.info(JSON.toJSONString(gaussian)); assertEquals("[12,12,12,12,12,92,92,92,92,92,383,383,383,383,383,902,902,902,902,902,1200,1200,1200,1200,1200,902,902,902,902,902,383,383,383,383,383,92,92,92,92,92,12,12,12,12,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]", JSON.toJSONString(gaussian)); Assert.assertEquals(19890, total); factor = 2500; stdDeviation = 8; variance = 1; gaussian = RandomUtils.getGaussian(0, 15, 9, factor, stdDeviation, variance, 32 / 6 + 1); total = 0; for (Integer g : gaussian) total += g; _log.info("Param: {}/{}/{}, Size: {}, Total: {}", 0, 15, 9, gaussian.size(), total); _log.info(JSON.toJSONString(gaussian)); factor = 2000; stdDeviation = 8; variance = 1.5; gaussian = RandomUtils.getGaussian(0, 15, 71, factor, stdDeviation, variance, 6); total = 0; for (Integer g : gaussian) total += g; _log.info("Param: {}/{}/{}, Size: {}, Total: {}", 0, 15, 71, gaussian.size(), total); _log.info(JSON.toJSONString(gaussian)); }
public static LinkedList<Integer> getGaussian(int start, int end, int num, long factor, double stdDeviation, double variance, double mean) { LinkedList<Integer> gaussianList = new LinkedList<>(); for (int i = start; i <= end; i++) { int y = (int) (getY(i, stdDeviation, variance, mean) * factor); gaussianList.add(y); } LinkedList<Integer> result = new LinkedList<>(); if (end > num) { int step = (end - 1) / num; for (int i = 0; i < num; i++) { result.add(gaussianList.get(i * step)); } } else if (end == num) { for (int i = 0; i < num; i++) result.add(gaussianList.get(i)); } else { int step = num / end + 1; for (int i = 0; i < end && result.size() < num; i++) { int y = gaussianList.get(i); int subY = y / step; for (int k = 0; k < step; k++) result.add(subY); } } return result; }
RandomUtils { public static LinkedList<Integer> getGaussian(int start, int end, int num, long factor, double stdDeviation, double variance, double mean) { LinkedList<Integer> gaussianList = new LinkedList<>(); for (int i = start; i <= end; i++) { int y = (int) (getY(i, stdDeviation, variance, mean) * factor); gaussianList.add(y); } LinkedList<Integer> result = new LinkedList<>(); if (end > num) { int step = (end - 1) / num; for (int i = 0; i < num; i++) { result.add(gaussianList.get(i * step)); } } else if (end == num) { for (int i = 0; i < num; i++) result.add(gaussianList.get(i)); } else { int step = num / end + 1; for (int i = 0; i < end && result.size() < num; i++) { int y = gaussianList.get(i); int subY = y / step; for (int k = 0; k < step; k++) result.add(subY); } } return result; } }
RandomUtils { public static LinkedList<Integer> getGaussian(int start, int end, int num, long factor, double stdDeviation, double variance, double mean) { LinkedList<Integer> gaussianList = new LinkedList<>(); for (int i = start; i <= end; i++) { int y = (int) (getY(i, stdDeviation, variance, mean) * factor); gaussianList.add(y); } LinkedList<Integer> result = new LinkedList<>(); if (end > num) { int step = (end - 1) / num; for (int i = 0; i < num; i++) { result.add(gaussianList.get(i * step)); } } else if (end == num) { for (int i = 0; i < num; i++) result.add(gaussianList.get(i)); } else { int step = num / end + 1; for (int i = 0; i < end && result.size() < num; i++) { int y = gaussianList.get(i); int subY = y / step; for (int k = 0; k < step; k++) result.add(subY); } } return result; } private  RandomUtils(); }
RandomUtils { public static LinkedList<Integer> getGaussian(int start, int end, int num, long factor, double stdDeviation, double variance, double mean) { LinkedList<Integer> gaussianList = new LinkedList<>(); for (int i = start; i <= end; i++) { int y = (int) (getY(i, stdDeviation, variance, mean) * factor); gaussianList.add(y); } LinkedList<Integer> result = new LinkedList<>(); if (end > num) { int step = (end - 1) / num; for (int i = 0; i < num; i++) { result.add(gaussianList.get(i * step)); } } else if (end == num) { for (int i = 0; i < num; i++) result.add(gaussianList.get(i)); } else { int step = num / end + 1; for (int i = 0; i < end && result.size() < num; i++) { int y = gaussianList.get(i); int subY = y / step; for (int k = 0; k < step; k++) result.add(subY); } } return result; } private  RandomUtils(); static double uniform(double a, double b); static int uniform(int n); static boolean bernoulli(double p); static double gaussian(); static double gaussian(double mean, double stddev); static int discrete(double[] a); static double exp(double lambda); static int[] perm(int n); static void shuffle(String[] a); static LinkedList<Integer> getGaussian(int start, int end, int num, long factor,
                                                  double stdDeviation, double variance, double mean); static double getY(double x, double stdDeviation, double variance, double mean); static long uuid(); static String uuid2(); }
RandomUtils { public static LinkedList<Integer> getGaussian(int start, int end, int num, long factor, double stdDeviation, double variance, double mean) { LinkedList<Integer> gaussianList = new LinkedList<>(); for (int i = start; i <= end; i++) { int y = (int) (getY(i, stdDeviation, variance, mean) * factor); gaussianList.add(y); } LinkedList<Integer> result = new LinkedList<>(); if (end > num) { int step = (end - 1) / num; for (int i = 0; i < num; i++) { result.add(gaussianList.get(i * step)); } } else if (end == num) { for (int i = 0; i < num; i++) result.add(gaussianList.get(i)); } else { int step = num / end + 1; for (int i = 0; i < end && result.size() < num; i++) { int y = gaussianList.get(i); int subY = y / step; for (int k = 0; k < step; k++) result.add(subY); } } return result; } private  RandomUtils(); static double uniform(double a, double b); static int uniform(int n); static boolean bernoulli(double p); static double gaussian(); static double gaussian(double mean, double stddev); static int discrete(double[] a); static double exp(double lambda); static int[] perm(int n); static void shuffle(String[] a); static LinkedList<Integer> getGaussian(int start, int end, int num, long factor,
                                                  double stdDeviation, double variance, double mean); static double getY(double x, double stdDeviation, double variance, double mean); static long uuid(); static String uuid2();  }